Sign in to follow this  
Subotron

custom matrix only works if I use negative z-axis [SOLVED]

Recommended Posts

Yesterday I've reconstructed my camera class, since it suffered from gimbal lock, and I wanted to implement quaternions for later use in a 3rd person camera. Everything seems to work fine, except for one thing: I draw a heightmap starting in the origin, in the direction of x and -z. Let me make it a little bit more clear with my ascii art: Z |xxxxxx0 |xxxxxxx |xxxxxxx --------------- X | | | the x's are the heightmap, coordinates of point 0 (top right) are [7][-3] (with [x][z]). In this setting, everything works. I point my camera down the negative z axis, and I see the map (providing I'm not standing 'above' it). However, if I multiply all the z-coordinates of the heightmap by -1, and I point the camera down the z-axis in the positive direction, I see nothing. This is not a matter of standing at the wrong side, I also inverted that coord. This is what I do: Initialize the camera, giving it a position.xyz and direction.xyz The position is stored and used later. The direction is stored in a vector, which I normalize. I create a non-unit quaternion out of this vector.* I normalize this quaternion. I convert the quaternion to a matrix every time I render.* I load this matrix. I translate over the inverse camera position. I draw the landscape. * I found the functions to do this in some articles, so I'm pretty sure it's right. Note: I use a different way to calculate the quaternion of the direction vector if the direction vector is [x=0, y=0, z=1], since my global conversion doesn't work for this one, but that's not the problem. Both conversions work, and the error doesn't only occur for direction = [0, 0, 1]. Even weirder is, if I look towards negative z-axis, I can perform a full rotation around the y-axis (which is up), so I actually achieve to look in the positive z-direction. However, doing a positive rotation around the y-axis makes the camera rotate to the left. I think it should rotate to the right... If any code or an exe is needed, please let me know!

Share this post


Link to post
Share on other sites
Quote:
Original post by Subotron
However, if I multiply all the z-coordinates of the heightmap by -1, and I point the camera down the z-axis in the positive direction, I see nothing. This is not a matter of standing at the wrong side, I also inverted that coord.


Flipping the Z coordinates of each point inverts the vertex order of your triangles. They coould thus be getting backface-culled.

Try turning off backface culling and see if this is your problem. If so, you need to switch the orders of the indices used to draw each triangle.

EDIT: Unless this is what you meant by "standing at the wrong side".

Share this post


Link to post
Share on other sites
oh my god... you fixed my problem within a minute :)

Thanks a lot! I actually thought of disabling backface culling yesterday, but I totally forgot now...

Only 'problem' left is the x-axis being 'inverted' (positive x is to the left, negative to the right), but this is to be expected. I'll probably fix that in another minute :)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this