|
3 registered members (3run, Grant, 1 invisible),
3,863
guests, and 14
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
Orientation of attached Entities
#314688
03/10/10 09:06
03/10/10 09:06
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Hi! I have sets of two bones on my ship model. Every set of two bones has a "connection bone" -> the position where the gun should be attached, and an "orientation bone", a bone a little off from the connection bone that the gun's z axis should be facing at, while the gun should look into the direction that the ship's facing:  Here: the gun should be facing (using pan and tilt values) into the direction the red arrow's pointing in, and then rotate to sit on the surface of the ship, meaning the z axis should point along the normal (here along the green arrow). The selected bone here is the "orientation bone" and the non-selected one next to it the "connection bone".
you = my.parentShip;
if(you != NULL && exiting == 0)
{
vec_for_bone(temp,you,connectBone);
vec_set(my.x,temp);
vec_set(my.pan,you.pan);
vec_for_bone(orientationBonePos,you,orientationBone);
vec_diff(orientationVec,orientationBonePos,my.x);
vec_set(temp,vector(0,0,-1)); vec_rotate(temp, you.pan);
vec_normalize(orientationVec,1);
rollCorrection = ang_between_vecs(orientationVec,temp);
//because ang_between_vecs returns only positive values, check which direction would make more sense and turn into that direction:
vec_set(vec1,vector(0,-10,0));vec_rotate(vec1,my.pan);vec_add(vec1,my.x);
vec_set(vec2,vector(0,10,0));vec_rotate(vec2,my.pan);vec_add(vec2,my.x);
if(vec_dist(vec1,orientationBonePos) < vec_dist(vec2,orientationBonePos)) rollCorrection *= -1;
my.roll += rollCorrection;
}
This is my current approach. It sets wrong roll values. And I don't understand why. Pan and tilt are fine, meaning the gun points in the right direction, but doesn't rotate to sit on the surface correctly. I hope you understand what I want to achieve... Help?
Last edited by Germanunkol; 03/10/10 17:24.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Orientation of attached Entities
[Re: Widi]
#314726
03/10/10 16:01
03/10/10 16:01
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
because I don't want the entity to face into the direction of the bone. This function will, as far as I know, only correct the pan and the tilt angle, but the roll angle will be wrong then...
I need pan and tilt to face forward, and then need it to roll until its local z axis points along the normal of the attached surface.
Edit: if I make it point into the direction of the bone using ent_bonerotate, there's a (theoretically) infinite number of roll angles it could end up at, right?
Last edited by Germanunkol; 03/10/10 16:02.
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Orientation of attached Entities
[Re: Saturnus]
#314750
03/10/10 17:28
03/10/10 17:28
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Thanks for the info, I fixed the link.
I have asked something very similar in the past. Two times, actually, but they were different problems. I thought I had fixed it after asking that last time, but now I came back to see that it's not fixed at all, only some of the angles were right, but most weren't.
The problem I always have is not orienting the guns in the right way (I've used vec_rotate, vec_rotateback and worked with vec_to_ent), my problem is that I usually get weird result because those commands often only care about pan and tilt, and that get's me really confused. The big problem is probably that I'm making a space game, so you can tilt above 90 degrees and it still needs to be set right...
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
Re: Orientation of attached Entities
[Re: Germanunkol]
#314753
03/10/10 17:59
03/10/10 17:59
|
Joined: Aug 2007
Posts: 1,922 Schweiz
Widi
Serious User
|
Serious User
Joined: Aug 2007
Posts: 1,922
Schweiz
|
Ok, here is a example with vec_for_vertex. I think you can convert it to your Bones - Code. For that you need 3 bones (or vertices) that are positioned like a "L".
void SETZE_ANGEH_GST(vertex_1,vertex_2,vertex_3)
{
proc_mode = PROC_LATE;
vec_for_vertex (Vertex_pos_1,you,vertex_1); // Hole Vertex - Positionen
vec_for_vertex (Vertex_pos_2,you,vertex_2);
vec_for_vertex (Vertex_pos_3,you,vertex_3);
vec_set (my.x, Vertex_pos_2); // Setze meine Position an vertex_2
vec_sub(Vertex_pos_1,Vertex_pos_2); // setze unseren pan und tilt
vec_to_angle(my.pan,Vertex_pos_1);
my.roll = 0; // Berechne unseren roll
vec_sub(Vertex_pos_2,Vertex_pos_3);
vec_set (Vertex_ebene_1, vector(0,1,0));
vec_rotate (Vertex_ebene_1, my.pan);
vec_set (Vertex_ebene_2, vector(0,0,1));
vec_rotate (Vertex_ebene_2, my.pan); // Diese Vectoren spannen die Ebene auf
Vertex_roll.x = vec_dot (Vertex_ebene_1, Vertex_pos_2);
Vertex_roll.y = vec_dot (Vertex_ebene_2, Vertex_pos_2);
vec_to_angle (Temp_ang1, Vertex_roll);
my.roll = Temp_ang1.pan;
}
Call this function in a while loop. You have to define also some VECTOR (Vertex_pos_1,Vertex_pos_,Vertex_pos_3,Vertex_ebene_1,Vertex_ebene_2,Vertex_roll)
|
|
|
Re: Orientation of attached Entities
[Re: Widi]
#314905
03/11/10 22:10
03/11/10 22:10
|
Joined: Jun 2006
Posts: 2,640 Earth
Germanunkol
OP
Expert
|
OP
Expert
Joined: Jun 2006
Posts: 2,640
Earth
|
Seems to be working great, thank you very much. Just the code I was looking for. Nice!
Had to move a lot of my bones, but that's fine and done.
Thanks!
~"I never let school interfere with my education"~ -Mark Twain
|
|
|
|