Hi,
Superkus' solution is better because it works on any camera and ground height.

Code:
#include <acknex.h>
#include <default.c>

BOOL vec_mouseground ( VECTOR *vecGround, var groundHeight )
{
	if ( mouse_dir3d.z == 0 )
		return FALSE;
	var height = groundHeight - camera->z;
	if ( !height )
		return FALSE;
	if ( (height>>31) != (mouse_dir3d.z>>31) ) //( sign(height) != sign(mouse_dir3d.z) )
		return FALSE;
	vec_set ( vecGround, &mouse_dir3d );
	vec_scale ( vecGround, height / mouse_dir3d.z );
	vec_add ( vecGround, &camera->x );
	return TRUE;
}

void main ()
{
	video_mode = 8;
	mouse_mode = 4;
	level_load ( "" );
	ENTITY *terrain = ent_createterrain ( NULL, nullvector, 1, 1, 1000 );
	camera.x = -800;
	camera.y = -200;
	camera.z = 600;
	camera.pan = 15;
	camera.tilt = -45;
	def_move ();
	VECTOR vecMouseGround;
	while ( !key_esc )
	{
		if ( vec_mouseground ( vecMouseGround, terrain.z ) )
			draw_point3d ( vecMouseGround, COLOR_GREEN, 100, 16 );
		DEBUG_VAR ( vecMouseGround.x, 10 );
		DEBUG_VAR ( vecMouseGround.y, 30 );
		wait(1);
	}
}


Salud!

Last edited by txesmi; 08/29/14 08:22.