Xna 3d bullet bath and drawing method are wrong

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.

+4
source share
2 answers

You must concatenate the effect. The world matrix is ​​the opposite of the order you are doing now. This should not affect the shape of the object, but will solve other problems. It should be like this:

 effect.World = transforms[mesh.ParentBone.Index] * worldMatrix; 

XNA is the basic structure of a string; concatenation is from left to right. Your code (from right to left) is how you do it for OpenGL, the main structure of the column.

+2
source

I understand that based on your code, your shells change direction after being fired if your ship changes direction.

You need to create a projectile object and save the direction of each individual projectile for each projectile object. When the projectile is created, you will set its direction in the same way as the ship (as you did above). However, for the rest of the life of this projectile, you do not need to change direction.

Example: Bullet 1 starts from POINT A in the direction of POINT B, then the ship turns and launches Bullet 2 from POINT C to POINT D.

Bule 1 and 2 will have unique vectors along which they move.

+1
source

All Articles