how to use the "WheelDescription"

z789017890

03-12-2010 10:58:14

how to use the "WheelDescription" to createWheelMachinePart

the createWheelMachinePart need the wheel?

thanks for your help

betajaen

03-12-2010 11:53:16

You've seen this right?

viewtopic.php?f=6&t=13598&p=76450&hilit=wheel#p76450

You really don't need to use the "Machine/WheelPart stuff", Just the things I have posted in that post.

z789017890

03-12-2010 12:40:27

i want to make a car with the git NXOGRE

how can i to do that?

z789017890

03-12-2010 12:53:36

You've seen this right?

viewtopic.php?f=6&t=13598&p=76450&hilit=wheel#p76450

You really don't need to use the "Machine/WheelPart stuff", Just the things I have posted in that post.


i need the "Machine/WheelPart stuff"

how can i to do that?

z789017890

03-12-2010 12:59:36

You've seen this right?

viewtopic.php?f=6&t=13598&p=76450&hilit=wheel#p76450

You really don't need to use the "Machine/WheelPart stuff", Just the things I have posted in that post.


that my code

struct VehicleWheel
{
Critter::PointRenderable* renderable;
Ogre::SceneNode *mNode;
NxOgre::WheelDescription *mWheel;
bool mDriving;
bool mSteering;
bool mBraking;
};



VehicleWheel* w = new VehicleWheel();

NxOgre::WheelDescription* mWheelD= new NxOgre::WheelDescription();
mWheelD->mRadius = radius;

if (VehicleModel::mEnableInputLongSlipVelocity)
mWheelD->mWheelFlags = NxOgre::Enums::WheelFlags_InputLongSlipVelocity;
else
{
mWheelD->mLongitudalTireFunction.mStiffnessFactor = VehicleModel::mLongitudalTireStiffnessFactor;
mWheelD->mLongitudalTireFunction.mExtremumSlip = VehicleModel::mLongitudalTireExtremumSlip;
mWheelD->mLongitudalTireFunction.mExtremumValue = VehicleModel::mLongitudalTireExtremumValue;
mWheelD->mLongitudalTireFunction.mAsymptoteValue = VehicleModel::mLongitudalTireAsymptoteValue;
mWheelD->mLongitudalTireFunction.mAsymptoteSlip = VehicleModel::mLongitudalTireAsymptoteSlip;

mWheelD->mLateralTireFunction.mStiffnessFactor = 700000;
}

mWheelD->mSuspension.mSpring = VehicleModel::mSuspensionSpring;
mWheelD->mSuspension.mDamper = VehicleModel::mSuspensionDamper;

mWheelD->mSuspensionTravel = VehicleModel::mSuspensionTravel;
mWheelD->mSuspension.mTargetValue = 0.5f;

mWheelD->mLocalPose.set(NxOgre::Vec3(pos.x, pos.y - mOffset, pos.z));

w->mWheel = mWheelD;

w->mDriving = driving;
w->mSteering = steering;
w->mBraking = braking;

mWheels.push_back(w);

Critter::PointRenderable* node = mRenderSystem->createPointRenderable(meshName);

w->mNode = node->getNode()->createChildSceneNode();
w->renderable = node;
assert(w->mNode != 0);
//createWheelMachinePart(w->mWheel, node);//can't use

z789017890

04-12-2010 13:19:39

who can help me ?

betajaen

04-12-2010 17:05:49

I found this old tutorial on my harddisk whilst I was looking for something else. I have no idea if it works, but it describes how to get a car running with the WheelMachinePart code:

#include "704.h"
#include "NxOgre.h"
#include "critter.h"

using namespace NxOgre;
using namespace Critter;

class Car;

Car* car;
Body* body;
float maxStrength = 1e7;

class Car : public NxOgre::Machine
{

public:

enum WheelID
{
Wheel_FrontLeft = 1,
Wheel_FrontRight = 2,
Wheel_BackLeft = 3,
Wheel_BackRight = 4
};

struct CarWheel
{

CarWheel() {}

CarWheel(NxOgre::Wheel* wheel, unsigned int id)
: mWheel(wheel), mID(id), mCanSteer(false), mCanDrive(false), mCanBrake(false)
{
}

static CarWheel makeWheel(NxOgre::Wheel* wheel, unsigned int id)
{

CarWheel wh(wheel, id);

// Front wheel drive.
if (id == Wheel_FrontLeft || id == Wheel_FrontRight)
{
wh.mCanSteer = true;
wh.mCanDrive = true;
wh.mCanBrake = true;
}
else if (id == Wheel_BackLeft || id == Wheel_BackRight)
{
wh.mCanBrake = true;
}

return wh;
}

NxOgre::Wheel* mWheel;
unsigned int mID;
bool mCanSteer;
bool mCanDrive;
bool mCanBrake;

};

Car(const NxOgre::Matrix44& globalPose, Critter::RenderSystem* rendersystem)
: mRenderSystem(rendersystem)
{
mScene = mRenderSystem->getScene();
_createCar(globalPose);
mScene->registerMachine(this);
}

~Car()
{
mScene->unregisterMachine(this);
}

void simulate(float time)
{
Machine::simulate(time);
mActor->wakeUp(100);
}

void setSteering(const NxOgre::Radian& angle)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanSteer)
(*it).second.mWheel->setSteeringAngle(angle);
}
}

