Help needed with Rotation and Bone Orientation

Posted By: EpsiloN

Help needed with Rotation and Bone Orientation - 07/20/15 21:23

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);
	}
}

Posted By: txesmi

Re: Help needed with Rotation and Bone Orientation - 07/22/15 07:23

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!
Posted By: EpsiloN

Re: Help needed with Rotation and Bone Orientation - 07/22/15 21:39

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...
Posted By: EpsiloN

Re: Help needed with Rotation and Bone Orientation - 07/26/15 07:32

It works, but instead of rotating back I add up the angles of the parent bones.

Thanks laugh
Posted By: txesmi

Re: Help needed with Rotation and Bone Orientation - 07/26/15 12:52

Glad to help laugh
© 2024 lite-C Forums