Skip to main content
GameDev.net gamedev.net
🔒 Locked 🎮 Unity

Need help with strange problem

Started by tont Sep 19, 2006 at 7:46 PM 0 replies 550+ views
Original Post
tont
tont
Im currently working on getting a small top down game working. At this point, i can draw this little tank on the screen and can drive it whereever i want to on the screen. But im running into something a little strange. Right now, if i move my object to the left side of the screen, i notice that my X value is getting larger, as if it were going up the positive scale, and if i go to the right, the x is getting smaller for some reason. Obviously this is the opposite of a standard axis. Then i noticed that in my move functions, I am infact decreasing the value to go 'forward'.(taking from a tutorial that i now cant find). but im not sure why its works this way. I as thinking maybe its my view matrix, but if i move it to where it works with the axis, all the images are flipped upside down. If anyone can lend a hand, I would be extremely thankful. Here are some exerts from my code. How the projections and view matrices are setup.
device.Transform.Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, this.Width / this.Height, 0.3f, 500f);
device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0,30), new Vector3(0, 0, 0), new Vector3(0, 1, 1));
Acceration calls and functions

  if (keys[Key.UpArrow])
            {
                tank.accelerate(-.1f);
            }
            if (keys[Key.DownArrow])
            {
                tank.accelerate(.05f);
                
            }
//further down in the accelerate function
 public void accelerate(double x)
        {            
            this.x +=  (float)(x * Math.Cos(a));
            this.y += (float)(x * Math.Sin(a));
            
        }

Transforms and drawing

device.SetTexture(0, tank.getTexture());
tank.translation_matrix = Matrix.Translation(tank.x, tank.y, 0.0f);
tank.rotMatrix = Matrix.RotationYawPitchRoll(0.0f, 0.0f, tank.getAngle());
tank.result = tank.rotMatrix * tank.translation_matrix;
device.Transform.World = tank.result;
device.DrawUserPrimitives(PrimitiveType.TriangleList, 2, tank.draw_tank());

COleException
COleException
Is there a reason, why the "Up"-Vector of your world points to (0,1,1)?

Try to set it to the y-axis, like this:

device.Transform.View = Matrix.LookAtLH(new Vector3(0, 0,30), new Vector3(0, 0, 0), new Vector3(0, 1, 0));


*edit*

And additionally, your "eye" is at 0,0,30 along at your z-axis and you are looking back at 0,0,0.

Is that what you wanted?

HTH

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.