void drive(float torque)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanDrive)
(*it).second.mWheel->setMotorTorque(torque);
}
}

void brake(float torque = 100)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanBrake)
(*it).second.mWheel->setBrakeTorque(torque);
}
}

private:

void _createCar(const NxOgre::Matrix44& globalPose)
{

RigidBodyDescription car_desc;
car_desc.mMass = 1000;
car_desc.mWakeUpCounter = 100;

ShapeDescriptions shapes;

BoxDescription chassis_desc;
chassis_desc.mSize.set(0.751, 0.275, 3.0);
shapes.push_back(&chassis_desc);

WheelDescription w_fl; // FrontLeft;
w_fl.mId = Wheel_FrontLeft;
w_fl.mRadius = 0.433 * 0.5f;
w_fl.mLocalPose.set(0.5f, 0, 1);
shapes.push_back(&w_fl);

WheelDescription w_fr; // FrontRight;
w_fr.mId = Wheel_FrontRight;
w_fr.mRadius = 0.433 * 0.5f;
w_fr.mLocalPose.set(-0.5f, 0, 1);
shapes.push_back(&w_fr);

WheelDescription w_bl; // BackLeft;
w_bl.mId = Wheel_BackLeft;
w_bl.mRadius = 0.433 * 0.5f;
w_bl.mLocalPose.set(0.5f, 0, -1);
shapes.push_back(&w_bl);

WheelDescription w_br; // BackRight;
w_br.mId = Wheel_BackRight;
w_br.mRadius = 0.433 * 0.5f;
w_br.mLocalPose.set(-0.5f, 0, -1);
shapes.push_back(&w_br);

mActor = mScene->createActor(shapes, globalPose, car_desc);
mPointRenderable = mRenderSystem->createPointRenderable("photon-frame.mesh");

CollisionModelIterator cm = mActor->getShapes();
while(cm != cm.end())
{
Shape* shape = (*cm);
cm++;
if (shape->getShapeType() == NxOgre::Classes::_Wheel)
{
Wheel* wheel = static_cast<Wheel*>(shape);
createWheelMachinePart(wheel, mRenderSystem->createPointRenderable("photon-wheel.mesh"));
mWheels[shape->getId()] = CarWheel::makeWheel(wheel, shape->getId());
}
}
}


Critter::RenderSystem* mRenderSystem;
NxOgre::Scene* mScene;
typedef std::map<unsigned int, CarWheel>::iterator WheelIterator;
typedef std::map<unsigned int, CarWheel> Wheels;

Wheels mWheels;

};

void NxOgre704::setupTutorial()
{
BodyDescription desc;
desc.mMass = 50;
body = mRenderSystem->createBody(BoxDescription(1,1,1), Vec3(5,8,0), "cube.1m.mesh", desc);
car = new Car(Vec3(0, 5, 0), mRenderSystem);
}

void NxOgre704::stopTutorial()
{
delete car;
}

bool NxOgre704::keyPressed(const OIS::KeyEvent& evt)
{

Vec3 force;

if (evt.key == OIS::KC_I)
force.z += 1;
else if (evt.key == OIS::KC_K)
force.z -= 1;
else if (evt.key == OIS::KC_J)
force.x -= 1;
else if (evt.key == OIS::KC_L)
force.x += 1;
else if (evt.key == OIS::KC_U)
force.y += 1;
else if (evt.key == OIS::KC_M)
force.y -= 1;

if (!force.isZero())
body->addForce(maxStrength * force * mLastTimeStep);

if (evt.key == OIS::KC_T)
body->setGlobalPosition(Vec3(0,1,0));



return SdkSample::keyPressed(evt);
}

bool NxOgre704::buttonPressed( const OIS::JoyStickEvent &arg, int button )
{
std::cout << "Down:" << button << std::endl;
return true;
}

