Gamestudio Links
Zorro Links
Newest Posts
loading historical data 1st time
by AndrewAMD. 04/14/23 12:54
Trade at bar open
by juanex. 04/13/23 19:43
Bug in Highpass2 filter
by rki. 04/13/23 09:54
Adding Limit Orders For IB
by scatters. 04/11/23 16:16
FisherN
by rki. 04/11/23 08:38
AUM Magazine
Latest Screens
SHADOW (2014)
DEAD TASTE
Tactics of World War I
Hecknex World
Who's Online Now
1 registered members (Grant), 999 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
rki, FranzIII, indonesiae, The_Judge, storrealba
18919 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
z axis facing another entity #269866
06/04/09 22:55
06/04/09 22:55
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Hi.
I've spent hours on this now, and I'm fed up with all these angles.
When i use vec_diff(temp,targetEnt.x,my.x);vec_to_angle(my.pan,temp);
I get what's shown on the left here:

It faces the targetEnt, but its roll could be anything (I think it's usually 0). Now I want the roll to be changed so that the z axis faces a second entity (shown on the right of the image).
Of course, depending on where that entity is, I can't face both (I'd need to tilt the moving entity for that) so to be more exact:

I want the x AND z axis of the moving entity to lie on the plane that the three entities' origins are all part of, with the x axis pointing at the first of the two targets.
It can't be that hard?!
help?


~"I never let school interfere with my education"~
-Mark Twain
Re: z axis facing another entity [Re: Germanunkol] #269905
06/05/09 07:31
06/05/09 07:31
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
Tobias Offline

Moderator
Tobias  Offline

Moderator

Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
I think this is medium difficult. I would use either the cross product or the dot product of the z axis vector (0,0,1) and the vector to the target entity, for calculating the angle difference. Then, set the roll angle to that angle difference.

Re: z axis facing another entity [Re: Tobias] #269968
06/05/09 11:05
06/05/09 11:05
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
Tried that before I posted here, doesn't work. 2 things: If I calculate the angle difference and the target is not in the plane that is defined by the ship's ( == the moving entitie's) origin and the ship's direction as a normal vector, then the angle is greater than the roll angle I'd need to set.
So instead, I projected the vector from the ship to the target into the plane that I just mentioned and then set the roll to the angle difference between the entitie's local z axis and the vector to the target (in the plane):
http://www4.picfront.org/picture/NzvzJ7CY/img/vecs4Eva.jpg
the red vector is the projected vector, the dotted orange-ish vector is the vector to the target.
Problem now is that I use:
vec_diff(temp,my.x,myFrontTarget.x);
vec_to_angle(my.pan,temp);
and then, after calculating the angle difference to myTopTarget:
my.roll += angleDifference;
Now, for some reason, when i do this once a frame, the entity's keep on "jumping" around.

Thanks for the suggestion!

edit: I think my calculation for the roll angle may have been wrong. So maybe this method works after all. I'll keep trying, but I'm still open for other methods.

edit2: solved. The problem was that I forgot that the angle between the two vectors was always positive. so when adding that to the roll angle I need to change the sign if the target is below the entity.

Last edited by Germanunkol; 06/05/09 12:31.

~"I never let school interfere with my education"~
-Mark Twain
Re: z axis facing another entity [Re: Germanunkol] #269976
06/05/09 12:28
06/05/09 12:28
Joined: Dec 2008
Posts: 271
Saturnus Offline
Member
Saturnus  Offline
Member

Joined: Dec 2008
Posts: 271
Hello!

I am not very good in mathematics, but the rotation should work this way, I guess. Obviously it's basically the same method as mentioned in your post, Germanunkol.
Perhaps it is useful for comparison. : )

Let Ship be the entity that needs to be rotated.
Let A be the primary target (targetEnt) of Ship.
Let B be the secondary target of Ship.

Generate a plane P with the current viewing direction of Ship as normal. The position of Ship should be a point on plane P.

Use the position of B as a position vector for the current viewing direction of Ship. This yields vector V, which defines a segment of a line L. Calculate the intersection point IP of line L and plane P.

Use the local Z-axis of Ship as a vector Z.

Now rotate Ship via ang_for_axis() about its viewing direction until the directions of Z and the direction vector from Ship to IP match. By calculating the angle between the two vectors the shorter direction of rotation can be calculated.

Re: z axis facing another entity [Re: Saturnus] #269978
06/05/09 12:37
06/05/09 12:37
Joined: Jun 2006
Posts: 2,640
Earth
Germanunkol Offline OP
Expert
Germanunkol  Offline OP
Expert

Joined: Jun 2006
Posts: 2,640
Earth
thank you very much for your answer. I did pretty much what you wrote at the top, the intersectionpoint IP you mention and my projection point are the same thing. But the last sentences you wrote were exactly where my mistake was. I wasn't rotating in the right direction. I can't find ang_for_axis in the manual though... it sounds like it's just what I need for the actual rotating process.

Edit 3:
I found it on the beta page. Thanks. I was waiting for such a function smile

Last edited by Germanunkol; 06/05/09 12:56.

~"I never let school interfere with my education"~
-Mark Twain

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