c# - xna 3d bullet bath and draw method gone wrong -


i'm designing 3d game, in have camera behind spaceship move around. have added asteroids in game well, , want add bullets. used quaternions control path of spaceship , camera behind it. nevertheless, when use same quaternions (the rotation in specific can calculate path of bullet) on bullet, funny effect , paths totally wrong. ideas why 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 3d                  effect.enabledefaultlighting();                 effect.preferperpixellighting = true;             }             mesh.draw();         }     } 

have in mind spaceship field of bullet object , how spaceship. rotation quaternion. in advance.

you should concatenate effect.world matrix opposite of order doing it. shouldn't affect shape of object solve other problems. should this:

effect.world = transforms[mesh.parentbone.index] * worldmatrix; 

xna row major framework, concatenation left right. code (right left) how opengl, column major framework.


Comments