bool NxOgre704::buttonReleased( const OIS::JoyStickEvent &arg, int button )
{
std::cout << "Up:" << button << std::endl;
if (button == 1)
{
car->mActor->setGlobalPosition(0,5,0);
car->mActor->setGlobalOrientationQuat(1,0,0,0);
}

return true;
}

bool NxOgre704::axisMoved( const OIS::JoyStickEvent &arg, int axis )
{
// Developed/Tested with a XBOX 360 controller.
// [0] Up/Down
// [1] Left/Right

// Torque
{
float a = (arg.state.mAxes[4].abs / 32768.f) * -500;
car->drive(a);
// std::cout << "Torque:" << a << "\n";
}

// Steering
{
float a = -0.785398163 * (arg.state.mAxes[1].abs / 32768.f);
car->setSteering(NxOgre::Radian(a));
// std::cout << "Steering:" << a << "\n";
}
#if 0
/*
for (unsigned int i=0; i < arg.state.mAxes.size(); ++i)
std::cout << "Axes:" << i << " => Abs:" << arg.state.mAxes[i].abs<< ", Rel: " << arg.state.mAxes[i].rel << ", AbsOnly: " << arg.state.mAxes[i].absOnly << "\n";
*/

std::cout << "Slider 0 => " << arg.state.mSliders[0].abX << ", " << arg.state.mSliders[1].abY << "\n";
std::cout << "Slider 1 => " << arg.state.mSliders[1].abX << ", " << arg.state.mSliders[1].abY << "\n";
std::cout << "Slider 2 => " << arg.state.mSliders[2].abX << ", " << arg.state.mSliders[2].abY << "\n";
std::cout << "Slider 3 => " << arg.state.mSliders[3].abX << ", " << arg.state.mSliders[3].abY << "\n";

for (unsigned int i=0; i < arg.state.mVectors.size(); ++i)
std::cout << "Vector:" << i << " =>" << arg.state.mVectors[i].x << ", " << arg.state.mVectors[i].y << ", " << arg.state.mVectors[i].z <<"\n";

std::cout << "POV: 0 => " << arg.state.mPOV[0].direction << "\n";
std::cout << "POV: 1 => " << arg.state.mPOV[1].direction << "\n";
std::cout << "POV: 2 => " << arg.state.mPOV[2].direction << "\n";
std::cout << "POV: 3 => " << arg.state.mPOV[3].direction << "\n";
#endif

// std::cout << arg.device->vendor() << std::endl;
// for (unsigned int i=0; i < arg.state.mAxes.size(); ++i)
// std::cout << "Axes:" << i << " =>" << arg.state.mAxes[i].abs << "\n";

// std::cout << "[0]" << arg.state.mVectors[0].x << ", " << arg.state.mVectors[0].y << ", " << arg.state.mVectors[0].z << "\n";
// std::cout << "[1]" << arg.state.mVectors[1].x << ", " << arg.state.mVectors[1].y << ", " << arg.state.mVectors[1].z << "\n";
// std::cout << "[2]" << arg.state.mVectors[2].x << ", " << arg.state.mVectors[2].y << ", " << arg.state.mVectors[2].z << "\n";
// std::cout << "[3]" << arg.state.mVectors[3].x << ", " << arg.state.mVectors[3].y << ", " << arg.state.mVectors[3].z << "\n";

//std::cout << arg.state.mAxes[axis].absOnly << "\n";
return true;
}

z789017890

05-12-2010 04:07:50

I found this old tutorial on my harddisk whilst I was looking for something else. I have no idea if it works, but it describes how to get a car running with the WheelMachinePart code:

#include "704.h"
#include "NxOgre.h"
#include "critter.h"

using namespace NxOgre;
using namespace Critter;

class Car;

Car* car;
Body* body;
float maxStrength = 1e7;

