I don't want to open another topic for another problem. Any one can tell me what I'm doing wrong in using c_scan? Basically I run c_scan to and try to get the nearest vertex to the contact point and get its coordinates. I'm scanning a terrain hmp.

my code for scanning terrain with c_trace
Code:
var vi;
void camera_scan()
{
        
	VECTOR tempv,temp;
	while(1)
	{
                
		if(mouse_left) //scan while left mouse if pressed
		{
		   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);
                   //get vertex coordinate with vec_for_vertex
		   vec_for_vertex(temp,hit.entity,hit.vertex); //if fails to return hit.vertex
	           vi = hit.vertex; //store it for panel
                  //Debugging draw point of contact and nearest vertex then draw a line between.
                  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);
	}
}



The problem is with hit.vertex returning nothing and vec_for_vertex always returns the coordinate of the first vertex regardless of the hit position. What am I doing wrong?

here is how it look in my test. Ignore the float in vertex index, I forgot to change the format. But clearly vertex index never updated.


Last edited by JerahYalyn; 04/23/15 19:36.