with this code you get the nearest position on the terrain under your cursor. this position is stored in the mouse3d_vec vector
Code:
vec_set(temp,mouse_dir3d);
vec_scale(temp,1000); // set a range
vec_add(temp,mouse_pos3d);
c_trace(mouse_pos3d,temp,IGNORE_MODELS|IGNORE_SPRITES);
vec_set( mouse3d_vec , target );



the code is tested
put it in the mainloop
declare temp as a local vector and mouse3d_vec as a global vector

muffel