[nxOgre 101] How do I create a simple wheel?

megabyte

01-01-2008 22:03:17

Hi guys,
I just started to fiddle around with nxOgre. I like it very much for its simplicity. However, I am getting confused byt he lack of unified documentation. There's that sexy-looking short guide, but well, it just covers the basics.
I need to create a motorized wheel that could be attached to an actor or a body. I don't need any suspension. How would I do that?

Thanks in advance,
Serge.

betajaen

01-01-2008 22:08:34

Roughly.

mActor = mScene->createActor("name", new CubeShape(1), Vector3(0,0,0), "mass:10");

mActor->addShape(new WheelShape(0.5, Vector3(1,0,0));


Is the easiest, if you want a full blown car, then you should use a wheelSet. The forums has plenty of examples on how to do that.

megabyte

02-01-2008 06:30:02

That simple? Wow. Thanks a bunch!
One last question: how could I apply velocity and torque to it?

betajaen

02-01-2008 10:42:18

Intellisense people?


Wheel* mWheel static_cast<Wheel*>(mActor->addShape(new WheelShape(0.5, Vector3(1,0,0)));

mWheel->addMotorTorque(torqueValue);

megabyte

02-01-2008 18:35:53

Thanks again.
Is there a way to get Wheel* from a Body* or Actor*? eg.
Body* rBody = mScene->createBody("rBody; cube.1m.mesh", new CubeShape(1), Vector3(0, 5, 0), "mass: 50");
rBody->addShape(new WheelShape(1, "offset: 2 0 2"));
rBody->addShape(new WheelShape(1, "offset: -2 0 2"));
rBody->addShape(new WheelShape(1, "offset: 2 0 -2"));
rBody->addShape(new WheelShape(1, "offset: -2 0 -2"));

Then later, in another class, I need to get these Wheel*s back. How could I do that if I have my Scene* and rBody? Or do I have to pass an array of wheel pointers from class to class? I don't want to use a fourWheelSet, since the number of wheels is variable from run to run.

BTW, Intellisense has failed me on this one.

betajaen

02-01-2008 18:48:06

Look up. I just posted how to do it.

megabyte

05-01-2008 11:39:24

Oh thanks, I got it.
Ugh, one more question, sorry:
How do I nicely add a display entity to a NxShape*? That's what I'm doing right now in my frame listener:
NxU32 nbShapes = mScene->getActor("botBody")->getNxActor()->getNbShapes();
NxShape*const* shapes = mScene->getActor("botBody")->getNxActor()->getShapes();
int iter = 0;
while (nbShapes--) {
if (shapes[nbShapes]->isWheel()) {
theWheel = reinterpret_cast<NxWheelShape*>(shapes[nbShapes]);
theWheel_pos = Vector3(theWheel->getGlobalPosition().x, theWheel->getGlobalPosition().y, theWheel->getGlobalPosition().z);
wheel_nodes[iter]->setPosition(theWheel_pos);
iter++;
}
}

Unfortunately, only three of four of the meshes update their position, and I can't figure out how to convert from an NxMat33 to an Ogre quaternion. Also, is there a better way to do this? This looks a little bit over-complicated....

betajaen

05-01-2008 12:11:40

Can't you do it the normal way of doing wheels? Luis worked long and hard getting that working and displaying properly.

megabyte

05-01-2008 12:20:20

Can't you do it the normal way of doing wheels? Luis worked long and hard getting that working and displaying properly.
No, sorry. I really need to do it that way.
*sigh* I'll guess I'll just read trough the NxOgre Wheel code, to see how Luis made it work, and then adapt it to my needs.