View topic - Angles, Directions, Trig...



All times are UTC + 1 hour


Post new topic Reply to topic  [ 10 posts ] 
Author Message
PostPosted: 21 Mar 2012, 15:39 
Map Creator
User avatar

Joined: 12 Jan 2005, 10:25
Location: Still signing off after all these years
Hi guys, working on a script for a unit and running into a whole load of mindslopionation re what the games returning angle wise.
Code:
unitdir1,unitdir2,unitdir3 = Spring.GetUnitDirection(unitID)

in this case am I right in thinking that unitdir1 will be which way the unit is facing? In which case where's that measured from (IE is that from "north" "south" "east" or "west"). Also am I right in thinking this is returning (stupidly) values from -pi to pi? (Instead of 0 to 2pi which is what I expected... I take it theres a reason...)

Thanks

aGorm


Top
 Offline Profile  
 
PostPosted: 21 Mar 2012, 19:23 
Kernel Panic Co-Developer
User avatar

Joined: 16 Nov 2004, 13:08
I would say unitdir1, unitdir2, unitdir3 are the cartesian coordinates (that, is, the X, the Y, the Z) of a vertex. This vertex direction is the same as the unit direction.

So no, they are not angles in the [-pi,pi] range. They are coordinates in the [-1,1] range (assuming the vertex is normalised).

Mostly a guess, though.


Top
 Offline Profile  
 
PostPosted: 21 Mar 2012, 21:13 
Moderator
User avatar

Joined: 29 Apr 2005, 00:14
Location: #moddev - join it!
zwzsg wrote:
I would say unitdir1, unitdir2, unitdir3 are the cartesian coordinates (that, is, the X, the Y, the Z) of a vertex. This vertex direction is the same as the unit direction.

So no, they are not angles in the [-pi,pi] range. They are coordinates in the [-1,1] range (assuming the vertex is normalised).

Mostly a guess, though.


Would be my guess / recollection also.


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 10:49 
Map Creator
User avatar

Joined: 12 Jan 2005, 10:25
Location: Still signing off after all these years
Ok, you've both really lost me there? Are you saying that they are the coordinates of a point which a line from the unit center would travel though that is pointing in the direction the unit is facing?

IE, if unitdir1=1 and the others are all 0 the unit is facing towards X?

And if unitdir1=0.5 then either unitdir2 or 3 would be 0.866...ish?

If so thats fine I can work with that, it's just a pain in the arse and I can't imagin why anyone would need those values in that format...

(I assume there is some cool math that you can do with it though and someone who's good at math will prob look at my script and go why the hell is he doing everything like this?)

aGorm


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 13:39 
Moderator

Joined: 12 Oct 2007, 08:24
It's just a vector, they are quite useful.

If you want x,z direction use this:
Code:
dir = Spring.GetUnitHeading(unitID)/32768*math.pi


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 13:56 
Map Creator
User avatar

Joined: 12 Jan 2005, 10:25
Location: Still signing off after all these years
Thanks... out of intrest whats the /32768 for? Just some magic constant?

aGorm


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 14:13 
Moderator

Joined: 12 Oct 2007, 08:24
32768 = 2^15

There are 2^16 heading units in a circle and 2pi radians in a circle.


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 14:24 
Map Creator
User avatar

Joined: 12 Jan 2005, 10:25
Location: Still signing off after all these years
That explains why when I tryed it with heading everything went weird... I assumed it returned in radians.

aGorm


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 14:52 

Joined: 17 Mar 2009, 00:20
aGorm wrote:
Thanks... out of intrest whats the /32768 for? Just some magic constant?

aGorm


32768 binary number


Top
 Offline Profile  
 
PostPosted: 22 Mar 2012, 15:22 
Map Creator
User avatar

Joined: 12 Jan 2005, 10:25
Location: Still signing off after all these years
Woohahahha it works. After a lot of head banging I have 3 legs positioned with the power of math! It's strange how you forget how trig works when you havn't done it for 10 years...

not that this pic explains much but the legs are positioned by the numbers echoing at the top, which are worked out from 3 empty peices in the root of the object and then ofset by the unit rotation. (by default all the legs are just pointing stright back...)
Attachment:
itworkshahaha.jpg [89.29 KiB]
Downloaded 2 times

This means I can now feed in cordinates of where the leg was previously and move it to there, and thus create the illusion of the feet sticking to the ground... well after I get the legs to also extend out to the points aswell... more math... :-(

aGorm


Top
 Offline Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group

Site layout created by Roflcopter et al.