Page 1 of 1

Basic Scene Node Rotation?

Posted: Tue Feb 17, 2004 3:47 am
by thesmileman
Havent got a clue how to rotate an object in small increments around the objects center in one dimension aka a person turing in place.

I thought the code below would work but I am not sure what point it is rotating about it is certainly not (0,0,0)

Code: Select all

if(keys[KEY_KEY_U]){
   core::vector3df v = paddle1Node->getRotation();
   v.Z += 1.0f;
   paddle1Node->setRotation(v);
} 
So is there a way to set this point of rotation? I would assume so.

I know there are some other post dealing with rotation but they did not seem to apply. Thanks!

Posted: Tue Feb 17, 2004 10:54 pm
by thesmileman
Anyone out there that can help me?

Re: Basic Scene Node Rotation?

Posted: Tue Feb 17, 2004 11:34 pm
by Guest
Hi,

rotation: is alway about the center of origin of the scenenode. that is, if you load a mesh , lets say cube that is placed in the positive half of all axis, then a rotation will look like you are rotating around a side and not around the center of the cube. so you'l have to translate the cube to have the center at the origin (0,0,0) before rotating? hm.. never tried that... but this should be correct.

the orientation of things: if you use a standard camera scenenode (FPS- Maya- etc.) then a rotation around the upward axis of a model will be the rotation in XZ plane and the parameter you'l want to adjust is the Y-component of the rotation.

setting the axis of rotation: hmmmm... should be easy with the quaternion class in the new release (0.5) I don't know if there is a method for it so here's the code from my class:

Code: Select all

void Quaternion::FromAngleAxis (const Real& rfAngle,const Vector3& rkAxis)
{
	// assert:  axis[] is unit length
	//
	// The quaternion representing the rotation is
	//   q = cos(A/2)+sin(A/2)*(x*i+y*j+z*k)

	Real fHalfAngle = 0.5*rfAngle;
	Real fSin = Math::Sin(fHalfAngle);
	W = Math::Cos(fHalfAngle);
	X = fSin*rkAxis.X;
	Y = fSin*rkAxis.Y;
	Z = fSin*rkAxis.Z;
}
If you don't know about quaternions here's an introduction to it
http://www.magic-software.com the doc title to search for is 'Quaternion Algebra and Calculus' by David Eberly.

good luck
42

Posted: Wed Feb 18, 2004 12:49 am
by thesmileman
Thanks 42 for the help but I am a little confused about how to use what you have said. Could you explain how to use Queaternion or another method in Irrlicht?

Re: Basic Scene Node Rotation?

Posted: Wed Feb 18, 2004 1:41 am
by rt
thesmileman wrote: I thought the code below would work but I am not sure what point it is rotating about it is certainly not (0,0,0)

Code: Select all

if(keys[KEY_KEY_U]){
   core::vector3df v = paddle1Node->getRotation();
   v.Z += 1.0f;
   paddle1Node->setRotation(v);
} 
it's not rotation about a point, it's rotation about an axis. in your example code you are rotating the object around the z-axis.