var vert; //to store vertex index next to hit position
void camera_scan()
{
VECTOR tempv,temp;
while(1)
{
if(mouse_left)
{
tempv.x = mouse_pos.x;
tempv.y = mouse_pos.y;
tempv.z = 2000;
vec_for_screen(tempv,camera);
c_trace(camera.x, tempv, IGNORE_ME | SCAN_TEXTURE);
if(HIT_TARGET) //needed to prevent crashing when not hitting something :P
{
vert = ent_nextvertex(hit.entity,hit.x);
vec_for_vertex(temp,hit.entity,vert);
//for debugging, create a point and line from the hit position to the nearest index
draw_point3d(temp.x,vector(0,0,255),100,300);
draw_point3d(vector(hit.x,hit.y,hit.z),vector(0,0,255),100,300);
draw_line3d(vector(hit.x,hit.y,hit.z),vector(0,0,255),100);
draw_line3d(temp.x,vector(0,0,255),100);
}
}
wait(1);
}
}