Applying Quaternion Rotation To A Vector

This topic is 3593 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Alright, I am making a program in C#/XNA and I have some Particles which are emitted from an Emitter. The Particle's are given some initial 3D velocity, such as Vector3(50, 0, 0). The Emitter has a quaternion representing it's rotation, and I want it so that when the Emitter is rotated, it affects the starting velocity of the Particles (i.e. so it always looks like particle's are emitted from the top of the emitter), but I just can't get it to work. This is how I assumed it would be done:
// Initialize Particle Properties
cParticle.cVelocity = new Vector3(50, 0, 0);

// Rotate the Emitter around the Z-axis according to some Angle
mcEmitter.mcRotation = new Quaternion(Vector3.Forward, mfAngle);
mcEmitter.mcRotation.Normalize();

// Rotate the Particle according to the Emitter
cParticle.cVelocity = Vector3.Transform(cParticle.cVelocity, mcEmitter.mcRotation);


I'm sure I'm doing something wrong with how I'm rotating the Velocity vector, but I'm not sure what. Can anybody see the problem? Thanks. [Edited by - deadlydog on September 19, 2008 10:54:09 AM]

Share on other sites
I got it, I was just defining a quaternion, instead of computing the actual rotation quaternion that I wanted, so the line:

mcEmitter.mcRotation = new Quaternion(Vector3.Forward, mfAngle);

just needed to be replaced with:

mcEmitter.mcRotation = Quaternion.CreateFromAxisAngle(Vector3.Forward, mfAngle);

So simple I kept overlooking it.

1. 1
2. 2
3. 3
Rutin
19
4. 4
5. 5

• 14
• 30
• 13
• 11
• 11
• Forum Statistics

• Total Topics
631780
• Total Posts
3002314
×