2 registered members (TipmyPip, 1 invisible),
18,699
guests, and 8
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Bone orientation - Local vs global
#362492
03/08/11 15:13
03/08/11 15:13
|
Joined: Apr 2005
Posts: 4,506 Germany
fogman
OP
Expert
|
OP
Expert
Joined: Apr 2005
Posts: 4,506
Germany
|
I want to rotate a bone towards a target. Sounds easy, but local vs global orientation makes me some trouble.
Here´s what I got, but this doesn´t work of course:
// rotate bone13 towards bone14 vec_for_bone(gvTemp, my, "bone14"); // get position of bone14 vec_for_bone(gvTemp2, my, "bone13"); // get position of bone13 vec_sub(gvTemp,gvTemp2); vec_to_angle(gvTempAng,gvTemp); ent_bonereset(my, "bone13"); ent_bonerotate(my,"bone13", vector(0,gvTempAng.tilt,0));
no science involved
|
|
|
Re: Bone orientation - Local vs global
[Re: fogman]
#362520
03/08/11 17:20
03/08/11 17:20
|
Joined: Aug 2009
Posts: 1,438 Spain
painkiller
Serious User
|
Serious User
Joined: Aug 2009
Posts: 1,438
Spain
|
maybe with ent_bonerotate_parent ?
3D Gamestudio A8 Pro AMD FX 8350 4.00 Ghz 16GB RAM Gigabyte GeForce GTX 960 4GB
|
|
|
Re: Bone orientation - Local vs global
[Re: fogman]
#362554
03/08/11 19:12
03/08/11 19:12
|
Joined: Nov 2008
Posts: 946
the_clown
User
|
User
Joined: Nov 2008
Posts: 946
|
You have to calculate the difference of the current bone angle and the desired angle, then apply that difference by ent_bonerotate - or at least I'd do it this way.
Like
vec_for_bone(gvTemp, my, "bone14"); // get position of bone14 vec_for_bone(gvTemp2, my, "bone13"); // get position of bone13 vec_sub(gvTemp,gvTemp2); vec_to_angle(gvTempAng,gvTemp); ang_for_bone(tempAng,my,"bone13); ent_bonereset(my,"bone13"); ent_bonerotate(my,"bone13",vector(0,ang(tempAng.tilt,gvTempAng.tilt),0));
Not tested though, but I guess that's the theory.
|
|
|
Re: Bone orientation - Local vs global
[Re: the_clown]
#362595
03/08/11 20:25
03/08/11 20:25
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Okay, I haven't done this but have has similar problems a lot from what the topic says.
Bone rotation is local, right? It's the actor's local space?
If so, you will probably need "vec_rotateback".
// rotate bone13 towards bone14 vec_for_bone(gvTemp, my, "bone14"); vec_for_bone(gvTemp2, my, "bone13"); vec_diff(temp, gvTemp, gvTemp2); vec_rotateback(temp, my.pan); //should rotate back to simulate local space vec_to_ang(temp, temp); ent_bonereset(my,"bone13"); ent_bonerotate(my,"bone13",temp);
Not tested.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Bone orientation - Local vs global
[Re: Germanunkol]
#362695
03/09/11 12:12
03/09/11 12:12
|
Joined: Apr 2005
Posts: 4,506 Germany
fogman
OP
Expert
|
OP
Expert
Joined: Apr 2005
Posts: 4,506
Germany
|
Thank you very much. Bone rotation is local, right? It's the actor's local space? Unfortunately not, because every bone has its own local space. The manual says: "Bone rotations are relative to the rotation of the entity." 
no science involved
|
|
|
Re: Bone orientation - Local vs global
[Re: fogman]
#362701
03/09/11 12:32
03/09/11 12:32
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
That's what I meant, yes. It's local because they're relative to the rotation of the entity. Ah. But you're saying they're also relative to the original rotation to the bone?
Did the "Thank you very much" mean you solved it? Or was that a "thank's for the reply" and you still need help?
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Bone orientation - Local vs global
[Re: Germanunkol]
#362707
03/09/11 12:46
03/09/11 12:46
|
Joined: Apr 2005
Posts: 4,506 Germany
fogman
OP
Expert
|
OP
Expert
Joined: Apr 2005
Posts: 4,506
Germany
|
It was more a "thanks for the reply". Your example doesn´t work, and I think I´ve got the reason why it´s not working.
vec_rotateback(temp, my.pan);
When I change my.pan to the angle of the bone it might work, I´ll try this. At the moment I´m really confused.
Edit: Doesn´t work either.
Last edited by fogman; 03/09/11 12:51.
no science involved
|
|
|
Re: Bone orientation - Local vs global
[Re: fogman]
#362718
03/09/11 13:59
03/09/11 13:59
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Hm. Would you send me the model? Or an example model? Then I could see if I can get it done for you.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Bone orientation - Local vs global
[Re: Germanunkol]
#362771
03/09/11 16:28
03/09/11 16:28
|
Joined: Apr 2005
Posts: 4,506 Germany
fogman
OP
Expert
|
OP
Expert
Joined: Apr 2005
Posts: 4,506
Germany
|
I´ve done a small example, complete with model and a stripped down script. Just the main() and the action for the model. Here you go [254 kb]: http://www.vulkanware.de/stuff/Test7Bonerotate.zipYou can rotate the bones with the cursor keys. Again, thank you very much for looking. Perfect would be a function like "ent_bonerotate_to(ENTITY* ent, STRING* szBone, VECTOR* vPos)"
no science involved
|
|
|
Re: Bone orientation - Local vs global
[Re: fogman]
#362800
03/09/11 17:57
03/09/11 17:57
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
Expert
|
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Okay. I've tried it. I have a solution, but I don't know if that's enough for you. First, what the problem was: The bones' angles are 0 at startup, while their meshes are already facing each other. So when you set the angles to the angle that a vector pointing towards the position would have, this rotates the bone into that direction, but since the mesh is not pointing into the same direction as the bone, it's messed up. So what I do now is I find out the angle it has at the beginning (where the meshes are turned into the correct direction) and subtract that from the angle I want to set it at every frame. Problems that are still there in this version: - When you tilt the whole entity, the code messes up. Not only my code though, yours as well, the main arm (not only the hydraulics) already messes up when the entity is tilted. I don't know if you need to tilt the entity in your app, so I didn't worry about this for now. - if the tilt of the arm goes up to 180, it messes up. would limiting it to 179 degrees do the trick for you? or do you need it to go up to 180?
action Picker()
{
var vAngBone1 = 0;
var vAngBone2 = 0;
var vAngBone3 = 0;
var vAngBone4 = 0;
var vAngBone5 = 0;
VECTOR gvTemp2;
ANGLE gvTempAng2;
VECTOR temp, initialDir;
vec_set(temp2, nullvector);
c_setminmax(my);
ent_bonereset_all(my);
vec_for_bone(dir1, my, "bone13");
vec_for_bone(dir2, my, "bone14");
vec_diff(initialDir, dir2, dir1);
vec_to_angle(initialAngle, initialDir);
while(1)
{
my.pan += (key_o - key_p)*time_step*3;
//my.tilt += (key_k - key_l)*time_step*3;
vAngBone1+= (key_cul-key_cur)*3*time_step; // bone1 angle (base pan)
ent_bonereset(my, "bone1");
ent_bonerotate(my,"bone1", vector(vAngBone1, 0, 0)); // rotate bone
vAngBone2+= (key_cud-key_cuu)*3*time_step; // bone2 angle (base arm tilt)
vAngBone2 = clamp(vAngBone2, 0, 80);
ent_bonereset(my, "bone2");
ent_bonerotate(my,"bone2", vector(0, vAngBone2, 0)); // rotate bone
ang_for_bone(gvTempAng, my, "bone3"); // get angle of bone3
ent_bonerotate(my,"bone3", vector(0,-gvTempAng.tilt,0)); // fixed bone angle
vec_for_bone(dir1, my, "bone13");
vec_for_bone(dir2, my, "bone14");
vec_diff(temp, dir2, dir1);
vec_to_angle(curAngle, temp);
vec_diff(temp, curAngle, initialAngle);
ent_bonereset(my, "bone13");
ent_bonerotate(my, "bone13", vector(0,temp.y,0));
// rotate bone 14 in opposite direction:
// vec_diff(temp, initialAngle, curAngle);
ent_bonereset(my, "bone14");
ent_bonerotate(my, "bone14", vector(0,temp.y,0));
wait(1);
}
}
Last edited by Germanunkol; 03/09/11 17:58.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
|