Jump to content
  • Advertisement
Sign in to follow this  
chipmeisterc

XNA - -y = up?

This topic is 3781 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, Kind of confused, currently integrating the JigLibX physics api into my xna project, which is pretty interesting with no documentation, anyways I seem to be getting fairly far with it. However gravity appears to be pulling my object upwards!! After some debugging it would appear that the physics is returning sensible data -Y increments...however the model is moving up in screen space. My model rendering is based on the XNA spaceship model loading tutorial. Any ideas that immediatley spring out to you guys? Much appreciated! Chris! Rendering ->
public void Render()
        {
            Matrix[] transforms = new Matrix[m_Model.Bones.Count];
            m_Model.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in m_Model.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();

                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(m_Parent.m_Rotation);
                        //* Matrix.CreateTranslation( Vector3.UnitX );

                    effect.View = Matrix.CreateLookAt(Game1.GetActiveGame().GetCameraPosition(), m_Parent.GetPosition().GetAxisW() , Vector3.Up);
                    
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView( MathHelper.ToRadians(45.0f),
                                                                             Game1.GetActiveGame().GetAspectRatio(), 1.0f, 10000.0f
                                                                            );
                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
    }
Physics->
        public override void Update()
        {
            //m_Parent.GetPosition().SetAxisW(m_Parent.GetPosition().GetAxisW() - new Vector3(0.0f, 5.0f, 0.0f));
      
            m_Parent.GetPosition().SetAxisW(m_Body.Position );

            base.Update();
        }

Share this post


Link to post
Share on other sites
Advertisement
IIRC the default XNA sprite coord system has the origin at the top left corner and has positive y heading downwards. This is fairly standard for 2d computer coord systems (although personally I always prefer my origin to be bottom left with positive y upwards).

Unfortunately there's no easy way that I know of to override the ortho setup without writing your own sprite batch.

Share this post


Link to post
Share on other sites
Doh!

I was setting the camera look at position to look at the physics new position rather than the model transform so the model was stationary and the camera was panning downwards giving the apperance of my model moving up! *idiot*

Thanks anyways :)

Wrong:-

effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(m_Parent.m_Rotation);

//* Matrix.CreateTranslation( Vector3.UnitX );



effect.View = Matrix.CreateLookAt(Game1.GetActiveGame().GetCameraPosition(), m_Parent.GetPosition().GetAxisW() , Vector3.Up);



Fix
 effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(m_Parent.m_Rotation)
* Matrix.CreateTranslation(m_Parent.GetPosition().GetAxisW());
Vector3 origin = new Vector3(0.0f, 0.0f, 0.0f);
effect.View = Matrix.CreateLookAt(Game1.GetActiveGame().GetCameraPosition(), origin, Vector3.Up);


Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!