Gamestudio Links
Zorro Links
Newest Posts
Zorro FIX plugin - Experimental
by flink. 04/21/24 07:12
Data from CSV not parsed correctly
by EternallyCurious. 04/20/24 21:39
M1 Oversampling
by 11honza11. 04/20/24 20:57
Scripts not found
by juergen_wue. 04/20/24 18:51
zorro 64bit command line support
by 7th_zorro. 04/20/24 10:06
StartWeek not working as it should
by jcl. 04/20/24 08:38
folder management functions
by VoroneTZ. 04/17/24 06:52
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (rki), 405 guests, and 1 spider.
Key: Admin, Global Mod, Mod
Newest Members
EternallyCurious, howardR, 11honza11, ccorrea, sakolin
19047 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
calculation of euler angles from position vectors #377009
07/09/11 00:46
07/09/11 00:46
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
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

Last edited by pjotr987; 07/09/11 12:55.
Re: calculation of euler angles from position vectors [Re: pjotr987] #377053
07/09/11 16:10
07/09/11 16:10
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
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

Re: calculation of euler angles from position vectors [Re: Myrkling] #377055
07/09/11 16:20
07/09/11 16:20
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
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

Re: calculation of euler angles from position vectors [Re: pjotr987] #377112
07/10/11 09:46
07/10/11 09:46
Joined: Jul 2011
Posts: 69
P
pjotr987 Offline OP
Junior Member
pjotr987  Offline OP
Junior Member
P

Joined: Jul 2011
Posts: 69
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



Last edited by pjotr987; 07/10/11 10:01.
Re: calculation of euler angles from position vectors [Re: pjotr987] #377117
07/10/11 10:44
07/10/11 10:44
Joined: Oct 2006
Posts: 873
S
Shadow969 Offline
User
Shadow969  Offline
User
S

Joined: Oct 2006
Posts: 873
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.

Re: calculation of euler angles from position vectors [Re: Shadow969] #377125
07/10/11 13:05
07/10/11 13:05
Joined: Feb 2011
Posts: 135
Myrkling Offline
Member
Myrkling  Offline
Member

Joined: Feb 2011
Posts: 135
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


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