I agree with Jibb, shaders is a better option I believe...

Try this (possibly) optimised get_height.

Make sure to test it with full painting enabled, because my logic may be
flawed around the final formulas...

Code:
var get_height(var Px, var Py, int SW, CONTACT* c1)
{
//P = point that we want the height of (x,y,0) 
//SW = vertex number of terrain ent closest towards the lower left corner of the square
//c1 = pointer to our terrain vertex info

VECTOR P, Triangle[3], temp_vec, Director[2], formula;
ANGLE temp_ang;
var ind_term;


// ###  NOTE  ###  All VECTOR calculations are working in D3D Vertex format!
//							That is X-Z-Y instead of X-Y-Z


//TRANSFORM SKIN PIXEL COORDS TO LOCAL ENT COORD SYSTEM
vec_set(P,vector(Px-256,0,256-Py));

//retrieve first point of containing triangle (base corner)
vec_set(Triangle[0], (c1.v)[SW].x);

//retrieve second point of containing triangle (diagonal to base)
vec_set(Triangle[1], (c1.v)[SW-32].x);

//determine third point of containing triangle (varying point)
vec_to_angle (temp_ang.pan, vec_sub( vec_set(temp_vec, P) , Triangle[0]) );

//retrieve third point of containing triangle (varying point)
if(temp_ang.pan>45)		vec_set(Triangle[2], (c1.v)[SW-33].x);
else							vec_set(Triangle[2], (c1.v)[SW+1].x);

//calculate the triangle's plane normal for the formula coeficients
vec_sub( vec_set(Director[0],Triangle[1]) ,Triangle[0]);
vec_sub( vec_set(Director[1],Triangle[2]) ,Triangle[0]);

vec_cross(formula, Director[0], Director[1]);

//set the independant term of the formula
ind_term=(-1*formula.x*Triangle[0].x)+(-1*formula.y*Triangle[0].y)+(-1*formula.z*Triangle[0].z);

//calculate our point's height plugging our values into the formula
P.y=(-1*((formula.x*P.x)+(formula.z*P.z)+ind_term))/formula.y;
 
return(P.y);
}




"There is no fate but what WE make." - CEO Cyberdyne Systems Corp.
A8.30.5 Commercial