mouse click to manipulate closest vertex

Posted By: cartoon_baboon

mouse click to manipulate closest vertex - 09/23/09 21:56

Hi,

once mroe I find my nonexistent programming skills fail me. I've been trying to achieve the following. The camera is from above looking at a flat 3d model. By left clicking the mouse the closest vertex should be selected and manipulated by mouse movement till the mouse is released.

dragging the vertex works when I specify a vertex (for example 30):
Code:
var temp;
 	   vec_for_mesh (temp, me, 30);
    vec_add(temp,vector(mouse_force.x/5,mouse_force.y/5,0));
    vec_to_mesh(temp,me,30);



However converting screen positions to real world positions, using c_trace and hit.vertex is driving me crazy frown

Could someone please tell me the easiest way to get a c_trace from the mouse position and how to use hit.vertex. Of course maybe I'm barking up completely the wrong tree with this shocked

Thanks a lot!
Posted By: Xarthor

Re: mouse click to manipulate closest vertex - 09/24/09 06:59

For the tracing part you could try:
Code:
VECTOR trace_from;
VECTOR trace_to;

vec_set(trace_from,vector(mouse_cursor.x,mouse_cursor.y,50));
vec_set(trace_to,vector(mouse_cursor.x,mouse_cursor.y,10000)); // play with the 1000 if the trace is to short

vec_for_screen(trace_from,camera);
vec_for_screen(trace_to,camera);

result = c_trace(trace_from,trace_to,USE_POLYGON|SCAN_TEXTURE);
if(result > 0)
{
  vertex_number = hit.vertex;
}



Now vertex_number contains the closest hit vertex, and you can process it as you like.
Note: not tested!
© 2024 lite-C Forums