Game Development Community

dev|Pro Game Development Curriculum

PhysX in TGEA 1.8.1

by Ronald J Nelson · 04/05/2009 (8:38 am) · 50 comments

Thanks to alot of help from the Garage Games Community namely Ross Pawley, Gerald Fishel, and deepscratch I am putting up an updated version of the PhysX resource that is compatible with TGEA 1.8.1.

It comes with something extra though, PhysX actors react to objects using Polysoup thanks to Triangle Mesh Cooking. I am using PhysX SDK version 2.7.3 but this will probably work fine with later versions.

Of course none of this would be possible (by me at least) without the original work done by Shannon "ScarWars" Scarvaci and his resource found here:

www.garagegames.com/community/resources/view/12711

So follow his PhysX SDK instructions then use these files.

One more thing, if you have bought Konrad Kiss's BG Cliff Kit and installed the TGEa 1.8.1 version, I have emailed him files that will make this work on his cliffs as well.

Here are the files:
torque.abigholeintheweb.com/public_system/useruploads/PhysX_TGEA_1_8_1_v2.zip
Page«First 1 2 3 Next»
#41
11/06/2009 (12:22 pm)
Sorry Brad, not only am I still winging it with VS2005, I have moved on to the Bullet Physics Engine since the Game MEchanics Kit did so much of the ground work for me and Bullet also releases ALL of its source in the SDK.
#42
11/10/2009 (9:46 pm)
What do make Physx max file?
#43
11/28/2009 (11:54 pm)
Ron I was wondering do you do contract work? If so please contract myself at imaginationseven7@yahoo.com I try the email on your profile but it didn't work.

thanks
Kory James
#44
11/29/2009 (1:09 am)
I am afraid my ability to do contract work is severely limited these days as I am still active duty in the Air Force and I am not a T3D owner yet. As for my email, you might want to double check, because that is the same address everyone else reaches me at or they catch me on MSN which is also listed in my profile.
#45
11/30/2009 (2:49 am)
thanks.....I has ravel out....
#46
11/30/2009 (12:42 pm)
Szzg007 - I am not much of a modeller, but really the models as far as I have tested can just be dts models.
#47
01/16/2010 (6:39 am)
This is old, kind of pointless, but if someone finds it useful, great. This code will give you a basic flying vehicle that parents back to a PhysXActor instead of ShapeBase. It doesn't work with the T3D PhysX implementation, but it does with the old PhysX resource.

Never was used for anything aside from a video I made years ago, and as such it never was really tested. Use at your own risk.

Based on TGE 1.5.1, but it's flyingVehicle, I doubt things have changed much.

Add these includes at the top of flyingVehicle.cpp:

#include "physX/PhysX.h"
#include "physX/PhysXActor.h"
#include "physX/PhysXWorld.h"
#include "physX/PhysXStream.h"

comment out the line "addToScene();" in bool FlyingVehicle::onAdd(). addToScene was already called in the parent class of Vehicle.

in updateForces, well, here's the new updateForces (pick this apart with winmerge for extra fun):

