Sign in to follow this  
elephantman

UVN Camera System - basic help required please

Recommended Posts

Hi, I am having major problems with a UVN camera system and I'm about to throw my computer and myself out the window. Heres what I'm doing. * create a cube 2x2x2 in OBJECT coords centered around origin * create camera UVN vector initially 1 up, 1 right 1 forward N=Vert_Sub(cam->position,cam->target); N=Normalise_Vector(N); V.x = sin(cam->roll_angle*(M_PI/180)); V.y = cos(cam->roll_angle*(M_PI/180)); V.z = 0; U=Cross_Product(V,N); U=Normalise_Vector(U); V=Cross_Product(N,U); V=Normalise_Vector(V); * apply transposed camera vector to cube OBJECT vertices like so poly.world_vertices[i].x=poly.vertices[i].x*U.x + poly.vertices[i].y*U.y + poly.vertices[i].z*U.z; poly.world_vertices[i].y=poly.vertices[i].x*V.x + poly.vertices[i].y*V.y + poly.vertices[i].z*V.z; poly.world_vertices[i].z=poly.vertices[i].x*N.x + poly.vertices[i].y*N.y + poly.vertices[i].z*N.z; * translate cube WORLD vertices by negative camera position * scale the cube WORLD VERTICES by 20 * project the cube like so (distance is screen width) poly.screen_vertices[i].x=(SCREEN_WIDTH/2)+(distance*poly.world_vertices[i].x)/(distance-poly.world_vertices[i].z); poly.screen_vertices[i].y=(SCREEN_HEIGHT/2)-(distance*poly.world_vertices[i].y)/(distance-poly.world_vertices[i].z); I then run a loop where i move the camera position in y direction by 0.5 each time, always looking at 0,0,0. Problem is the cube should be 20 in height but by the time the camera has got to 1 im looking at the cube rotated by over 45 degrees ??? The cube also moves down the screen but i should always be looking at the center of it ?? Also im checking if a surface should be drawn by checking if its normal vectors z element is positive and this also stops working properly (although as far i can figure it should still work). Im obviously missing something about how all this fits together. Any help would be greatly apprecited. If anyone could explain the basics of the system or tell me what im doing wrong I'd be eternally grateful. Even point me in the direction a book with a good clear explanation. I've lost count of how many tutorials I've read but they never clearly explain how everything fits together. I can send all the code I have if anyone can be bothered to look at it :) Thanks in advance, [Edited by - elephantman on November 30, 2004 1:14:05 PM]

Share this post


Link to post
Share on other sites
I had some problems w/ the same viewing system a while back, and worked through them...

Would you mind posting your code?

The best tutorial I found was here


Thanks!

[Edited by - jakem3s90 on November 30, 2004 12:20:13 PM]

Share this post


Link to post
Share on other sites
Hi,

Thanks for the reply. Although I couldn't find much about the actual UVN camera system there.

My problem is that I don't really understand how the system works as my background is not really in maths.

Maybe you can help me with some really basic questions about the system:


1) Do you rotate by transposed UVN matrix, then simply translate negatively by camera position ?


2) I'm not using matrices - I'm doing the rotate and translate sa two seperate steps (as you can see in the code above) - does this matter ??


I don't understand how this achieves the desired results (and in my code it doesn't).

I'll tidy up my code and post it.

Share this post


Link to post
Share on other sites
It probably doesn't help much, but
    V.x = -sin(cam->roll_angle*(M_PI/180)) 
It appears that you are doing the right steps in the wrong order. You must scale the cube (transforming it to world space) before translating and rotating it (transforming it to view space). Then, you must translate it (by the negative camera position) before rotating it (by the inverse of the camera orientation).

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