Irrnewt lock axes

Post your questions, suggestions and experiences regarding game design, integration of external libraries here. For irrEdit, irrXML and irrKlang, see the
ambiera forums
Post Reply
morph
Posts: 10
Joined: Sun Jun 03, 2007 10:19 pm

Irrnewt lock axes

Post by morph »

I want to loch 1 or 2 axes of a collisions body has anybody an idear???

thanks for help
Dances
Posts: 454
Joined: Sat Jul 02, 2005 1:45 am
Location: Canada
Contact:

Post by Dances »

Just reset its position to where you want it every frame before drawing.
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post 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
Tell me what you cherish most. Give me the pleasure of taking it away.
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post 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
morph
Posts: 10
Joined: Sun Jun 03, 2007 10:19 pm

Post by morph »

ok it works thanks for the god help
has anybody a tuto for the IVehicle funktion
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post 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
Tell me what you cherish most. Give me the pleasure of taking it away.
morph
Posts: 10
Joined: Sun Jun 03, 2007 10:19 pm

Post by morph »

can i have some example please
white tiger
Posts: 269
Joined: Tue Oct 31, 2006 3:24 pm
Contact:

Post by white tiger »

has anybody a tuto for the IVehicle funktion
look at car example
olivehehe_03
Posts: 157
Joined: Tue Mar 20, 2007 8:30 am

Post 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
Tell me what you cherish most. Give me the pleasure of taking it away.
morph
Posts: 10
Joined: Sun Jun 03, 2007 10:19 pm

Post by morph »

i have it but the setTorque do nothing ???
Post Reply