Gamestudio Links
Zorro Links
Newest Posts
Z9 getting Error 058
by k_ivan. 04/25/26 19:13
ZorroGPT
by TipmyPip. 04/25/26 16:09
Stooq now requires an API key
by jcl. 04/13/26 09:42
Strange "Alien" Skull created with >Knubber<
by NeoDumont. 04/10/26 18:58
400 free seamless texture pack downl. here !
by NeoDumont. 04/08/26 19:55
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (3run, Grant, 1 invisible), 3,863 guests, and 14 spiders.
Key: Admin, Global Mod, Mod
Newest Members
valino, juergenwue, VladMak, Geir, ondrej
19209 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Orientation of attached Entities #314688
03/10/10 09:06
03/10/10 09:06
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline 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".

Code:
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: Germanunkol] #314711
03/10/10 13:55
03/10/10 13:55
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
why you don`t use ang_for_bone?
And turn your Bone with

ent_bonerotate( ENTITY*,STRING* name,VECTOR* angle)

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 Offline OP
Expert
Germanunkol  Offline 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: Germanunkol] #314747
03/10/10 17:21
03/10/10 17:21
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
JTLYK: The link doesn't seem to work anymore.

If I'm not mistaken you asked something similar in the past, don't you?

Without seeing the image I'm not quite sure what the problem is. However, in C-Script I once attached a turnable turret at a floating vehicle by adjusting it's position and angles to a bone. The target's coordinates were then converted into the vehicle's local coordinate system (using vec_rotate(), but now vec_to_ent() can be used, too), so I could use the pan/tilt of the bone to rotate the turret properly.
Well, I hope this somehow made sense to you.

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 Offline OP
Expert
Germanunkol  Offline 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 Offline
Serious User
Widi  Offline
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".

Code:
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 Offline OP
Expert
Germanunkol  Offline 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
Re: Orientation of attached Entities [Re: Germanunkol] #314922
03/12/10 01:05
03/12/10 01:05
Joined: Aug 2007
Posts: 1,922
Schweiz
Widi Offline
Serious User
Widi  Offline
Serious User

Joined: Aug 2007
Posts: 1,922
Schweiz
You are welcome.


Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | 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