Sign in to follow this  
cedricmobile

How to tansform normal and vertices to World Space?

Recommended Posts

Here are the variables we will need to backface cull in Object Space. Code: //the Camera Position World Space. cam_z cam_y cam_z //the Objects Orientation matrix. (ie final rotational state) objM //the position of the object in World Space. obj_x obj_y obj_z //a point on the plane/face that is being culled. (Object Space)face_x face_y face_z //the plane/face normal (calculated in Object Space once at start-up) face_norm_x face_norm_y face_norm_z Now for doing the calcs. Code: //first the Camera Object displacement (vector from camera to object) var Dx = obj_x - cam_x; var Dy = obj_y - cam_y; var Dz = obj_z - cam_z; // rotate the camera into Object Space (use the inverse of the displacement and the object Matrix) var newCamx = -Dx * objM.xx + -Dy * objM.xy + -Dz * objM.xz; var newCamy = -Dx * objM.yx + -Dy * objM.yy + -Dz * objM.yz; var newCamz = -Dx * objM.zx + -Dy * objM.zy + -Dz * objM.zz; //now get a vector from the plane/face to the camera var fx=newCamx - face_x; var fy=newCamy - face_y; var fz=newCamz - face_z; //and finally do the backface culling (take the dot product) if((fx*face_norm_x + fy*face_norm_y + fz*face_norm_z) >0) { //face is visible and NOT backface culled} I want to know how can I get the followings: cam_z cam_y cam_z objM obj_x obj_y obj_z is cam_z cam_y cam_z = Camera direction in camera space can be transformed to world coordinate space by multiplying transpose of model view matrix ? How to get objM then? abd how about obj_x obj_y obj_z ? Please help, thanks.

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