Sign in to follow this  

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); U.x = sin(cam->roll_angle*(M_PI/180)); U.y = cos(cam->roll_angle*(M_PI/180)); U.z = 0; V=Cross_Product(U,N); V=Normalise_Vector(V); U=Cross_Product(N,V); U=Normalise_Vector(U); * 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,

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