Coordinate system confusion (camera)

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

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 on other sites
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 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 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 ;)

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 15
• 9
• 11
• 9
• 9
• Forum Statistics

• Total Topics
634136
• Total Posts
3015756
×