I'm designing a 3D game, in which I have a camera behind a spaceship to move around. I have added some asteroids in the game as well, and I want to add bullets. I used quaternions to control the path of the spaceship and the camera behind it. Nevertheless, when I use the same quaternions (the rotation in specific so that i can calculate the path of the bullet) on the bullet, I get a really funny effect and the paths are totally wrong. Any ideas as to why this happens?
public void Update(GameTime gameTime)
{
lazerRotation = spaceship.spaceShipRotation;
Vector3 rotVector = Vector3.Transform(new Vector3(0, 0, -1), lazerRotation);
Position += rotVector* 10 * (float)gameTime.ElapsedGameTime.TotalSeconds;
//
}
//spaceShipRotation = Quaternion.Identity;
//Quaternion additionalRot = Quaternion.CreateFromAxisAngle(new Vector3(0, -1, 0), leftRightRot) * Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), upDownRot);
//spaceShipRotation *= additionalRot;
//Vector3 addVector = Vector3.Transform(new Vector3(0, 0, -1), spaceShipRotation);
// futurePosition += addVector * movement * velocity;
public void Draw(Matrix view, Matrix projection)
{
// //Quaternion xaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 0, -1), spaceship.leftrightrot);
// //Quaternion yaxis = Quaternion.CreateFromAxisAngle(new Vector3(0, 1, 0), spaceship.updownrot);
// //Quaternion rot = xaxis * yaxis;
//Matrix x = Matrix.CreateRotationX(spaceship.leftrightrot);
//Matrix y = Matrix.CreateRotationY(spaceship.updownrot);
//Matrix rot = x * y;
Matrix[] transforms = new Matrix[Model.Bones.Count];
Model.CopyAbsoluteBoneTransformsTo(transforms);
Matrix worldMatrix = Matrix.CreateFromQuaternion(lazerRotation) * Matrix.CreateTranslation(Position);
foreach (ModelMesh mesh in Model.Meshes)
{
foreach (BasicEffect effect in mesh.Effects)
{
effect.World = worldMatrix * transforms[mesh.ParentBone.Index]; //position
effect.View = view; //camera
effect.Projection = projection; //2d to 3d
effect.EnableDefaultLighting();
effect.PreferPerPixelLighting = true;
}
mesh.Draw();
}
}
Have in mind that my spaceship is a field of the bullet object and that is how I get the spaceship. Rotation quaternion. Thanks in advance.