Help with ISOMETRIC and mouse_dir3d

Posted By: EpsiloN

Help with ISOMETRIC and mouse_dir3d - 04/07/15 07:18

I tried pointing my player towards the mouse in ISOMETRIC camera mode and top-down view with mouse_dir3d, but it doesn't work at all. Height of camera is set at max ~650 quants.

After that, I tried the old method:
Code:
testvec1[0] = mouse_pos.x;
			testvec1[1] = mouse_pos.y;
			testvec1[2] = 10;
			testvec2[0] = mouse_pos.x;
			testvec2[1] = mouse_pos.y;
			testvec2[2] = 1000;
			vec_for_screen(testvec1[0], camera);
			vec_for_screen(testvec2[0], camera);
			c_trace(testvec1[0], testvec2[0], IGNORE_ME);
mouse_dir3d
			vec_set(debug_var[3], hit.x);
			vec_to_angle(my.pan,hit.x);


But it doesn't work as it should either. It sets only hit.y I think, so the player points mainly to the right and sometimes rotates a little (nowhere near the mouse)...

I'm using this for the mouse:
Code:
while (mouse_mode > 0) // move it over the screen
	{
		vec_set(mouse_pos,mouse_cursor);
		wait(1);
	}



Anyone got any solutions?

EDIT: No error in code, because it works without ISOMETRIC flag...
Posted By: 3run

Re: Help with ISOMETRIC and mouse_dir3d - 04/07/15 07:49

I've made a working example for you, take a look:
Code:
// include lib:
#include <acknex.h>
#include <default.c>
#include <windows.h>

// mouse vectors:
VECTOR mouseVec;              // current mouse position
VECTOR mouseTemp;             // temp vector for mouse position

// camera parameters:
var camXBoarder = 100;        // top and bottom view boarders (distance from the player)
var camYBoarder = 140;        // left and right view boarders (distance from the player)
var camDistFactor = 0.85;     // offset factor, this will help to zoom in and out

// don't allow mouse, leave the window:
void lockMouse(){
	RECT rect;
	GetClientRect(hWnd, &rect);
	ClientToScreen(hWnd, &rect);
	ClientToScreen(hWnd, &rect.right);
	ClipCursor(&rect);
}

// init mouse:
void initMouse(){
	// set mouse range:
	mouse_range = 5000;
	// activate mouse:
	mouse_mode = 4;
	// lock mouse inside the window:
	lockMouse();
}

// update mouse positions:
void updateMouse(ENTITY* ent){
	// save mouse position:
	vec_set(mouseVec.x, vector(mouse_pos.x, mouse_pos.y, 1000));
	// convert it in into the world coordinates:
	vec_for_screen(mouseVec.x, camera);
	// set the Z position to player, to aim straight ahead:
	mouseVec.z = ent.z;
}

// fog, sky color setup:
void fogSkySetup(){
	// lods:
	vec_set(d3d_lodfactor, vector(12.5, 25, 50)); 
	// disable sunlight:
	sun_light = 0;
	// camera clipping parameters:
	camera.clip_near = 1;
	camera.clip_far = 2500;
	// fog parameters:
	camera.fog_start = 150; 
	camera.fog_end = 2000; 
	// fog and sky colors:
	fog_color = 4;
	// change fog color:
	vec_set(d3d_fogcolor4.blue, vector(1, 1, 1));
	// change sky color:
	vec_set(sky_color.blue, d3d_fogcolor4.blue);
	// create isometric camera:
	set(camera, ISOMETRIC);
}

// main function:
void main(){
	// video modes:
	video_set(800, 600, 16, 2);
	// no wide-screen:
	video_aspect = 1.333;
	// window title:
	video_window(NULL, NULL, NULL, "ISOMETRIC MOUSE!");	
	// doppler factor:
	doppler_factor = 0;
	// show all errors:
	warn_level = 6;
	// max fps limit:
	fps_max = 60;
	// freeze input:
	freeze_mode = 1;
	// load level:
	level_load("");
	// wait till loaded:
	wait(3);
	// unfreeze the game:
	freeze_mode = 0; 
	// handle sky, fog color etc:
	fogSkySetup();
	// init mouse:
	initMouse();
	// set camera positions:
	vec_set(camera.x, vector(0, 0, 500));
	vec_set(camera.pan, vector(0, -90, 0));
	// create pseudo player:
	player = ent_create(CUBE_MDL, vector(0, 0, 0), NULL);
	// make player smaller:
	vec_fill(player.scale_x, 0.5);
	// wait one frame:
	wait(1);
	// update bbox:
	c_setminmax(player);
	// set his flags:
	set(player, TRANSLUCENT);
	// loop:
	while(!key_esc){
		// move player:
		c_move(player, nullvector, vector(5 * (key_w - key_s) * time_step, 5 * (key_a - key_d) * time_step, 0), GLIDE);
		// all view boarders:
		camera.bottom = -camXBoarder * camDistFactor;
		camera.top = camXBoarder * camDistFactor;
		camera.left = -camYBoarder * camDistFactor;
		camera.right = camYBoarder * camDistFactor;
		// update mouse positions:
		updateMouse(player);
		// save the target position:
		vec_set(mouseTemp.x, mouseVec.x);
		// subtract from it my position:
		vec_sub(mouseTemp.x, player.x);
		// rotate angle to the target position:
		vec_to_angle(player.pan, mouseTemp.x);
		// reset TILT and ROLL angles:
		player.tilt = player.roll = 0;
		// draw mouse position:
		draw_point3d(mouseVec.x, COLOR_RED, 100, 3);
		// wait one frame:
		wait(1);
	}
	// exit the game:
	sys_exit("bye!");
}

The most important part is here:
Code:
// update mouse positions:
void updateMouse(ENTITY* ent){
	// save mouse position:
	vec_set(mouseVec.x, vector(mouse_pos.x, mouse_pos.y, 1000));
	// convert it in into the world coordinates:
	vec_for_screen(mouseVec.x, camera);
	// set the Z position to player, to aim straight ahead:
	mouseVec.z = ent.z;
}

Simply as it is laugh

Best regards!
Posted By: EpsiloN

Re: Help with ISOMETRIC and mouse_dir3d - 04/07/15 09:50

I'm very confused why this works (a single vec_for_screen) and a c_trace between two vec_for_screen doesn't work...

Anyway, thanks for the help laugh I can continue my tut now...
© 2024 lite-C Forums