STATE_camera_get_transformation_matrix

 

 



   Who needs this function ?
   --------------------------
  	Users that are porting code from other 3D engines might want to use this function.
  	All the rest can skip this function
  
   General background
   ------------------
  	Please note that when moving or rotating the camera all that the engine does is change
  	the camera's matrix which is a quick and fast to do.
  
  
   What is this matrix ?
   ---------------------
  	To learn more about transformation matrixes you should read a computer graphics math book.
    This is just if you are interested in the subject. One of the great things about the STATE engine
  	is that it makes it completely unnecessary to learn these subjects.
  	Anyhow, since you are still reading it means that you want to know more, so here it is:
  		the first top 9 cells of the matrix are the rotation matrix
  		The bottom row is the translation values.
  		The diagnal is the scale values
  
  		S R R 0
  		R S R 0
  		R R S 0
  		T T T 1
  
  		Above is the matrix. T stands for translation. S for scale. R for rotation.
  		If you don't know what we are talking about then you should read a book in the subject
  
  		By taking a point in camera space and multiplying it by the inverse_matrix we get the point in World Space.
  		for example the point (0,0,0) in camera space is the location of the camera.
  		when multiplying (0,0,0) by the inverse_matrix we get (T T T) which means that
  		(T,T,T) is the camera location
  		The code below shows how to multiply a point (vec) by the matrix (mat).
  		The result is saved in dst.
  
  		void 	mul_vec_mat(vector	dst, vector vec, matrix mat)   does dst=vec*mat
  		{
  		  double	res[4];
  		  double	one_over_res3;
  
  
  			res[0]=vec[0]*mat[0][0] + vec[1]*mat[1][0] + vec[2]*mat[2][0] + mat[3][0];
  			res[1]=vec[0]*mat[0][1] + vec[1]*mat[1][1] + vec[2]*mat[2][1] + mat[3][1];
  			res[2]=vec[0]*mat[0][2] + vec[1]*mat[1][2] + vec[2]*mat[2][2] + mat[3][2];
  			res[3]=vec[0]*mat[0][3] + vec[1]*mat[1][3] + vec[2]*mat[2][3] + mat[3][3];
  
  			if(res[3]<1e-20 && res[3]>-1e-20) {   protect agains floating point errors.
  				ERROR_MSG(SCREEN,"mul_vec_mat: devision by zero\n");
  		
  				dst[0]=res[0];
  				dst[1]=res[1];
  				dst[2]=res[2];
  				return;
  			}
  
  			one_over_res3=1/res[3];
  
  			dst[0]=res[0]*one_over_res3;
  			dst[1]=res[1]*one_over_res3;
  			dst[2]=res[2]*one_over_res3;
  
  		}
  
  
  	Parametar:
  	----------
  
  		camera_handle: the camera handle
  
  		camera_matrix: The camera matrix. Note that multiplying a point in world space by this matrix will result
  					   a point in camera space.
  
  		inverse_matrix: The inverse of camera_matrix. Multiplying a point in camera space by this matrix will
  						result a point in world space.
  
  
   Example:
  
  		double matrix[4][4], int_matrix[4][4];
  		STATE_camera_get_transformation_matrix(my_camera, matrix);
  

 

 

Go to page 1      Select API

 

Copyright © 2007 3DSTATE Corporation. www.3dstate.com