Page 1 of 2

In Place Rotation

Posted: Mon Sep 26, 2005 11:31 am
by Guest
How does one rotate a mesh in its place. Whats happening on my case is that it revolves around the origin...This is my code...

Code: Select all

void RotateMotor1(char a){
	irr::core::vector3df v;
	irr::core::matrix4 m;
	irr::core::matrix4 n;
	irr::core::vector3df origpos;
	irr::core::vector3df start;
	
	ISNrotmotor1->setParent(smgr->getRootSceneNode());
	ISNarm1->setParent(ISNrotmotor1);
	ISNrotmotor2->setParent(ISNarm1);
	ISNarm2->setParent(ISNrotmotor2);
	ISNwrist1->setParent(ISNarm2);
	ISNwrist2mot->setParent(ISNwrist1);
	ISNwrist2des->setParent(ISNwrist2mot);
	ISNlfinger->setParent(ISNwrist2des);
	ISNrfinger->setParent(ISNwrist2des);
	
	origpos = ISNrotmotor1->getPosition();
	//start = smgr->getRootSceneNode()->getPosition();
	start = irr::core::vector3df(0.0f, 0.0f, 0.0f);
	
	ISNrotmotor1->setPosition(ISNbase->getPosition());
	if(a=='l'){
		v = irr::core::vector3df(0.0f, -0.2f, 0.0f);
	}
	else if(a=='r'){
		v = irr::core::vector3df(0.0f, 0.2f, 0.0f);
	}
	m.setRotationDegrees(ISNrotmotor1->getRotation());
	n.setRotationDegrees(v);
	m *= n;
	
	//ISNrotmotor1->setRotation(ISNrotmotor1->getRotation() + v);
	ISNrotmotor1->setRotation(m.getRotationDegrees());
	ISNrotmotor1->setPosition(origpos);
	
}//end of RotateMotor1()

Posted: Mon Sep 26, 2005 4:58 pm
by CZestmyr
I'm not sure that I understand why you parent the nodes everytime you want to
rotate a part of the body. And why do you change position of the nodes, when you only want to rotate them?

And why do you calculate the angles through matrices? Wouldn't vectors be sufficient?

Posted: Mon Sep 26, 2005 5:24 pm
by Guest
Well for starters, I'm debugging it so it looks that way...because the main problem is that when I'm rotating a mesh it rotates not on its own but according to the origin coordinates...this is why I'm trying to change its position and rotating it and back again...Sadly, it still doesnt work or my algo is just wrong...

Well I'm desperate so I've matrices to create another solution but at first it was the vectors...that is why there is a lot of "//" since I'm trying a lot of things out but still ahvent worked...

I'm desperate for a solution and I've run out of ideas...I need help...

Posted: Tue Sep 27, 2005 8:22 am
by dhenton9000
I'm jumping in here cold, but when I ran into this problem, I found I had to translate to origin, rotate, translate back to position.

Code: Select all

	fixmat.makeIdentity();
	rotmat.makeIdentity();
	rotmat.setRotationDegrees(rotate);

	
	unfixmat.setTranslation(vector3df(m_size.X/2,m_size.Y/2, m_size.Z/2) );
	fixmat = fixmat* unfixmat ;
	fixmat = fixmat * rotmat;
 
	m_playerNode->setPosition(place +fixmat.getTranslation());
	m_playerNode->setRotation(fixmat.getRotationDegrees());

Say I've got a box at position 5,5,5. I want to rotate it in place 45 degrees. I translate it to the origin, then I rotate it, then I translate it back to 5,5,5 by building a matrix stack, in the example above that stack is fixmat.

The OpenGL red book has a great discussion on matrix stacks.

HTH

Just a comment:

Posted: Tue Sep 27, 2005 9:35 am
by Thulsa
OGL (as 95% of math books) works with right hand side,
DirectX (as Irrlicht) with left hand side algebra.
Both are consistent, but be aware of it.

Posted: Tue Sep 27, 2005 1:22 pm
by Guest
questions about the code...

-what are the variables? matrix4?
-what does the variables contain?
-why /2?

Posted: Tue Sep 27, 2005 9:36 pm
by dhenton9000
Anonymous wrote:questions about the code...

-what are the variables? matrix4?
-what does the variables contain?
-why /2?

sorry, this piece of code is out of context. Now that I think of it, this is probably useless to show. Probably best to ignore it. It does show how to create your stack in Irrlicht, via matrix operator *. Matrix4 is the Irrlicht matrix class, part of core:

Posted: Wed Sep 28, 2005 3:45 am
by Guest
how do u get the origin because when I'm using

setPosition(vector3df(0.0, 0.0, 0.0));

it still wont go to the origin...

Posted: Wed Sep 28, 2005 5:03 am
by Guest
I have also tried

smgr->getRootSceneNode()->getPosition();

and also

setPosition(orginalPosition * vector3df(-1.0,-1.0,-1.0)); -> inverse

it still doesnt go to the origin...

Posted: Wed Sep 28, 2005 9:40 am
by Thulsa
Anonymous wrote:how do u get the origin because when I'm using

setPosition(vector3df(0.0, 0.0, 0.0));

it still wont go to the origin...

You're parent child setting in the beginnig of you're function seems traceable.

As I understand it, using setPosition(..) on a scenenode set's the relative position according to the parent. If origin of parents coordinate system differs from the global origin, I would expect all relativ transforms to act in the parent's coordinate frame. Also you could use getAbsolutePosition() to retrieve global coordinates. Anyway setting global coordinates of a scenenode, are allways transformed by the parent's coords (if the's a parent) in the OnPostRender() call.

Posted: Wed Sep 28, 2005 1:04 pm
by dhenton9000
I'm worse than a dog with a bone. Here's a simple spinning cube, spinning around its center point, and the cube is not at the origin.

This probably isn't what you are talking about, but may be you can use it to get at what you need. The motor example is way too complex for me. See if this helps or rewrite it to illustrate your issue and maybe I can figure out whats up.

http://www.sendmefile.com/00101485

Posted: Wed Sep 28, 2005 5:42 pm
by Guest
Problem is that the meshes always say that they are on 0,0,0 even when Absolute and Relative is used...and still they are not rotating on place...when I move them to the original 0,0,0 (got the coordinates when I was doing the model in 3D Studio Max) and still wont work...

My code: (go to the RotateMotor1 function, all my work is there...)
http://www.geocities.com/revin122/revsept29.zip[/url]

Posted: Wed Sep 28, 2005 6:40 pm
by dhenton9000
No luck on the link.

BTW, I had a problem like this, its seems that modifications to a node won't stick unless you issue updateAbsolutePosition. I had a box that newton was bouncing all over the place but irrlicht thought it was a 0,0,0. Sounds like something similar, perhaps?

Posted: Thu Sep 29, 2005 2:13 am
by Guest

Posted: Thu Sep 29, 2005 2:16 am
by Guest
wtf...just go to

www.geocities.com/revin122/

then download the revsept29.zip (or something similar)...