Jump to content
  • Advertisement
Sign in to follow this  
deadlydog

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.

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!