Page 1 of 1

Irrnewt lock axes

Posted: Mon Jun 18, 2007 5:33 pm
by morph
I want to loch 1 or 2 axes of a collisions body has anybody an idear???

thanks for help

Posted: Mon Jun 18, 2007 9:21 pm
by Dances
Just reset its position to where you want it every frame before drawing.

Posted: Tue Jun 19, 2007 3:02 am
by olivehehe_03
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:

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 
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 :P

Posted: Tue Jun 19, 2007 11:44 am
by white tiger
The best solution to avoid rotation on certain axes is use a up vector joint. Check IUtils::avoidRotationOnAllAxes()

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);
}
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

Posted: Thu Jun 21, 2007 7:14 pm
by morph
ok it works thanks for the god help
has anybody a tuto for the IVehicle funktion

Posted: Thu Jun 21, 2007 11:37 pm
by olivehehe_03
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:
create a simple vehicle (IWorld::createVechicleSimple()) add the tires you want (IVechileSimple::addTire()) and rotate (setOmega) or move (setTorque) every tire you want manually
That's pretty much the basics of using an IVehicleSimple, just look in the documentation for a better description of each function

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 :D

Posted: Sat Jun 23, 2007 8:49 pm
by morph
can i have some example please

Posted: Sun Jun 24, 2007 10:44 am
by white tiger
has anybody a tuto for the IVehicle funktion
look at car example

Posted: Mon Jun 25, 2007 12:25 am
by olivehehe_03
morph wrote:can i have some example please
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 here

Posted: Tue Jun 26, 2007 12:50 pm
by morph
i have it but the setTorque do nothing ???