PhysX Implementation Questions
by Ronald J Nelson · in Torque Game Engine Advanced · 10/19/2008 (11:03 pm) · 66 replies
I have implemented PhysX into my code. With that I have some questions about some things since I have noticed no one has been updating the stuff on TDN.
1. Has anyone gotten it to work with Polysoup, since Polysoup is stock with TGEA 1.7.1 I figured someone might have by now.
2. Has anyone gotten vehicle collisions to work properly with it yet?
3. Has anyone gotten a working example of using links that they are willing to share?
Thanks in advance.
1. Has anyone gotten it to work with Polysoup, since Polysoup is stock with TGEA 1.7.1 I figured someone might have by now.
2. Has anyone gotten vehicle collisions to work properly with it yet?
3. Has anyone gotten a working example of using links that they are willing to share?
Thanks in advance.
#62
10/27/2008 (7:33 pm)
It's not actually very difficult. It's one function. Look in the PhysX documents. You just call the function, it either returns a struct of some sort or you pass it one that it fills. It will have all the information of whether or not it got a hit. You'll use the "time" value to scale the position of the player, to move him back. You'll want to do this whereever it updates the player position in player.cpp. There is sample code for the sweep tests available.
#63
10/27/2008 (7:47 pm)
You might instead take a look at the character controller code that PhysX has. It has the full source code, so you can always make changes to it. There are also a couple of demos for it.
#64
Does this look about right to you?
I am assuming you mean the "t" variable member of NxSweepQueryHit is the time value you mentioned even though it says in the docs it is the distance to the hit.
Now finally, What do you mean scale the position of the object,? That is about the only thing I really have no idea what you mean.
10/27/2008 (8:51 pm)
Ok well I am starting this out.void Vehicle::updatePos(F32 dt)
{
Point3F origVelocity = mRigid.linVelocity;
if (isServerObject())
{
PhysXWorld *PxWorld = PhysXWorld::getWorld(isServerObject());
if (PxWorld)
{
// const NxVec3 &motion = NxVec3(origVelocity.x, origVelocity.y, origVelocity.z);
NxU32 flags = NX_SF_STATICS|NX_SF_DYNAMICS;
NxSweepQueryHit result;
float dist = 100.0f;
NxVec3 dir(0.0f, -1.0f, 0.0f);
mActor->actor->linearSweep(dir*dist, flags, NULL, 1, &result, NULL);
}
}Does this look about right to you?
I am assuming you mean the "t" variable member of NxSweepQueryHit is the time value you mentioned even though it says in the docs it is the distance to the hit.
Now finally, What do you mean scale the position of the object,? That is about the only thing I really have no idea what you mean.
#65
10/28/2008 (1:26 pm)
OK I have another question as I can see I had the option of adding more to the function which is the NxUserEntityReport which apparently calls a function for the closest object in the sweep. Did you use this?
#66
Here is my code. Please tell me what I have done wrong.
10/28/2008 (10:41 pm)
OK Ross I really need your help. I know now that I am extremely close with this but I am definitely handling the shape repositioning wrong because it is bounces madly and is nearly uncontrollable. However, I do know from the very few times I could contrl the vehicle enough to try to collide with the Triangle Mesh object I am using that it definitely detects it and reacts to it.Here is my code. Please tell me what I have done wrong.
if (isServerObject())
{
PhysXWorld *PxWorld = PhysXWorld::getWorld(isServerObject());
if (PxWorld)
{
static NxF32 t = 0.0f;
NxF32 elapsedTime = dt;
t += elapsedTime;
float dist = 100.0f;
NxVec3 dir(0.5f, -1.0f, 0.0f);
dir.normalize();
NxU32 flags = NX_SF_STATICS|NX_SF_DYNAMICS;
NxSweepQueryHit results[100];
NxU32 nb = mActor->actor->linearSweep(dir*dist, flags, NULL, 100, results, NULL);
NxBox shapeBox;
if(nb)
{
mActor->actor->getShapes()[0]->isBox()->getWorldOBB(shapeBox);
shapeBox.center += results[0].t * dist * dir;
Point3F shapeCenter;
shapeCenter.set(shapeBox.center.x, shapeBox.center.y, shapeBox.center.z);
mRigid.linPosition = shapeCenter;
}
}
}
Torque Owner Ronald J Nelson
Code Hammer Games