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 (1 invisible), 692 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, 11honza11, ccorrea, sakolin, rajesh7827
19046 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Help needed with Rotation and Bone Orientation #453324
07/20/15 21:23
07/20/15 21:23
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
Hi all,

PLEASE HELP!

I'm getting desperate. I cant match the orientation of a bone and a gizmo and rotate them together...

Here's my gizmo function.
myBias is an angle difference between the actual (world) bone orientation and the local bone orientation (0,0,0 at start)
The actual (world) bone orientation comes from a vec_set/sub/to_angle between the bone joint and its child joint (for example shoulder>elbow and elbow>wrist)
When I run the script and point to the elbow, the gizmo and bone rotate in sync, but when I rotate even a little the shoulder joint, the elbow bone will shift its rotation axis off from the elbow gizmo even with the aligning I'm doing for the gizmo towards new bone angles when I'm not pointing the mouse at the elbow gizmo.
(Testing with X axis gizmos only, for now...)
In other words, the elbow gizmo still has the same orientation it should towards the wrist joint, but the elbow joint behaves as being shifted from its original orientation relative to the bone when I point the mouse at the elbow gizmo after the shoulder has been rotated a little...
Code:
function rotationGizmo() {
	var myBias[3];

	ANGLE* tmpAng1[3];
	var tmpAng2[3];
	// WAIT FOR EXTERIOR INITIALIZATION
	wait(4);	
	vec_set( myBias[0] , my.pan );

	while(1) {
		if(my.bone_handle) {
			you = ptr_for_handle( my.parent_entity );	// Entity containing the bone
			if(you) {
		if(mouse_ent != me) {

				// Update my position to joint position
				vec_for_bone( my.x , you , (long)my.bone_handle );
				// Rotate gizmo to match bone orientation
				ang_for_bone( tmpAng2[0] , you , (long)my.bone_handle );
				vec_set( my.pan , myBias[0] );
				ang_add( my.pan , tmpAng2[0] );
		}

		if(mouse_ent == me) {
				ang_rotate( my.pan , vector( 5 * time_step , 0 , 0 ) );

				// Rotate bone to my Orientation
				ent_bonereset( you , (long)my.bone_handle );
				ang_diff( tmpAng1.pan , my.pan , myBias[0] );
				ent_bonerotate( you , (long)my.bone_handle , tmpAng1.pan );
		}

			}
		}
		wait(1);
	}
}



Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Help needed with Rotation and Bone Orientation [Re: EpsiloN] #453350
07/22/15 07:23
07/22/15 07:23
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 am not able to test it but I think you should rotate back the orientation of the gizmo by all the bones parents orientation.

Code:
ANGLE aTemp1, aTemp2;
vec_set ( aTemp1, my.pan );
var hndParent = ent_boneparent ( you, NULL, (long)my.bone_handle );
while ( hndParent )
{
	ang_for_bone ( aTemp2 , you , (long)hndParent );
	vec_rotateback ( aTemp1, aTemp2 );
	hndParent = ent_boneparent ( you, NULL, (long)hndParent );
}
vec_rotateback ( aTemp1, you.pan );
ent_bonereset ( you , (long)my.bone_handle );
ent_bonerotate ( you , (long)my.bone_handle , aTemp1 );



Hope it helps,
salud!

Re: Help needed with Rotation and Bone Orientation [Re: txesmi] #453365
07/22/15 21:39
07/22/15 21:39
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
I will test your solution tomorrow, in order to make it more 'general'.

I just succeeded in making the gizmo rotate in sync with the joint by using local angles.
But, the local angle of the gizmo is the same as the absolute angle, so I keep track of the local angle in skills.

When I rotate a bone, I rotate the absolute angle of the child bone gizmo to match the new "absolute" orientation of a bone, but it still keeps the local angles intact in the gizmo skills, and when I need to rotate the child gizmo and bone I use the difference between the old local angle and the new rotated local angle and rotate the bone.

Currently, my solution isnt good, because (out of desperation) I've defined all the bone positions, orientations, handles and I use a separate function for each gizmo at every joint. I currently have two joints with gizmos testing and I'm already at 300 lines of code for the gizmos alone grin

I intend to share the script, so I'll have to make it more general, without hard definitions...

I'll tell you how it goes...


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Help needed with Rotation and Bone Orientation [Re: EpsiloN] #453426
07/26/15 07:32
07/26/15 07:32
Joined: Jan 2006
Posts: 968
EpsiloN Offline OP
User
EpsiloN  Offline OP
User

Joined: Jan 2006
Posts: 968
It works, but instead of rotating back I add up the angles of the parent bones.

Thanks laugh


Extensive Multiplayer tutorial:
http://mesetts.com/index.php?page=201
Re: Help needed with Rotation and Bone Orientation [Re: EpsiloN] #453430
07/26/15 12:52
07/26/15 12:52
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