Gamestudio Links
Zorro Links
Newest Posts
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
M1 Oversampling
by 11honza11. 04/30/24 08:16
Trading Journey
by howardR. 04/28/24 09:55
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (AndrewAMD), 840 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: check if entity is within rotated box [Re: txesmi] #462538
10/07/16 10:06
10/07/16 10:06
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
I think I can explain this the best way through images. The grid shows how the camera.pan is. The red/yellow/green lines are my drawed boxes. Green mouse cursors are the begin and end points of my mouse selection. (note that boxes are 2d on the images but 3d in my game)

First one without your vec2d_rotate function:


Second is with your vec2d_rotate function:


Third, this is with your vec2d_rotate function and with the tweak I posted in my previous post (only 1 of the 2 vectors are correct):


Fourth, this is what I want:

Re: check if entity is within rotated box [Re: Reconnoiter] #462544
10/07/16 16:12
10/07/16 16:12
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Ok, I got it!

The only difference with my previous example is that you need to convert the bounds vector to that pseudo view space before computing the symmetric point of the rectangle.

Here you go:
Code:
#include <acknex.h>

void vec2d_rotate ( VECTOR *_v, var angle )
{
	var x = fcos(angle,_v->x) - fsin(angle,_v->y);
	_v->y = fsin(angle,_v->x) + fcos(angle,_v->y);
	_v->x = x;
}

void mouseOnZ0 ( VECTOR *_v )
{
	vec_set ( _v, &mouse_dir3d );
	vec_scale ( _v, -camera->z/_v->z );
	vec_add ( _v, &camera->x );
}

void onMouseLeft ()
{
	VECTOR vStart, vEnd;
	mouseOnZ0 ( &vStart );
	
	while ( mouse_left )
	{
		mouseOnZ0 ( &vEnd );
		
		VECTOR vCenter, vBounds;
		vec_lerp ( &vCenter, &vStart, &vEnd, 0.5 );
		vec_diff ( &vBounds, &vStart, &vCenter );
		vec2d_rotate ( &vBounds, -camera->pan );
		
		VECTOR vP1, vP2;
		vec_set ( &vP1, &vBounds );
		vec_set ( &vP2, vector(vBounds.x,-vBounds.y,-vBounds.z) );
		vec2d_rotate ( &vP1, camera->pan );
		vec2d_rotate ( &vP2, camera->pan );
		
		draw_line3d ( vector ( vCenter.x+vP1.x, vCenter.y+vP1.y, 0), COLOR_RED, 0 );  
		draw_line3d ( vector ( vCenter.x+vP1.x, vCenter.y+vP1.y, 0), COLOR_RED, 100 );  
		draw_line3d ( vector ( vCenter.x+vP2.x, vCenter.y+vP2.y, 0), COLOR_RED, 100 );
		draw_line3d ( vector ( vCenter.x-vP1.x, vCenter.y-vP1.y, 0), COLOR_RED, 100 ); 
		draw_line3d ( vector ( vCenter.x-vP2.x, vCenter.y-vP2.y, 0), COLOR_RED, 100 ); 
		draw_line3d ( vector ( vCenter.x+vP1.x, vCenter.y+vP1.y, 0), COLOR_RED, 100 );
		draw_line3d ( vector ( vCenter.x+vP1.x, vCenter.y+vP1.y, 0), COLOR_RED, 0 );
		
		wait(1);
	}
}

void main ()
{
	video_mode = 10;
	mouse_mode = 4;
	wait(1);
	level_load ( "" );
	camera->tilt = -30;
	camera->pan = 30;
	
	on_mouse_left = onMouseLeft;
	
	while ( !key_esc )
	{
		camera->pan += key_force.x * 10 * time_step;
		vec_for_angle ( &camera->x, &camera->pan );
		vec_scale ( &camera->x, -1000 );
		
		// World space axis
		draw_line3d ( vector(1000,0,0), COLOR_WHITE, 0 );
		draw_line3d ( vector(1000,0,0), COLOR_WHITE, 100 );
		draw_line3d ( vector(-1000,0,0), COLOR_WHITE, 100 );
		draw_line3d ( vector(-1000,0,0), COLOR_WHITE, 0 );
		draw_line3d ( vector(0,1000,0), COLOR_WHITE, 0 );
		draw_line3d ( vector(0,1000,0), COLOR_WHITE, 100 );
		draw_line3d ( vector(0,-1000,0), COLOR_WHITE, 100 );
		draw_line3d ( vector(0,-1000,0), COLOR_WHITE, 0 );
		
		wait(1);
	}
	
	sys_exit ( NULL );
}



Salud!


edited______________

a bit faster version
Code:
VECTOR vCenter, vBounds;
vec_lerp ( &vCenter, &vStart, &vEnd, 0.5 );
vec_diff ( &vBounds, &vStart, &vCenter );

VECTOR vP1, vP2;
vec_set ( &vP1, &vBounds );
vec_set ( &vP2, &vBounds );
vec2d_rotate ( &vP2, -camera->pan );
vP2.y *= -1;
vP2.z *= -1;
vec2d_rotate ( &vP2, camera->pan );



Last edited by txesmi; 10/08/16 07:21.
Re: check if entity is within rotated box [Re: txesmi] #462551
10/08/16 11:53
10/08/16 11:53
Joined: Dec 2011
Posts: 1,823
Netherlands
Reconnoiter Offline OP
Serious User
Reconnoiter  Offline OP
Serious User

Joined: Dec 2011
Posts: 1,823
Netherlands
Works like a charm now, tnx! laugh For others; if anyone has now problems with selecting entities within the bounds add this line before comparing if the enitity's vOffset is within/below the selectionbox's vBounds:

vec2d_rotate (vBounds, -camera.pan);

Re: check if entity is within rotated box [Re: Reconnoiter] #462554
10/08/16 15:33
10/08/16 15:33
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline
Serious User
txesmi  Offline
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
you are welcome smile

Page 2 of 2 1 2

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