# Applying Quaternion Rotation To A Vector

## 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.

## Create an account

Register a new account

• ### Forum Statistics

• Total Topics
627701
• Total Posts
2978700

• 21
• 14
• 12
• 10
• 12