Gamestudio Links
Zorro Links
Newest Posts
Data from CSV not parsed correctly
by EternallyCurious. 04/18/24 10:45
StartWeek not working as it should
by Zheka. 04/18/24 10:11
folder management functions
by VoroneTZ. 04/17/24 06:52
lookback setting performance issue
by 7th_zorro. 04/16/24 03:08
zorro 64bit command line support
by 7th_zorro. 04/15/24 09:36
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:48
Zorro FIX plugin - Experimental
by flink. 04/14/24 07:46
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 677 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help with ISOMETRIC and mouse_dir3d #450125
04/07/15 07:18
04/07/15 07:18
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
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...

Last edited by EpsiloN; 04/07/15 07:18.

Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Help with ISOMETRIC and mouse_dir3d [Re: EpsiloN] #450127
04/07/15 07:49
04/07/15 07:49
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
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!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: Help with ISOMETRIC and mouse_dir3d [Re: 3run] #450138
04/07/15 09:50
04/07/15 09:50
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
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...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1