Thanks for the compliment on the random planet generator! It took alot of work to figure out all the math for that, I still consider it (and the shader) a work in progress but it's pretty close to what I want.

I got the rotations to work with your function, thanks alot!

Only one problem though... Now I somehow managed to mess up the positioning of my vehicle! This is starting to turn into a huge headache (literally).

The function:
Code:
void align_to_surface(ENTITY* Planet, ENTITY* Vehicle)
{
   VECTOR start_trace;
	VECTOR Temp_Vec;
	
	
	//get the surface position
   vec_set(start_trace,Vehicle.x);
	vec_sub(start_trace,Planet.x);
	vec_normalize(start_trace,vec_length(start_trace)*2);
	vec_add(start_trace,Planet.x);
	me=Vehicle;
	c_trace(start_trace, Planet.x,IGNORE_ME);
	
	//place vehicle on surface 
	//(taking into account vehicle min_z)
	vec_set(Temp_Vec,hit.x);
	vec_sub(Temp_Vec,Planet.x);
	vec_normalize(Temp_Vec,vec_length(Temp_Vec.x)-Vehicle.min_z);
	vec_add(Temp_Vec,Planet.x);
	vec_set(Vehicle.x,Temp_Vec);
	
	//rotate towards planet core
	vec_sub(Temp_Vec,Planet.x);
	alignToVec(Vehicle.pan, Temp_Vec, vector(0, 0, 1), 1); 
}



JibbSmart's AlignToVec funtion:
Click to reveal..
Code:
function alignToVec(ANGLE* entAng, VECTOR* vec, VECTOR* axis, var factor) {
	vec_rotate(axis, entAng);
	vec_normalize(axis, 1);
	vec_normalize(vec, 1);
	VECTOR rotAxis;
	vec_cross(rotAxis, vec, axis);
	var angle = -acos((float)vec_dot(axis, vec)) * factor * vec_length(rotAxis);
	ANGLE rotAngle;
	ang_for_axis(rotAngle, rotAxis, angle);
	ang_add(entAng, rotAngle);
}



My movement code:
Code:
c_move(vehicle,vector(key_w-key_s,0,0),nullvector,IGNORE_MODELS);
ang_rotate(vehicle.pan,vector(key_a-key_d,0,0));
align_to_surface(Planet, Vehicle);



I know its ugly withought any time_step in there, but its just for testing till I get it to work properly.

This is the result:
http://www.youtube.com/watch?v=1Y2uTAf8twI

EDIT:
it looks as if it was detecting the planet as a box or something... But I have set it's POLYGON flag, I swear!
set(Planet,POLYGON);

Last edited by Carlos3DGS; 01/13/12 19:30.

"The more you know, the more you realize how little you know..."

I <3 HORUS
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=401929&page=1