I am developing a 3D game in which I have a camera behind a spaceship to move. I added some asteroids to the game, and I want to add ammo. I used quaternions to control the path of the spacecraft and the camera behind it. However, when I use the same quaternions (rotation in a specific one so that I can calculate the bullet path) on the pool, I get a really funny effect, and the paths are completely wrong. Any ideas as to why this is happening?
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(); } }
Keep in mind that my spaceship is the field of the bullet object, and that is how I get the spaceship. Rotational Quaternion. Thanks in advance.
source share