James
11-01-2010 07:31:20
I read the vehicles codes from PhysX samples , but i have no idea on how to use bloodymess for it. I'm confused by machine/machinePart/wheel...
anyone help me? thanks!
anyone help me? thanks!
James
11-01-2010 07:31:20
hevi
19-01-2010 11:43:54
spacegaier
19-01-2010 11:59:27
hevi
19-01-2010 12:28:07
hevi
19-01-2010 20:06:49
I read the vehicles codes from PhysX samples , but i have no idea on how to use bloodymess for it. I'm confused by machine/machinePart/wheel...
anyone help me? thanks!
class Car : public NxOgre::Machine
{
public:
Car(const Vec3& position, Scene* scene, OGRE3DRenderSystem* renderSystem) : Machine(), mScene(scene), mRenderSystem(renderSystem)
{
RigidBodyDescription description;
description.mMass = 1000; // Make it heavy.
description.mWakeUpCounter = 1E8; // Never go to sleep.
NxOgre::Shapes shapes;
mChassisShape = new NxOgre::Box(0.751, 0.275, 3.0);
shapes.insert(mChassisShape);
addWheel(Vec3(-0.5,0,1), true, true, true);
addWheel(Vec3(0.5,0,1), true, true, true);
addWheel(Vec3(-0.5,0,-1), false, false, true);
addWheel(Vec3(0.5,0,-1), false, false, true);
for (unsigned int i=0;i < mWheels.size();i++)
shapes.insert(mWheels[i].mWheel);
mActor = mScene->createActor(shapes, position, description);
mPointRenderable = mRenderSystem->createPointRenderable("photon-frame.mesh");
mScene->registerMachine(this);
}
~Car()
{
mScene->unregisterMachine(this);
}
void addWheel(const Vec3& position, bool driving, bool steering, bool braking)
{
CarWheel w;
// Create the physics wheel, which our rules and point renderable will represent and work with.
WheelBlueprint* blueprint = new WheelBlueprint();
blueprint->mRadius = 0.433f * 0.5f;
blueprint->mLocalPose.set(position);
w.mWheel = new Wheel(blueprint);
// Create our rules about this wheel.
w.mDriving = driving;
w.mSteering = steering;
w.mBraking = braking;
mWheels.insert(w);
// Then create the machine part of that wheel, so rules can be applied to it, and it can be rendered.
createWheelMachinePart(w.mWheel, mRenderSystem->createPointRenderable("photon-wheel.mesh"));
}
void drive(float torque)
{
for (unsigned int i=0;i < mWheels.size();i++)
if (mWheels[i].mDriving)
mWheels[i].mWheel->setMotorTorque(torque);
}
void brake(float torque)
{
for (unsigned int i=0;i < mWheels.size();i++)
if (mWheels[i].mBraking)
mWheels[i].mWheel->setBrakeTorque(torque);
}
void steer(float angle)
{
for (unsigned int i=0;i < mWheels.size();i++)
if (mWheels[i].mSteering)
mWheels[i].mWheel->setSteeringAngle(angle);
}
protected:
struct CarWheel
{
Wheel* mWheel;
bool mDriving;
bool mSteering;
bool mBraking;
};
NxOgre::Array<CarWheel> mWheels;
Scene* mScene;
OGRE3DRenderSystem* mRenderSystem;
NxOgre::Box* mChassisShape;
};
James
22-01-2010 08:50:46