Irrnewt lock axes
Irrnewt lock axes
I want to loch 1 or 2 axes of a collisions body has anybody an idear???
thanks for help
thanks for help
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
I reckon you'd just need to set the rotation of the IrrNewt body every loop, for example if you want to lock the x axis do something like this:
EDIT: Haha, wasn't sure if you were talking about position or rotation. For rotation use the code above, for position just change "Rotation" to "Position" and it should work
Code: Select all
core::vector3df rot = body->getRotation();
body->setRotation(core::vector3df(0.0f, rot.Y, rot.Z); //0.0f is the value you want to lock rotation to
Tell me what you cherish most. Give me the pleasure of taking it away.
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
The best solution to avoid rotation on certain axes is use a up vector joint. Check IUtils::avoidRotationOnAllAxes()
so create a up vector joint with ParentBody set as the body you want to lock certain axes, PinDir to 0 in the axis you want to lock and 1 in the axis you don't want to lock ( 1,0,1 lock y axis ) and create the joint.
Please note you can't set PinDir to 0,0,0 to lock all axes (because it can't be normalize), this is the reason why avoidRotationOnAllAxes create 2 joints
Code: Select all
void irr::newton::IUtils::avoidRotationOnAllAxes(irr::newton::IBody* body) {
irr::newton::IJointUpVector* joint;
//avoid rotation on y axes
irr::newton::SJointUpVector jointData;
jointData.ParentBody=body;
jointData.PinDir.set(1,0,1);
joint = this->world->createJoint(jointData);
//avoid rotation on x and z axes
jointData.PinDir.set(0,1,0);
joint = this->world->createJoint(jointData);
}
Please note you can't set PinDir to 0,0,0 to lock all axes (because it can't be normalize), this is the reason why avoidRotationOnAllAxes create 2 joints
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
I wish I could help out a little more but it's too early for my brain to be working properly, so have a look at this:
EDIT: Just a quick note about addTire(), the tire will be attached wherever the scene node is, so move your scene node to where you want it relative to the chassis, then addTire(). Just thought I'd share that cos it was something that I got stuck on
That's pretty much the basics of using an IVehicleSimple, just look in the documentation for a better description of each functioncreate a simple vehicle (IWorld::createVechicleSimple()) add the tires you want (IVechileSimple::addTire()) and rotate (setOmega) or move (setTorque) every tire you want manually
EDIT: Just a quick note about addTire(), the tire will be attached wherever the scene node is, so move your scene node to where you want it relative to the chassis, then addTire(). Just thought I'd share that cos it was something that I got stuck on
Tell me what you cherish most. Give me the pleasure of taking it away.
-
- Posts: 269
- Joined: Tue Oct 31, 2006 3:24 pm
- Contact:
-
- Posts: 157
- Joined: Tue Mar 20, 2007 8:30 am
The best way to learn things (in my opinion) is trial and error. Try it yourself and if it doesn't work, find where you went wrong, fix it and try again. Also, IrrNewt (as well as Irrlicht) has really good documentation, so learn how to use it if you get stuck. You'll learn things alot quicker that way than you will copying and pasting code off heremorph wrote:can i have some example please
Tell me what you cherish most. Give me the pleasure of taking it away.