Jump to content
  • Advertisement
Sign in to follow this  
xchimera

my model points upwars when i adjust yaw

This topic is 2077 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

Hi i am making a space game and i am trying to make my model move. i want my model to tilt a bit and then turn. However when i do that my model begins to point upwards when i press the button and i am thinking that it is because my model is rolled a bit. i have tried subtracting the amount of yaw from pitch, but that did nothing. here is my code:

 

            if (keyboardState.IsKeyDown(Keys.A))
            {
                
                if ( tempRoll  > -MathHelper.ToRadians(45 /2))
                {
                    rollAngle -= MathHelper.ToRadians(turningSpeed);

                }
                   yawAngle -= tempRoll / 10;
                    //direction.X -= rollAngle;
            }

            if (keyboardState.IsKeyDown(Keys.D))
            {
                if (tempRoll < MathHelper.ToRadians(45 / 2))
                {
                    rollAngle += MathHelper.ToRadians(turningSpeed);

                }                    
                yawAngle += -tempRoll / 10;
                pitchAngle += pitchAngle - yawAngle;


                //direction.X += -rollAngle;
            }
            tempRoll += rollAngle;
            tempYaw += yawAngle;
            tempYaw = MathHelper.Clamp(tempYaw, 0, 0.01f);

 

Share this post


Link to post
Share on other sites
Advertisement

this is my complete update method

 

            ProcessKeyboard(gametime);
            world *= Matrix.CreateTranslation(direction);
            rotation *= Matrix.CreateFromYawPitchRoll(yawAngle, pitchAngle, rollAngle);
            rollAngle = 0;
            yawAngle = 0;
            pitchAngle = 0;
            base.Update(gametime);

i set them back to 0 as i don't want them to keep multiplying.

Share this post


Link to post
Share on other sites

i create my world matrix in my constructor.

 

  public Player(Model model, Vector3 position, float yawAngle, float pitchAngle, float rollAngle, Vector3 direction)
            : base(model)
        {
            Quaternion rot = Quaternion.CreateFromAxisAngle(new Vector3(1, 0, 0), 0f);
            world = Matrix.CreateScale(1f) * Matrix.CreateFromQuaternion(rot) * Matrix.CreateTranslation(position);
            this.yawAngle = yawAngle;
            this.pitchAngle = pitchAngle;
            this.rollAngle =  rollAngle;
            this.direction = direction;
        }

and i then have a property who multiplies them

 

       public override Matrix GetWorld()
        {
            return rotation * world;
        }

which my draw method then uses as my class is derived from that.

Share this post


Link to post
Share on other sites

Hm... I'm not entirely sure of how you're doing it, but it seems like you're missing a rotation matrix somewhere. If you want to tilt, then turn, you need two quaternions/matrices to model that transform, and I'm only seeing one. It looks like you're only getting the yaw rotation, but not the pitch and roll rotations. Just guessing though.

Share this post


Link to post
Share on other sites

i have a rotation matrix in my update method, which i then add to the world matrix in my property, but it might be that i am missing something.

rotation *= Matrix.CreateFromYawPitchRoll(yawAngle, pitchAngle, rollAngle);

Share this post


Link to post
Share on other sites

try

 

rotation = Matrix.CreateFromYawPitchRoll(yawAngle, pitchAngle, rollAngle); 
 

Also is your post above in constructor - 

 

world = scale * rotation * translate

and later

GetWorld = rotation * world    i.e;    GetWorld = rotation * scale * rotation * translate ????

 

Also try calling Normalize on quaternion before converting into matrix.

 

These are just couple of things i noticed form limited code you provided hope that helps. :)

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.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!