Gamestudio Links
Zorro Links
Newest Posts
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
LPDIRECT3DCUBETEXTUR
E9

by Ayumi. 04/12/24 11:00
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
6 registered members (AndrewAMD, ricky_k, EternallyCurious, 7th_zorro, 2 invisible), 477 guests, and 3 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Rotate an object with mouse #453447
07/27/15 09:13
07/27/15 09:13
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
Again, hi all.

So, apparently I skipped a few years of math from highschool about vectors and angles grin here we go again...

To describe the problem better, I want to 'drag' a point of the sphere surface, thats under my mouse pointer, to a new location on the sphere surface. I'm either close, but visibly inaccurate or completely off...

I'm tracing two rays from mouse pos to a sphere (gizmo) and I get the two points coordinates relative to the model origin with:
Code:
vec_set( m3dStartPos , vector( mouse_pos.x , mouse_pos.y , 1 ) );
vec_set( m3dEndPos , vector( mouse_pos.x , mouse_pos.y , 1000 ) );
vec_for_screen( m3dStartPos , camera );
vec_for_screen( m3dEndPos , camera );
you = puppet;
result = c_trace( m3dStartPos , m3dEndPos , IGNORE_YOU | USE_POLYGON );
if( result > 0 ) {
	// Get local point position (relative to my sphere)
	vec_diff( oldContactPos , hit.x , my.x );
}

wait(1);

vec_set( m3dStartPos , vector( mouse_pos.x , mouse_pos.y , 1 ) );
vec_set( m3dEndPos , vector( mouse_pos.x , mouse_pos.y , 1000 ) );
vec_for_screen( m3dStartPos , camera );
vec_for_screen( m3dEndPos , camera );
you = puppet;
result = c_trace( m3dStartPos , m3dEndPos , IGNORE_YOU | USE_POLYGON );
if( result > 0 ) {
	// Get local point position (relative to my sphere)
	vec_diff( contactPos , hit.x , my.x );
}


"My" is the sphere.

And I'm trying to rotate my gizmo so that oldContactPos will move to the new contactPos location.
All attempts failed, here's the last two:
Code:
if( vec_dist( oldContactPos , contactPos ) > 0 ) {
	VECTOR dir1 , dir2 , axis1 ;
	ANGLE oldAng , newAng , diffAng ;

//
// Using vec_to_angle to orient two angles
// and get the difference needed to rotate the gizmo
/*	vec_set( dir1 , contactPos );
	vec_set( dir2 , oldContactPos );
	vec_to_angle( oldAng , oldContactPos );
// Here roll becomes 2xxx, so I reset it to 0
// But I think I need roll too, to be a realistic rot.?
	oldAng.roll = 0;
	vec_to_angle( newAng , contactPos );
	newAng.roll = 0;
	ang_diff( diffAng , newAng , oldAng );

	ang_add( my.pan , diffAng );
	ang_add( my.local_pan , diffAng );
*/

//
// Using ang_for_axis to rotate the objects angles
// by the angle difference of the two points
// around axis - cross product of the two points
// (relative to local object space)
	vec_set( dir1 , oldContactPos );
	vec_set( dir2 , contactPos );
	vec_cross( axis1 , dir1 , dir2 );
	vec_set( newAng , my.pan );
	vec_normalize( dir1 , 1 );
	vec_normalize( dir2 , 1 );
	ang_for_axis( newAng , axis1 , acosv( vec_dot( dir1 , dir2 ) ) );

	ang_add( my.pan , newAng );
	ang_add( my.local_pan , newAng );
}



Anyone know why both methods fail? I have no idea what I'm doing wrong, but this must be my 20-th attempt doing the same stuff and always wrong...

Thanks in advance.


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Rotate an object with mouse [Re: EpsiloN] #453448
07/27/15 09:29
07/27/15 09:29
Joined: Oct 2011
Posts: 1,082
Germany
C
Ch40zzC0d3r Offline
Serious User
Ch40zzC0d3r  Offline
Serious User
C

Joined: Oct 2011
Posts: 1,082
Germany
Just rotate it arround the distance your cursor moved in pixels from click position until now? o.o

Re: Rotate an object with mouse [Re: Ch40zzC0d3r] #453449
07/27/15 09:35
07/27/15 09:35
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
I will provide that method too in my app, but I need the 'realistic' rotation too, as if you're rotating the object by hand...

This article is my goal:
http://www.quantimegroup.com/solutions/pages/Article/Article.html

But I dont understand java that much and I dont have access to the polygons of the sphere to implement that laugh so I'm trying to figure it out on my own, but I'm failing...

I dont see anything wrong with my script, but it is not working, both methods...or my previous attempts...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Rotate an object with mouse [Re: EpsiloN] #453451
07/27/15 11:21
07/27/15 11:21
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
Hi,
I built same method of you (the second) and it is working.

I realized that the sphere entity needs the POLYGON flag set. Otherway the hit position vector differs from the point it should hit visually.

Code:
#include <acknex.h>

void fncRotate ()
{
	VECTOR vPos, vTarget;
	vec_set ( &vPos, &camera->x );
	vec_set ( &vTarget, &mouse_dir3d );
	vec_scale ( &vTarget, 1000 );
	vec_add ( &vTarget, &vPos );
	c_trace ( &vPos, &vTarget, NULL );
	if ( HIT_TARGET )
	{
		ENTITY *ent = you;
		VECTOR vDir1;
		vec_diff ( &vDir1, &hit->x, &you->x );
		vec_normalize ( &vDir1, 1 );
		ANGLE angOld;
		vec_set ( &angOld, &you->pan );
		while ( mouse_left )
		{
			vec_set ( &vPos, &camera->x );
			vec_set ( &vTarget, &mouse_dir3d );
			vec_scale ( &vTarget, 1000 );
			vec_add ( &vTarget, &vPos );
			c_trace ( &vPos, &vTarget, NULL );
			if ( HIT_TARGET )
			{
				if ( you == ent )
				{
					draw_point3d ( &hit->x, COLOR_WHITE, 100, 2 );
					VECTOR vDir2, vAxis;
					vec_diff ( &vDir2, &hit->x, &you->x );
					vec_normalize ( &vDir2, 1 );
					vec_cross ( &vAxis , &vDir1 , &vDir2 );
					ANGLE angRot;
					ang_for_axis( &angRot, &vAxis, acosv ( vec_dot ( &vDir1 , &vDir2 ) ) );
					vec_set ( &you->pan, &angOld );
					ang_add( &you->pan, &angRot );
				}
			}
			
			DEBUG_VAR ( ent->pan, 10 );
			DEBUG_VAR ( ent->tilt, 40 );
			DEBUG_VAR ( ent->roll, 70 );
			wait(1);
		}
	}
}

void main ()
{
	mouse_mode = 4;
	wait(1);
	
	level_load ( "" );
	camera->x -= 100;
	ENTITY *ent = ent_create ( "sphere.mdl", nullvector, NULL );
	ent->flags |= POLYGON;
	
	on_mouse_left = fncRotate;
	
	while ( !key_esc )
		wait(1);
	
	ent_remove ( ent );
	sys_exit ( NULL );
	
}



Salud!

Re: Rotate an object with mouse [Re: txesmi] #453457
07/27/15 12:51
07/27/15 12:51
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
I havent tested it yet, but thanks again for saving my ass laugh


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Rotate an object with mouse [Re: EpsiloN] #453473
07/28/15 05:47
07/28/15 05:47
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
Glad to help laugh


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