class Car : public NxOgre::Machine
{

public:

enum WheelID
{
Wheel_FrontLeft = 1,
Wheel_FrontRight = 2,
Wheel_BackLeft = 3,
Wheel_BackRight = 4
};

struct CarWheel
{

CarWheel() {}

CarWheel(NxOgre::Wheel* wheel, unsigned int id)
: mWheel(wheel), mID(id), mCanSteer(false), mCanDrive(false), mCanBrake(false)
{
}

static CarWheel makeWheel(NxOgre::Wheel* wheel, unsigned int id)
{

CarWheel wh(wheel, id);

// Front wheel drive.
if (id == Wheel_FrontLeft || id == Wheel_FrontRight)
{
wh.mCanSteer = true;
wh.mCanDrive = true;
wh.mCanBrake = true;
}
else if (id == Wheel_BackLeft || id == Wheel_BackRight)
{
wh.mCanBrake = true;
}

return wh;
}

NxOgre::Wheel* mWheel;
unsigned int mID;
bool mCanSteer;
bool mCanDrive;
bool mCanBrake;

};

Car(const NxOgre::Matrix44& globalPose, Critter::RenderSystem* rendersystem)
: mRenderSystem(rendersystem)
{
mScene = mRenderSystem->getScene();
_createCar(globalPose);
mScene->registerMachine(this);
}

~Car()
{
mScene->unregisterMachine(this);
}

void simulate(float time)
{
Machine::simulate(time);
mActor->wakeUp(100);
}

void setSteering(const NxOgre::Radian& angle)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanSteer)
(*it).second.mWheel->setSteeringAngle(angle);
}
}

void drive(float torque)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanDrive)
(*it).second.mWheel->setMotorTorque(torque);
}
}

void brake(float torque = 100)
{
for (WheelIterator it = mWheels.begin(); it != mWheels.end(); ++it)
{
if ((*it).second.mCanBrake)
(*it).second.mWheel->setBrakeTorque(torque);
}
}

private:

void _createCar(const NxOgre::Matrix44& globalPose)
{

RigidBodyDescription car_desc;
car_desc.mMass = 1000;
car_desc.mWakeUpCounter = 100;

ShapeDescriptions shapes;

BoxDescription chassis_desc;
chassis_desc.mSize.set(0.751, 0.275, 3.0);
shapes.push_back(&chassis_desc);

WheelDescription w_fl; // FrontLeft;
w_fl.mId = Wheel_FrontLeft;
w_fl.mRadius = 0.433 * 0.5f;
w_fl.mLocalPose.set(0.5f, 0, 1);
shapes.push_back(&w_fl);

WheelDescription w_fr; // FrontRight;
w_fr.mId = Wheel_FrontRight;
w_fr.mRadius = 0.433 * 0.5f;
w_fr.mLocalPose.set(-0.5f, 0, 1);
shapes.push_back(&w_fr);

WheelDescription w_bl; // BackLeft;
w_bl.mId = Wheel_BackLeft;
w_bl.mRadius = 0.433 * 0.5f;
w_bl.mLocalPose.set(0.5f, 0, -1);
shapes.push_back(&w_bl);

WheelDescription w_br; // BackRight;
w_br.mId = Wheel_BackRight;
w_br.mRadius = 0.433 * 0.5f;
w_br.mLocalPose.set(-0.5f, 0, -1);
shapes.push_back(&w_br);

mActor = mScene->createActor(shapes, globalPose, car_desc);
mPointRenderable = mRenderSystem->createPointRenderable("photon-frame.mesh");

CollisionModelIterator cm = mActor->getShapes();
while(cm != cm.end())
{
Shape* shape = (*cm);
cm++;
if (shape->getShapeType() == NxOgre::Classes::_Wheel)
{
Wheel* wheel = static_cast<Wheel*>(shape);
createWheelMachinePart(wheel, mRenderSystem->createPointRenderable("photon-wheel.mesh"));
mWheels[shape->getId()] = CarWheel::makeWheel(wheel, shape->getId());
}
}
}


Critter::RenderSystem* mRenderSystem;
NxOgre::Scene* mScene;
typedef std::map<unsigned int, CarWheel>::iterator WheelIterator;
typedef std::map<unsigned int, CarWheel> Wheels;

Wheels mWheels;

};

void NxOgre704::setupTutorial()
{
BodyDescription desc;
desc.mMass = 50;
body = mRenderSystem->createBody(BoxDescription(1,1,1), Vec3(5,8,0), "cube.1m.mesh", desc);
car = new Car(Vec3(0, 5, 0), mRenderSystem);
}

void NxOgre704::stopTutorial()
{
delete car;
}

bool NxOgre704::keyPressed(const OIS::KeyEvent& evt)
{

Vec3 force;

if (evt.key == OIS::KC_I)
force.z += 1;
else if (evt.key == OIS::KC_K)
force.z -= 1;
else if (evt.key == OIS::KC_J)
force.x -= 1;
else if (evt.key == OIS::KC_L)
force.x += 1;
else if (evt.key == OIS::KC_U)
force.y += 1;
else if (evt.key == OIS::KC_M)
force.y -= 1;

if (!force.isZero())
body->addForce(maxStrength * force * mLastTimeStep);

if (evt.key == OIS::KC_T)
body->setGlobalPosition(Vec3(0,1,0));



return SdkSample::keyPressed(evt);
}

