STATE_point_set_normal

 

 


  The point's normal is relevant only when using light (through the STATE_light_ API)
  The following are three cases where you might want to modify the points normal
   1) If it is needed to sharpen the contact lines of polygons (see example below)
  	  in order to get better illumination of objects such as rooms boxes etc. 
   2) If one is writing his own lighting module
   3) If one is writing a file format converter (from or to STATE).
  
  The normal of a point is set internally to the average of the normals of the adjacent surfaces.
  For example, if we have model of a room (a cube) the normal of a point on the floor
  will point to the center of the cube this is because the coordinates of a point on the floor
  exists in three polygons. The floor polygon and two adjacent walls.
  The average of the normals of these three polygons is a normal that points to the center of the cube.
  Please note that inside the engine a cube is built from 6 polygons each contains
  4 points, so a cube is built from 24 points (and NOT 8).
  Because of the fact that the normal of each point is the average of the adjacent
  it results that points that have the same coordinates will have the same adjacent polygons
  and therefore the same point normal. In other words point that have the same X,Y,Z coordinates
  will also have the same normal.
  
  Why do we need points to have a normal ? What is it good for.
  -------------------------------------------------------------
  The point normal helps a lot in making polygonal shapes to look more rounded
  while lighting the model polygons. Since points with the same X,Y,Z coordinates but on
  different polygons have the same point normal , they will also get the same color
  while the object is lighted and this will hide the connecting line between
  any two polygons.
  
  
  When saving a world on the disk (using STATE_engine_save() or WorldBuilder()
  The engine automatically calculates the polygons normal. This means that if you
  use STATE_point_set_normal() to modify the normals you will then loose
  your changes when the world is saved. To keep your changes
  call STATE_engine_save() with the flag: SAVE_WITHOUT_CALCULATING_POINT_NORMALS
  
   Parameters:
  
  	point_handle: a handle to a point.
  
  	normal:	a three values in the range of [-1  -  1] that corresponds with the
  			X,Y,Z values to be set (normal[0] is the X value)
  			Note that the normal is normalized internally so values such as Normal= {10,0, -20}
  			can also be used to set a normal
  
    Note that internally the engine uses only 24 bits for the normal X,Y,Z values
    (for example, three double values would occupied 8*8*3=192 bits)
    This means that if one calls STATE_point_set_normal() with a normal_x == 0.123456789
  	then internally it will be rounded to something like 0.123
  
   Return Value: OK or VR_ERROR.
  
   Example:
  
   A)	double normal[3]={1,0,0};
  		STATE_point_set_normal(point_handle, normal);
  
   B)
  		The following example will set all the points normal to the same value
  		of their respective polygon. This will make the edges of the polygon much sharper
  		This effect is good for lighting a room were there should be a visible difference
  		between the light that the floor and the wall receive. 
  
  		STATE_light_calcualte_vertices_normals_automatically(DISABLE_AUTOMATIC_NORMAL_CALCULATION);   so that the values that we set wont be overwritten when doing STATE_engine_save().
      	for(DWORD poly=STATE_polygon_get_first_polygon(); poly!=NULL; poly=STATE_polygon_get_next(poly) ) {
  	  		double normal[4];   The normal is the three first values
  	  		STATE_polygon_get_plane(poly, normal);
  	  		for(DWORD point=STATE_polygon_get_first_point(poly); point!=NULL ; point=STATE_point_get_next_point(point) ) {
  	  			STATE_point_set_normal(point, normal);
  	  		}
  	  
  	  	}
  
   NOTE: When a group is lit at the first time (when STATE_light_activate() is called)
  		 it will calculate the group normals and will override any setting that were done before.
  		 To avoid this call STATE_light_calcualte_light_normals_automatically(NO);
  
   See also STATE_point_get_normal()

 

 

Go to page 1      Select API

 

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