|
This is a very powerful function. Beginners will probably never use this function.
See also STATE_math_calculate_bitmap_coords_equations() which is less general but easier to use
See the example below to understand what it is all about.
It is used to interpolate values across a polygon. Please note that this function is used together with
STATE_math_get_interpolated_value_using_equation()
With STATE_math_calculate_triangle_interpolation_equation() we build an equation
and with STATE_math_get_interpolated_value_using_equation() we query for values using the equation we
have already constructed.
Return values.
If an error occurred it returns VR_ERROR. On success it will return the type of the equation that
was created. We shouldn't care about this value though it is important that we keep it
because later we will have to send it to STATE_math_get_interpolated_value_using_equation();
This function also returns the resulted equation through the result_equation argument.
Again we shouldnt care at all about what this means though we should save it for calling
STATE_math_get_interpolated_value_using_equation()
Arguments:
double xyz_of_3_points[3][3] - Three points of the polygon that will be used for interpolating. For example:
xyz_of_3_points[0][0] X value of the first point
xyz_of_3_points[0][1] Y value of the first point
xyz_of_3_points[1][2] Z value of the SECOND point
double value_to_interpolate[3]
The values to be interpolated.
value_to_interpolate[0] - The value from the first point (for example the point bitmap_x coord)
value_to_interpolate[1] - The value from the second point
double polygon_plane[4] - the polygon plane. Use STATE_polygon_get_plane() to get it.
double result_equation[4] - Through this argument the computed equation is returned.
Example,
Lets say that we have a polygon and a point x,y,z on the plane of the polygon. We want
to know what should be the point bm_x,bm_y values.
Using this function we can build an equation that given any x,y,z it will return the
appropriate bm_x of that point. To build the equation we need to take three points of the polygon
and their bm_x values.
xyz_of_3_points[0][0]=1 ; X value of first point
xyz_of_3_points[0][1]=2; Y value of first point
xyz_of_3_points[0][2]=3; Z value of first point
xyz_of_3_points[1][0]=4 X value of second point
and so on for the three points....
value_to_interpolate[0]=0 ; bm_x value of the first point
value_to_interpolate[1]=1 ; bm_x value of the second point
value_to_interpolate[2]=0 ; bm_x value of the third point
double polygon_plane[4];
STATE_polygon_get_plane(my_polygon, polygon_plane); getting the polygon plane
double result_equation[4];
int equation_type;
equation_type=STATE_math_calculate_polygon_interpolation_equation(xyz_of_3_points, value_to_interpolate, polygon_plane, result_equation);
We have now created an equation for interpolating the bitmap_x coordinate over our polygon.
The equation_type and the result_equation are like a black box for us (we don't need to care about what it is exactly).
Now lets use the equation and calculate the bitmap_x coordinate in the point x,y,z (that should be on the polygon plane)
double xyz[3]= {1,2,3} a point on the polygon's plane
double bitmap_x=STATE_math_get_interpolated_value_using_equation(xyz, result_equation, equation_type);
Note that for getting the bitmap_y coord of the same point we need to build another equation for the bitmap_y values.
|