# Trouble with my scene in XNA. [Solved - XNA uses RH coords!]

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

## Recommended Posts

Ok, I've been using Direct3D for quite some time now, but only with 2D pretransformed vectors. Now that I've finally decided to give 3D a shot I find myself failing at the most basic of tasks! [depressed] My objective very simple: Draw a textured quad on the X/Z plane, with a camera looking down at it from one edge. Since I'm only playing around, I thought I'd try out XNA. Here's the vertex and camera definitions I'm using: (drawn as an indexed triangle list)
vertexGrid[0].Position = new Vector3(-512.0f, 0.0f, +512.0f);
vertexGrid[1].Position = new Vector3(+512.0f, 0.0f, +512.0f);
vertexGrid[2].Position = new Vector3(-512.0f, 0.0f, -512.0f);
vertexGrid[3].Position = new Vector3(+512.0f, 0.0f, -512.0f);

vertexGrid[0].TextureCoordinate = new Vector2(0.0f, 0.0f);
vertexGrid[1].TextureCoordinate = new Vector2(1.0f, 0.0f);
vertexGrid[2].TextureCoordinate = new Vector2(0.0f, 1.0f);
vertexGrid[3].TextureCoordinate = new Vector2(1.0f, 1.0f);

indexGrid[0] = 0;
indexGrid[1] = 1;
indexGrid[2] = 3;
indexGrid[3] = 3;
indexGrid[4] = 2;
indexGrid[5] = 0;

mWorld = Matrix.Identity;
mView  = Matrix.CreateLookAt(new Vector3(0.0f, 256.0f, -512.0f), Vector3.Zero, Vector3.Up);
mProj  = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 1280.0f / 720.0f, 1.0f, 1024.0f);


Unfortunately to obtain the following image I had to turn culling off. It clearly shows that my quad is facing away from the camera... As far as I can tell I'm defining the two triangles of my quad in clockwise order, so what am I missing? I feel such a noob! [rolleyes] [Edited by - Racky1275 on April 4, 2008 3:59:28 AM]

##### Share on other sites
XNA, if I recall, switched to a right-handed coordinate system and by default uses counter-clockwise winding for front faces.

##### Share on other sites
Quote:
 Original post by smitty1276XNA, if I recall, switched to a right-handed coordinate system and by default uses counter-clockwise winding for front faces.

Yeah, they did. Sure makes for some annoying bugs when I'm porting over my D3D code.

##### Share on other sites

AAAAARRRRGH! OK, April 1st has passed so I'm going to assume that you're not joking. I must admit to not actually 'reading' the documentation, so I guess it's my fault for assuming...

RTFM [smile]

##### Share on other sites

From the XNA Migration Guide
Quote:
 Nearly all of the basic math types familiar to the native D3DX libraries and MDX have been replicated in the XNA Framework. There have been numerous additions to the XNA Framework math types and methods to reduce the amount of boilerplate math code that you have to rewrite for each new game. The biggest breaking change has been the removal of left-handed coordinate-system math functions in favor of unifying on a right-handed coordinate system. This simplifies the Math API and omits functionality that causes a large amount of confusion.

I personally would have liked to stick with the LH coordinate system to maintain parity with my DX3D code, but RH is the accepted mathematical standard. Gotta move with the times I guess. [wink]

##### Share on other sites
How does changing to a RH system make the math API any more simple than sticking with only the LH system.

##### Share on other sites
It doesn't make the maths any simpler, it just makes it more 'standard'. If you are learning 3D from a math text book, you'll be using RH coordinates.

Wiki Quote (sorry) - Cartesian coordinate system
Quote:
 The standard orientation, where the xy-plane is horizontal and the z-axis points up (and the x- and the y-axis form a positively oriented two-dimensional coordinate system in the xy-plane if observed from above the xy-plane) is called right-handed or positive.

There's also a fair bit if discussion about it here

From my point of view I wish they hadn't made the change, but I can see why they did it. Of course the best solution would be to travel back in time and bash some people over the head with a maths book. [smile]

1. 1
Rutin
29
2. 2
3. 3
4. 4
5. 5

• 13
• 13
• 11
• 10
• 13
• ### Forum Statistics

• Total Topics
632959
• Total Posts
3009476
• ### Who's Online (See full list)

There are no registered users currently online

×