Jump to content
  • Advertisement
Sign in to follow this  
adamkromm

Everything inverted

This topic is 2550 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'm working on a game using Direct3D 10. From what i have heard and understand Direct3D 10 uses a left handed coordinate system normally. So positive x is to the right, positive y is up, and positive z is into the screen. From what I understand that is how I have is set up. I use all the D3D..LH functions to set up my matrices, I when calculating the "LookAt" I also used the LH and set

position = (0,0,-1) -- one unit out of the screen (towards viewer)
target = (0,0,1) -- one unit into the screen (away from viewer)
up = (0,1,0) - one unit up

(I think this is correct but as i look at it i wonder, does up need to be aligned with the position? ie. should up be (0,1,-1) either way I doubt this is the problem.)

My problem is I expect the above mentioned coordinate system. But what i see is that the coordinate system is inverted. So the positive x is the the left, the positive y is down, and the positive z is towards the viewer.

Where would I look, or what could I have done wrong to make this happen?


This is what I'm seeing
coordinates.png


Any help is appreciated.

Share this post


Link to post
Share on other sites
Advertisement
Check your view & projection Matrices.
It looks like you're setting up your view matrix correctly, but double check that it is not inverted.
Your projection matrix could also be built with a negative field of view, which can happen if you use MatrixPerspectiveFovLH and input degrees instead of radians.

Share this post


Link to post
Share on other sites
Here is where I set up the projection matrix:


D3DXMatrixPerspectiveFovLH(&projection, (float)D3DX_PI * 0.33f, (float)width/(float)height, 0.1f, 1000.0f);

and then the view matrix:



D3DXVECTOR3 eye(0, 0, -70);
D3DXVECTOR3 lookAt(0, 0, 0);
D3DXVECTOR3 up(0, 1, 0);

D3DXMatrixLookAtLH(&view, &eye, &lookAt, &up);

To the best of my knowledge those are correct. Anything else that could be causing the problem?

Share this post


Link to post
Share on other sites
Yes, those are correct.
I'm not sure what your problem is.
Check the matrices (WVP) that are passed to your shaders in pix I guess, and if something's off work back from there.

Share this post


Link to post
Share on other sites
When I'm viewing the matrices (WVP) in pix, what should they look like? I don't recall doing much matrix math in regards to 3D transformations. Does anyone have some good resources?

I know off the top of my head most (if not all) of the view matrices are just the identity matrix.

Share this post


Link to post
Share on other sites
post your vertex shader code. the thing is, if everything in your scene was inverted like you say, you wouldn't even know it since everything would be using the same coordinate system. My guess is that your are actually doing something backwards when setting the geometries world matrices. so, post where you set your geometries world matrices and your vertex shader (if you calculate your world view projection matrix outside of the shader, like before you render it, post that code too). the problem is most likely somewhere there, since your camera seems to be set up all right

also, this isn't the best place to look for transformations, but it will at least show you what each transformation matrix looks like:
http://www.braynzarsoft.net/index.php?p=D3D11TRANS

Share this post


Link to post
Share on other sites
Here is my vertex shader code:



PSINPUT VShader(VSINPUT input)
{
PSINPUT output;
float4 worldPosition;

input.Pos.w = 1.0;

output.Pos = mul(input.Pos, World);
output.Pos = mul(output.Pos, View);
output.Pos = mul(output.Pos, Projection);

output.Tex = input.Tex;

output.Norm = mul(input.Norm, (float3x3)World);
output.Norm = normalize(output.Norm);

worldPosition = mul(input.Pos, World);

[unroll]
for(int i = 0; i < NumberOfLights; i++)
{
output.LightPos = LightPosition.xyz - worldPosition.xyz;
output.LightPos = normalize(output.LightPos);
}

return output;
}

and this is the code that I use for each model to set up the model's world matrix.


target = D3DXVECTOR3(0,0,1);
up = D3DXVECTOR3(0,1,0);
position = D3DXVECTOR3(0,0,-1);
D3DXMatrixLookAtLH(&world, &position, &target, &up);

Share this post


Link to post
Share on other sites
your problem is setting the world matrices for the models. the lookat function is only used for the camera as far as i know. check out that link i gave above

Share this post


Link to post
Share on other sites
[font="Arial"]Yes, D3DXMatrixLookAtLH() creates a View Matrix, but your models need a World Matrix.

Everything seems inverted because a View Matrix is actually an inverted World Matrix.

[/font]

[font="Arial"]So if you want to use D3DXMatrixLookAtLH() to rotate your model towards a specific point in space, you'll have to invert the resulting Matrix in order to obtain a valid World Matrix.[/font]

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!