bool NxOgre704::buttonPressed( const OIS::JoyStickEvent &arg, int button )
{
std::cout << "Down:" << button << std::endl;
return true;
}

bool NxOgre704::buttonReleased( const OIS::JoyStickEvent &arg, int button )
{
std::cout << "Up:" << button << std::endl;
if (button == 1)
{
car->mActor->setGlobalPosition(0,5,0);
car->mActor->setGlobalOrientationQuat(1,0,0,0);
}

return true;
}

bool NxOgre704::axisMoved( const OIS::JoyStickEvent &arg, int axis )
{
// Developed/Tested with a XBOX 360 controller.
// [0] Up/Down
// [1] Left/Right

// Torque
{
float a = (arg.state.mAxes[4].abs / 32768.f) * -500;
car->drive(a);
// std::cout << "Torque:" << a << "\n";
}

// Steering
{
float a = -0.785398163 * (arg.state.mAxes[1].abs / 32768.f);
car->setSteering(NxOgre::Radian(a));
// std::cout << "Steering:" << a << "\n";
}
#if 0
/*
for (unsigned int i=0; i < arg.state.mAxes.size(); ++i)
std::cout << "Axes:" << i << " => Abs:" << arg.state.mAxes[i].abs<< ", Rel: " << arg.state.mAxes[i].rel << ", AbsOnly: " << arg.state.mAxes[i].absOnly << "\n";
*/

std::cout << "Slider 0 => " << arg.state.mSliders[0].abX << ", " << arg.state.mSliders[1].abY << "\n";
std::cout << "Slider 1 => " << arg.state.mSliders[1].abX << ", " << arg.state.mSliders[1].abY << "\n";
std::cout << "Slider 2 => " << arg.state.mSliders[2].abX << ", " << arg.state.mSliders[2].abY << "\n";
std::cout << "Slider 3 => " << arg.state.mSliders[3].abX << ", " << arg.state.mSliders[3].abY << "\n";

for (unsigned int i=0; i < arg.state.mVectors.size(); ++i)
std::cout << "Vector:" << i << " =>" << arg.state.mVectors[i].x << ", " << arg.state.mVectors[i].y << ", " << arg.state.mVectors[i].z <<"\n";

std::cout << "POV: 0 => " << arg.state.mPOV[0].direction << "\n";
std::cout << "POV: 1 => " << arg.state.mPOV[1].direction << "\n";
std::cout << "POV: 2 => " << arg.state.mPOV[2].direction << "\n";
std::cout << "POV: 3 => " << arg.state.mPOV[3].direction << "\n";
#endif

// std::cout << arg.device->vendor() << std::endl;
// for (unsigned int i=0; i < arg.state.mAxes.size(); ++i)
// std::cout << "Axes:" << i << " =>" << arg.state.mAxes[i].abs << "\n";

// std::cout << "[0]" << arg.state.mVectors[0].x << ", " << arg.state.mVectors[0].y << ", " << arg.state.mVectors[0].z << "\n";
// std::cout << "[1]" << arg.state.mVectors[1].x << ", " << arg.state.mVectors[1].y << ", " << arg.state.mVectors[1].z << "\n";
// std::cout << "[2]" << arg.state.mVectors[2].x << ", " << arg.state.mVectors[2].y << ", " << arg.state.mVectors[2].z << "\n";
// std::cout << "[3]" << arg.state.mVectors[3].x << ", " << arg.state.mVectors[3].y << ", " << arg.state.mVectors[3].z << "\n";

//std::cout << arg.state.mAxes[axis].absOnly << "\n";
return true;
}


if i don't use the "createWheelMachinePart" can i create the car? and how to create it?

betajaen

05-12-2010 10:27:01

Wheel's are basically shapes, like Boxes or Capsules. You just create them along with the Actor (like you do with Boxes/Capsules/etc), but because your attaching more than one at a time; you use a ShapeDescriptions container.

i.e.

WheelDescription left;
... Setup left wheel here.
WheelDescription right;
... Setup right wheel here.
BoxDescription chassis
.... Setup chassis.

ShapeDescriptions shapes;
shapes.push_back(&left);
shapes.push_back(&right);
shapes.push_back(&chassis);

mScene->createActor or mRenderSystem->createBody(shapes, ...);


Those first two tutorials explain clearly how to do it, and that last tutorial I just posted explains it too; except afterwards it passes on the wheels into a Machine for ease of use. It also shows how to get the created Wheels (not the Descriptions) back and link them up to SceneNodes - which I assume is ideally you want.

z789017890

06-12-2010 08:55:07

let me try that , thanks for your help