#48
01/16/2010 (6:40 am)
void FlyingVehicle::updateForces(F32 /*dt*/)
{
   MatrixF currPosMat = getTransform();
   //mRigid.getTransform(&currPosMat);
   //mRigid.atRest = false;

   Point3F massCenter;
   currPosMat.mulP(mDataBlock->massCenter,&massCenter);

   Point3F xv,yv,zv;
   currPosMat.getColumn(0,&xv);
   currPosMat.getColumn(1,&yv);
   currPosMat.getColumn(2,&zv);
   F32 speed = getVelocity().len();

   Point3F force  = Point3F(0, 0, 0);
   Point3F torque = Point3F(0, 0, 0);

   // Drag at any speed
   Point3F forceTemp, torqueTemp;
   forceTemp.x = mActor->actor->getLinearVelocity().x;
   forceTemp.y = mActor->actor->getLinearVelocity().y;
   forceTemp.z = mActor->actor->getLinearVelocity().z;

   torqueTemp.x = mActor->actor->getAngularVelocity().x;
   torqueTemp.y = mActor->actor->getAngularVelocity().y;
   torqueTemp.z = mActor->actor->getAngularVelocity().z;

   //Con::printf("ROT VEL = %f %f %f", torqueTemp.x, torqueTemp.y, torqueTemp.z);

   force  -= forceTemp * mDataBlock->minDrag * mMass;
   torque = -torqueTemp * mDataBlock->rotationalDrag * mMass;

   //Con::printf("TORQUE: %f %f %f", torque.x, torque.y, torque.z);

   // Auto-stop at low speeds
   if (speed < mDataBlock->maxAutoSpeed) {
      F32 autoScale = 1 - speed / mDataBlock->maxAutoSpeed;

      // Gyroscope
      F32 gf = mDataBlock->autoAngularForce * autoScale;
      torque -= xv * gf * mDot(yv,Point3F(0,0,1));

      // Manuevering jets
      F32 sf = mDataBlock->autoLinearForce * autoScale;
      force -= yv * sf * mDot(yv, forceTemp);
      force -= xv * sf * mDot(xv, forceTemp);
   }

   // Hovering Jet
   F32 vf =  -sFlyingVehicleGravity * mMass * mGravityMod;
   F32 h  = getHeight();
   if (h <= 1) {
      if (h > 0) {
         vf -= vf * h;// * 0.1;
      } else {
         ;//vf += mDataBlock->jetForce * -h;
      }
   }
   else
   {
      vf = 0;
   }
   //force += zv * vf;

   // Damping "surfaces"
   force -= xv * speed * mDot(xv,forceTemp) * mDataBlock->horizontalSurfaceForce;
   force -= zv * speed * mDot(zv,forceTemp) * mDataBlock->verticalSurfaceForce;

   // Turbo Jet
   if (mJetting) {
      //Con::printf("!JETTING!");
      if (mThrustDirection == ThrustForward)
         force += yv * mDataBlock->jetForce * mCeilingFactor;
      else if (mThrustDirection == ThrustBackward)
         force -= yv * mDataBlock->jetForce * mCeilingFactor;
      else
         force += zv * mDataBlock->jetForce * mDataBlock->vertThrustMultiple * mCeilingFactor;
   }

   // Maneuvering jets
   force += yv * (mThrust.y * mDataBlock->maneuveringForce * mCeilingFactor);
   force += xv * (mThrust.x * mDataBlock->maneuveringForce * mCeilingFactor);

   // Steering
   Point2F steering;
   steering.x = mSteering.x / mDataBlock->maxSteeringAngle;
   steering.x *= mFabs(steering.x);
   steering.y = mSteering.y / mDataBlock->maxSteeringAngle;
   steering.y *= mFabs(steering.y);
   torque -= xv * steering.y * mDataBlock->steeringForce;
   torque -= zv * steering.x * mDataBlock->steeringForce;

   // Roll
   torque += yv * steering.x * mDataBlock->steeringRollForce;
   F32 ar = mDataBlock->autoAngularForce * mDot(xv,Point3F(0,0,1));
   ar -= mDataBlock->rollForce * mDot(xv, forceTemp);
   torque += yv * ar;

   // Add in force from physical zones...
   force += mAppliedForce;

   // Container buoyancy & drag
   force -= Point3F(0, 0, 1) * (mBuoyancy * sFlyingVehicleGravity * mMass * mGravityMod);
   //force -= forceTemp * mDrag * mMass;

   //
   NxVec3 tempVec(force.x, force.y, force.z);
   NxVec3 tempTorque(torque.x, torque.y, torque.z);
   //Con::printf("FORCE: %f %f %f", force.x, force.y, force.z);
   mActor->actor->addForce(tempVec, NX_IMPULSE, 1);
   //mActor->actor->setLinearMomentum(tempVec);
   //mActor->actor->setLinearVelocity(tempVec);
   mActor->actor->addTorque(tempTorque, NX_IMPULSE, 1);
   //mActor->actor->addLocalTorque(tempTorque, NX_FORCE, 1);
   //mRigid.force  = force;
   //mRigid.torque = torque;
}

#49
01/16/2010 (6:44 am)
You'll notice I left in lots of fun commented lines and absurd debug output just for whatever value it may have to someone trying to improve on this.

I also couldn't fix the hover jet in the short time I spent with this. See if you can have more luck; I just commented it out for now. Without the crashy/sinkyness of Rigid, it wasn't really a concern (use your jet trigger .. I think that's trigger 3.. to move up).

And one more function to replace:

void FlyingVehicle::readPacketData(GameConnection *connection, BitStream *stream)
{
   Parent::readPacketData(connection, stream);

   NxQuat tempRot = mActor->actor->getGlobalOrientationQuat();
   tempRot.invert();
   QuatF tempQuat;
   tempQuat.set(tempRot.x, tempRot.y, tempRot.z, tempRot.w);
   NxVec3 tempVec = mActor->actor->getGlobalPosition();
   Point3F tempPos(tempVec.x, tempVec.y, tempVec.z);

   //setPosition(mRigid.linPosition,mRigid.angPosition);
   mDelta.pos = tempPos;
   mDelta.rot[1] = tempQuat;
}

Not sure if this actually helps anything, but it's an exact mirror of what Rigid would have done here. I assume it was required, but feel free to play with this bit and see what happens.

That's flyingVehicle. Now to vehicle.h, where you replace the two instances of ShapeBaseData with PhysXActorData and the two instances of ShapeBase with PhysXActor.

Finally, three other files need those same #define lines from the start of the post, also at the top (or at least before vehicle.h):
wheeledvehicle.cpp
hovervehicle.cpp
aiwheeledvehicle.cpp (if you have this file.. my 1.5.1 did)
any other files that might, for some reason, mention vehicle.h.
Those defines should probably come from vehicle.h itself, but I'm not intending to update this; I've also moved on to using GMK's Bullet implementation at this point. :P

I think that'll do it. Your flying vehicle, while lacking its hover functionality, should interact very nicely with other PhysX objects. Obviously this code doesn't work w/ T3D PhysX, since it relies on having a ShapeBase-based PhysX class to hook into, and the actual Torque devs are too efficient to have based their PhysX objects on ShapeBase.

GMK's implementation of PhysX comes from ShapeBase, I believe, so you might have more luck there.

Finally, I'm going to assume I totally broke wheeled and hover vehicle, because I parented them to PhysXActor and never wrote specific PhysX code for them.
#50
03/17/2010 (10:41 am)
What are the odds that this resource will work in T3D?
Page«First 1 2 3 Next»