Vectors and Rotation - Problems With XY Rotation

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Taonas
Posts: 4
Joined: Tue Oct 28, 2008 7:21 pm

Vectors and Rotation - Problems With XY Rotation

Post by Taonas »

Hi,

I've been bashing my head for at least 2 hours over an issue which I haven't been able to fix. I am trying to update a particle emitters direction so particles always come out at a certain vector (in this case 0, 1, 0) from a parent object.

So if the parent object rotates in any dimension the particles still appear to be coming out of the top of the object.

Code: Select all

irr::core::vector3df direction(0, 1, 0);
irr::core::vector3df centre(0, 0, 0);
direction.rotateXYBy(parent->getGraphicsObject()->getRotation().Z, centre);
direction.rotateXZBy(parent->getGraphicsObject()->getRotation().Y, centre);
direction.rotateYZBy(parent->getGraphicsObject()->getRotation().X, centre);
this->emitter->setDirection(direction);
This appeared to work until I found out that rotateXYBy() was no making any changes on the vector. So if the parent object angled skywards the particles still just went straight up rather than coming up / backwards a bit.

I find a picture helps;

Image

Basically the two engines in green should have the two flame emitters firing as the red lines indicate. The engines have a rotation of (0, 0, 90) which the above code picks up and rotates the direction so it's horizontal not vertical. But it still doesn't rotate around the Y axis.

I know this is probably a very stupid mistake on my part but I cant work it out, any help is greatly appreciated.
MasterGod
Posts: 2061
Joined: Fri May 25, 2007 8:06 pm
Location: Israel
Contact:

Post by MasterGod »

Did you knew about this method of vector3d?

Code: Select all

//! Builds a direction vector from (this) rotation vector.
		/** This vector is assumed to hold 3 Euler angle rotations, in degrees.
		The implementation performs the same calculations as using a matrix to
		do the rotation.
		\param[in] forwards  The direction representing "forwards" which will be
		rotated by this vector.  If you do not provide a
		direction, then the positive Z axis (0, 0, 1) will
		be assumed to be fowards.
		\return A vector calculated by rotating the forwards direction by
		the 3 Euler angles that this vector is assumed to represent. */
		vector3d<T> rotationToDirection(const vector3d<T> & forwards = vector3d<T>(0, 0, 1)) const
		{
			const f64 cr = cos( core::DEGTORAD64 * X );
			const f64 sr = sin( core::DEGTORAD64 * X );
			const f64 cp = cos( core::DEGTORAD64 * Y );
			const f64 sp = sin( core::DEGTORAD64 * Y );
			const f64 cy = cos( core::DEGTORAD64 * Z );
			const f64 sy = sin( core::DEGTORAD64 * Z );

			const f64 srsp = sr*sp;
			const f64 crsp = cr*sp;

			const f64 pseudoMatrix[] = {
				( cp*cy ), ( cp*sy ), ( -sp ),
				( srsp*cy-cr*sy ), ( srsp*sy+cr*cy ), ( sr*cp ),
				( crsp*cy+sr*sy ), ( crsp*sy-sr*cy ), ( cr*cp )};

			return vector3d<T>(
				(T)(forwards.X * pseudoMatrix[0] +
					forwards.Y * pseudoMatrix[3] +
					forwards.Z * pseudoMatrix[6]),
				(T)(forwards.X * pseudoMatrix[1] +
					forwards.Y * pseudoMatrix[4] +
					forwards.Z * pseudoMatrix[7]),
				(T)(forwards.X * pseudoMatrix[2] +
					forwards.Y * pseudoMatrix[5] +
					forwards.Z * pseudoMatrix[8]));
		}
Taken from vector3d.h

I'm not sure but this might be what you're looking for.

P.S
I think one of the examples is using it, I'm not sure - worth to check (by you of course).
Image
Dev State: Abandoned (For now..)
Requirements Analysis Doc: ~87%
UML: ~0.5%
Taonas
Posts: 4
Joined: Tue Oct 28, 2008 7:21 pm

Post by Taonas »

I just checked but I don't appear to have this function in my version 1.4.2 (downloaded from site)

Thank you though, as I just made a modified copy of that function and it worked perfectly
Post Reply