Predat0R
17-09-2006 09:34:31
I creat dynamic actor. But when I can addForce to my actor => he DON'T change position.
actor->addForce(NxVec3(0,150,0));
but position actor - const
???
betajaen
17-09-2006 10:14:37
Usually the force isn't high enough due to mass, increase it.
Predat0R
26-09-2006 18:00:51
NxTriangleMesh* bunnyMesh;
NxTriangleMeshDesc bunnyDesc;
bunnyDesc.numVertices = vertlist.size() / 3;
bunnyDesc.numTriangles= indlist.size() /3;
bunnyDesc.pointStrideBytes= sizeof(NxVec3);
bunnyDesc.triangleStrideBytes= 3*sizeof(NxU32);
bunnyDesc.points = verts;
bunnyDesc.triangles = indices;
bunnyDesc.flags= 0;
bunnyDesc.materialIndexStride= sizeof(NxMaterialIndex);
NxInitCooking();
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(bunnyDesc, buf);
MemoryReadBuffer readBuffer(buf.data);
bunnyMesh = Nxg::Nogredex_world::getSingleton().mPhysicsSDK->createTriangleMesh(readBuffer);
free(verts);
free(indices);
NxTriangleMeshShapeDesc bunnyShapeDesc;
bunnyShapeDesc.meshData = bunnyMesh;
bunnyShapeDesc.userData = this;
bunnyShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;
NxBodyDesc BodyDesc;
NxActorDesc ActorDesc;
ActorDesc.setToDefault();
BodyDesc.setToDefault();
BodyDesc.flags|= NX_BF_FROZEN_ROT_X|NX_BF_FROZEN_ROT_Z;
BodyDesc.linearDamping = 1.0f;
BodyDesc.angularDamping = 10.0f;
ActorDesc.shapes.pushBack(&bunnyShapeDesc);
ActorDesc.body = &BodyDesc;
ActorDesc.density = 0.1f;
ActorDesc.globalPose.t = toNx(pos);
ActorDesc.userData = this;
actor = Nxg::Nogredex_world::getSingleton().mScene->createActor(ActorDesc);
actor->userData = this;
actor->setGroup(Nxg::GROUP_DEFAULT);
betajaen
26-09-2006 18:38:48
Two things.
X and Z movement are frozen. You can only go up and down.
Why on earth are you using Nogredex?
Predat0R
27-09-2006 06:27:42
I use NxOgre + Nogredex.
How I can unfroze X and Z movement ?
betajaen
27-09-2006 09:56:49
Erm....
You could not include that flags line. Seriously just read the PhysX documentation for that.
And why do you would want to use NxOgre+Nogredex together it just seems silly?
Predat0R
17-10-2006 07:10:04
I long time don't can decide this problem. I past my body.cpp - load mesh + create body + create actor + ADDFORCE !
May be you find error :
____________________________________________________________
#include "Nogredex_dynamicBody.h"
#include "nxOgre_util_stream.h"
namespace Nxg
{
Nogredex_dynamicBody::Nogredex_dynamicBody(String _name, String meshName,Ogre::Vector3 pos)
{
float scale = 1.0;
ent = Nxg::Nogredex_world::getSingleton().mSceneMgr->createEntity(_name, meshName);
ent->setVisible(true);
ent->setNormaliseNormals(true);
MeshPtr pMesh = (MeshPtr) MeshManager::getSingleton().getByName(meshName);
unsigned short numSubMeshes = pMesh->getNumSubMeshes();
std::vector<float> vertlist;
std::vector<NxU32> indlist;
long indoffset = 0;
for(unsigned short s = 0; s < numSubMeshes; s++)
{
SubMesh *pSubMesh = pMesh->getSubMesh(s);
VertexData *vertexData = pMesh->sharedVertexData;
if(!pSubMesh->useSharedVertices)
vertexData = pSubMesh->vertexData;
VertexDeclaration *vertexDecl = vertexData->vertexDeclaration;
int numVertexElements = vertexDecl->getElementCount();
size_t vertexSize = vertexDecl->getVertexSize(0) / sizeof(Real);
int vertexPosOffset = 0;
for(int i = 0; i < numVertexElements; i++)
{
if(vertexDecl->getElement(i)->getSemantic() == VES_POSITION)
vertexPosOffset = vertexDecl->getElement(i)->getOffset();
}
printf("vertexPosOffset = %d\n", vertexPosOffset);
IndexData *indexData = pSubMesh->indexData;
HardwareIndexBufferSharedPtr iBuf = indexData->indexBuffer;
long numIndices = indexData->indexCount;
unsigned short *pIndex = static_cast<unsigned short *>(iBuf->lock(HardwareBuffer::HBL_DISCARD));
if(pIndex == NULL)
printf("pIndex is NULL!\n");
VertexBufferBinding *vertexBinding = vertexData->vertexBufferBinding;
HardwareVertexBufferSharedPtr vBuf = vertexBinding->getBuffer(0);
long numVerts = vBuf->getNumVertices();
Real *pVertex = static_cast<Real*>(vBuf->lock(HardwareBuffer::HBL_DISCARD));
if(pVertex == NULL)
printf("pVertex is NULL!\n");
for(long i = 0; i < numVerts; i++)
{
Real *piVertex = pVertex + vertexPosOffset;
Real *x = (piVertex);
Real *y = (piVertex + 1);
Real *z = (piVertex + 2);
vertlist.push_back(*x * scale);
vertlist.push_back(*y * scale);
vertlist.push_back(*z * scale);
pVertex += vertexSize;
}
for(long i = 0; i < numIndices; i++)
{
indlist.push_back(pIndex + indoffset);
}
vBuf->unlock();
iBuf->unlock();
indoffset += indlist.size();
}
pMesh.setNull();
printf("Processed %d vertices\n", vertlist.size());
printf("Processed %d indices\n", indlist.size());
float *verts = (float *) malloc(sizeof(float) * vertlist.size());
for(unsigned int i = 0; i < vertlist.size(); i++)
{
verts = vertlist;
}
NxU32 *indices = (NxU32 *) malloc(sizeof(NxU32) * indlist.size());
for(unsigned int i = 0; i < indlist.size(); i++)
{
indices = indlist;
}
//node = obj->node->createChildSceneNode(_name);
node = Nxg::Nogredex_world::getSingleton().mSceneMgr->getRootSceneNode()->createChildSceneNode(_name);
node->attachObject(ent);
node->setPosition(pos);
NxTriangleMesh* bunnyMesh;
NxTriangleMeshDesc bunnyDesc;
bunnyDesc.numVertices = vertlist.size() / 3;
bunnyDesc.numTriangles = indlist.size() / 3;
bunnyDesc.pointStrideBytes = sizeof(NxVec3);
bunnyDesc.triangleStrideBytes = 3*sizeof(NxU32);
bunnyDesc.points = verts;
bunnyDesc.triangles = indices;
bunnyDesc.flags = 0;
bunnyDesc.materialIndexStride = sizeof(NxMaterialIndex);
NxInitCooking();
MemoryWriteBuffer buf;
bool status = NxCookTriangleMesh(bunnyDesc, buf);
MemoryReadBuffer readBuffer(buf.data);
bunnyMesh = Nxg::Nogredex_world::getSingleton().mPhysicsSDK->createTriangleMesh(readBuffer);
free(verts);
free(indices);
NxTriangleMeshShapeDesc bunnyShapeDesc;
bunnyShapeDesc.meshData = bunnyMesh;
bunnyShapeDesc.userData = this;
bunnyShapeDesc.shapeFlags = NX_SF_FEATURE_INDICES;
NxBodyDesc BodyDesc;
NxActorDesc ActorDesc;
ActorDesc.setToDefault();
BodyDesc.setToDefault();
BodyDesc.flags |= NX_BF_FROZEN_ROT_X|NX_BF_FROZEN_ROT_Z;
BodyDesc.linearDamping = 1.0f;
BodyDesc.angularDamping = 10.0f;
ActorDesc.shapes.pushBack(&bunnyShapeDesc);
ActorDesc.body = &BodyDesc;
ActorDesc.density = 0.1f;
ActorDesc.globalPose.t = toNx(pos);
ActorDesc.name = "ActorDesc";
ActorDesc.userData = this;
actor = Nxg::Nogredex_world::getSingleton().mScene->createActor(ActorDesc);
actor->userData = this;
actor->setGroup(Nxg::GROUP_DEFAULT);
Ogre::LogManager::getSingleton().logMessage("[Nogredex] Creating Object " + _name);
}
Nogredex_dynamicBody::~Nogredex_dynamicBody()
{ }
void Nogredex_dynamicBody::simulate(float _time)
{
node->setPosition( toOgre(actor->getGlobalPosition()) ) ;
node->setOrientation( toOgre(actor->getGlobalOrientation() ) );
}
Void NxVec3 Nogredex_dynamicBody::addForce(Ogre::Vector3 _force)
{
actor->addForce(toNx(_force), NX_FORCE);
simulate(0);
}
betajaen
17-10-2006 09:40:11
I'm not answering you if your using Nogredex, and I'm not answering you if you hand me bunch of random code, and just say fix it it - in so many words.
If you want to use PhysX with Ogre. Use NxOgre, it's that simple. Not some twisted piece of code above.