calculation of euler angles from position vectors

Posted By: pjotr987

calculation of euler angles from position vectors - 07/09/11 00:46

halo all together,
i have 3 following questions.
1: Is it possible to read out the bone euler angles using:
ang_for_bone(ANGLE*,ENTITY*,STRING*) function,
then use a position vector as target position for the new
bone localisation?
2: how can i calculate euler angles from position vectors?

3: how to build a quaternion from a position vector:

any help is welcome laugh
Posted By: Myrkling

Re: calculation of euler angles from position vectors - 07/09/11 16:10

1)
I'm not sure if I understood your question correctly, but if you want to rotate a bone towards a target position, then the answer is: yes, this is possible.

The code should look something like this:
Code:
VECTOR  bone_pos, *to_target;
ANGLE   bone_angle;
    
vec_for_bone(bone_pos, entity, "bone");
to_target = vec_diff(NULL, target_position, bone_pos);
vec_to_angle(bone_angle, to_target);
        
// Take the entity's pan rotation into account.
bone_angle.pan -= entity.pan;
// To make this work with tilt and roll as well, we would have to
// transform the target position into the entity's local space.
        
ent_bonereset_all(entity);
ent_bonerotate(entity, "bone", bone_angle);



2)
vec_to_angle()

3)
Have a look at this thread:
http://www.opserver.de/ubb7/ubbthreads.php?ubb=showflat&Number=114062#Post114062
Posted By: pjotr987

Re: calculation of euler angles from position vectors - 07/09/11 16:20

Myrkling,
thanks for your answer i ll take a look on it and will tell wheather it worked for me or not. At least now i have where to start.

thanks one more time
Posted By: pjotr987

Re: calculation of euler angles from position vectors - 07/10/11 09:46

Hi again,
i still have the problem with orientation of the bones.
The thing is i am getting permanently new points in 3D space expressed in vectors. Now i want that my bone changes the orientations towards exactly this changing points.

The code from Myrkling above seems to be suitable but the bone is moving only in pan direction. How to get tilt and roll orientations working??

and sorry if i get it wrong, but according to the manual i get only pan and tilt using
vec_to_angle (ANGLE* ang, VECTOR* dir);
roll seems to be missing

thanks in advance for any help


Posted By: Shadow969

Re: calculation of euler angles from position vectors - 07/10/11 10:44

Quote:
but according to the manual i get only pan and tilt using vec_to_angle

yes, it's due to the fact that in order to define third degree of freedom(roll) you have to specify third point in coordinate space. unfortunately, gamestudio doesn't have a predefined function for this, so you'll have to deal with underlying math to implement it. however, if you're willing to make some kind of ragdoll system (just my guess), you won't need this anyway.

as for quaternions - one forum member has made a neat tutorial, explaning how they work and how to implement them (it was either Joozey or JibbSmart if i recall correct), just search for it.
Posted By: Myrkling

Re: calculation of euler angles from position vectors - 07/10/11 13:05

The code above should change both the bone's pan and tilt. The code doesn't consider the tilt and roll of the entity, though, so if the entity is tilted or rolled, the bone's rotation won't be correct anymore.

If overcoming this limitation is what you're looking for, the following snippet should do the trick. It's a slightly modified version of the code above.
Code:
VECTOR  bone_pos, local_target_pos;
ANGLE   bone_angle;

vec_for_bone(bone_pos, entity, "bone");
vec_set(local_target_pos, target_position);
vec_to_ent(local_target_pos, entity);
vec_to_angle(bone_angle, local_target_pos);

// vec_to_angle leaves roll unchanged.
// To prevent random roll angles, roll must be set manually.
bone_angle.roll = 0;

ent_bonereset_all(entity);
ent_bonerotate(entity, "bone", bone_angle);


I did a quick and dirty test and the code worked properly. There might be sitations, however, I didn't take account of, in which it fails. This is left to be checked. laugh
© 2024 lite-C Forums