STATE_camera_get_projection_plane_d

 

 


   *** An advanced function. Not very useful.
   The camera projection plane is the plane on which the seen world is projected on.
   The projection plane equation is X+d=0 or in other words all the points in camera space
   that have their X coordinate equals to -d.
  
   Q: What is this function good for ?
   A: Lets say you have an object in the world and you would like to put it
      so it is seen (by the camera) in the lower right corner of the screen.
  	  Here are several ways that you can achive this.
  	  Method 1:
  			double offset[3]={-10, 11, -12};    10 units in front of the camera, 11 units to the right of the camera, 12 units below the camera
  											  the 10,11,12 numbers have no special meaning, check other values till you have the correct position
  			double object_location[3];
  			STATE_camera_convert_point_to_world_space(camera, offset, object_location);
  			STATE_object_set_location1(my_object, object_location);
  
  			This method is very simple though if the size of the rendering window changes
  			it will also change the position of the object relative to the rendering window corners
  
  	  Method 2: Use STATE_camera_get_zoom() to get the camera field of view and calculate it from there.
  
  	  Method 3: Use STATE_camera_get_projection_plane_d() (this function)
  		 
  			STATE_camera_set_current(my_camera, m_hWnd);   m_hWnd is the window on which we render
  			double d=STATE_camera_get_projection_plane_d(my_camera);
  			  get the dimension of the rendering window
  			RECT rect;
  			GetClientRect(&rect);
  			double object_location[3];
  			object_location[0]=d;
  			object_location[1]=rect.right/2;
  			object_location[2]=-rect.bottom/2;
  			  Now we have a point at the bottom left corner of the screen
  			  This point might be closer than the allowed distance from the camera (eye)
  			  so we will now take care of it.
  			double allowed_distance=STATE_camera_get_distance_from_eye(my_camera);
  			  Remeber that the camera is looking towards the negativ X axis
  			object_location[0]= -allowed_distance;
  			object_location[1]= object_location[1]*allowed_distance/-d;
  			object_location[2]= object_location[1]*allowed_distance/-d;
  			  The point that we have now is in camera space and its location
  			  is in the bottom left corner of the viewed rendering window
  			  Note that you will probably want to move the location alittle bit
  			  forward, left and upper so it is not cut by the viewing frustom
  			double object_location_world_space[3];
  			STATE_camera_convert_point_to_world_space(camera, object_location, object_location_world_space);
  			STATE_object_set_location1(my_object, object_location);
  
   Return Value
  		Returns the projection plane equation d parameter (plane equation: X+d=0) which is the
  		the distance of the projection plane from the camera. The return number is negative
  		

 

 

Go to page 1      Select API

 

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