Jump to content
  • Advertisement
Sign in to follow this  
FoxHunter2

Coordinate system confusion (camera)

This topic is 4818 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 everybody! I'm trying to get my camera up and working, but right now I'm confused with the coordinate system. This is how I draw my race track (just a plane right now):
device.Transform.World = Matrix.Translation(-HEIGHT * pixel_meter_ratio / 2f, 0, -WIDTH * pixel_meter_ratio / 2f);

Ok fine, this draws my race track from about X = -15f to 15f Y = 0 Z = -15f to 15f So basically just a plane one the ground. Now comes the part that is confusing me: I set up a camera to get a proper view on the track
matWorld = Matrix.Identity;
matProjection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1f, 100f);
matView = Matrix.LookAtLH(new Vector3(0, -100, 1), new Vector3(0, 0, 0), new Vector3(0, 1, 0));
device.Transform.Projection = matProjection;
device.Transform.View = matView;
device.Transform.World = matWorld;

Given the Camera vector(0,-100,1) the eye is 100f outside of the "screen" facing the flat track from BEHIND. If I change the eye vector to (0,1,100) now I face the track from 100f from ABOVE. If I change the vector to (1, -100, 1) now I face the track from 100f BEHIND, but the track is rotated at a 45 degree angle clockwise. What is going on here? I though that if I set the Y value to 100, then I'm 100f ABOVE the track. However, this is only the case with setting the Z-value to 100. So are the Y and Z vectors exchanged? According to the docs the Z-vector faces into the screen and not upwards. And what's with the rotation of the track when I change the X vector from 0 to 1!? Any help is greatly appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Hi there FoxHunter2,
How are you doing?

The Problem
Left hand coordinate systems.

The Solution
When using left handed coordinate systems like you are the following rules apply, given the following situation.
Scenario: For a left handed coordinate system.
matProjection = Matrix.PerspectiveFovLH((float)Math.PI / 4, fAspect, 1f, 100f);
matView = Matrix.LookAtLH(new Vector3(0, -100, 0), new Vector3(0, 0, 0), new Vector3(0, 1, 0));

Negative X : To the left of the screen
Positive X : To the right of the sceen
Negative Y : To the bottom of the screen
Positive Y : To the top of the screen
Negative Z : Coming out of the screen, pulling the camera back
Positive Z : Going into the screen


See, I think you missed that you are setting the value to -100 rather than 100. Which will bring you above the track.

I hope this helps a bit buddy.

Share this post


Link to post
Share on other sites
Thanks so far. I know D3D uses a lefthand coordinate system, but I don't get the point :(

Please take a look at this screen. The values don't make sense in a LH system:

Share this post


Link to post
Share on other sites
D'oh I mixed up the Y and Z values in the vertex declaration of my race track :D

Quote:
vertices[x + y * WIDTH].Position = new Vector3(x * pixel_meter_ratio, height, y * pixel_meter_ratio);


That's the correct order now ;)

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!