Hard Light Productions Forums

Modding, Mission Design, and Coding => FS2 Open Coding - The Source Code Project (SCP) => Topic started by: lukeopai on April 13, 2015, 11:04:34 pm

Title: Accessing Ship Orientation
Post by: lukeopai on April 13, 2015, 11:04:34 pm
Hi there,

I was wondering if someone knows if the player’s ship orientation can be accessed from FSO by some means. 

Can someone let me know if this is currently accessible in FSO somehow?  If not then is there somewhere that I can put this down as an enhancement idea?

Thanks!

Luke
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: chief1983 on April 13, 2015, 11:07:32 pm
If there is, it's probably in the Lua scripting, and if there's not, that's probably where it should go.
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: AdmiralRalwood on April 13, 2015, 11:30:24 pm
This information should be accessible with Lua scripting, through the ship's orientation matrix. In SEXPs, there's "get-object-pitch", "get-object-bank", and "get-object-heading".
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: lukeopai on April 14, 2015, 12:09:51 am
Thanks for the info.  I can see that these functions are in SEXP (sexp.cpp) and appear to be what I am looking for. 

My next question is: are SEXP functions available through LUA scripting?  If so, can someone direct me to some documnetation on (or explain) how this might be acheived?

Thanks!

Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: lukeopai on April 14, 2015, 12:19:06 am
Nevermind, I can see that I can call runSEXP in LUA to run these functions.  Pretty powerful stuff, looking forward to getting this working.  Thanks for the help guys!
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: The E on April 14, 2015, 12:51:37 am
There's an easier way, though, one that doesn't require a detour through the sexp code. Every ingame object (ship, weapon) has an "orientation" member variable, which in turn is a matrix object that has member variables called p, b and h.

Example:
Code: [Select]
for i = 1, #mn.Ships do
     local tempship = mn.Ships[i]
     local pitch = tempship.Orientation.p
     local bank = tempship.Orientation.b
     local heading = tempship.Orientation.h

--do stuff
end
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: lukeopai on April 14, 2015, 01:31:04 am
Excellent suggestion.  Thanks!
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: lukeopai on April 14, 2015, 01:34:09 am
Can someone suggest some LUA code (or hook) to run this on a regular basis during the game.   

I would only need updated these angles a couple of times a second maybe, not nessessarly every frame.

Thanks.
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: The E on April 14, 2015, 01:50:32 am
Then you do need to run code every frame, and use mn.Missiontime to read the current timestamp.
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: lukeopai on April 14, 2015, 01:54:11 am
Got it, thanks! 

One final thing.  Can LUA write to a socket? 

I would like to get this game data to another process that is listening on a specified port.

Cheers
Title: Re: Accessing Euler Angles - roll, pitch, yaw
Post by: m!m on April 14, 2015, 03:09:30 am
You could try LuaSockets (http://w3.impa.br/~diego/software/luasocket/) but I am not sure if FSO properly handles loading external DLLs.
Title: Re: Accessing Ship Orientation
Post by: lukeopai on April 15, 2015, 07:42:33 am

Can anyone tell me what units that the orientation is in or how to interpret it?

I am using:
local pitch = plr.Orientation.p
local bank = plr.Orientation.b
local heading = plr.Orientation.h

It looks like it could be radians but then I get negative numbers also.

Thanks
Title: Re: Accessing Ship Orientation
Post by: Phantom Hoover on April 15, 2015, 07:45:34 am
Having negative values in radians is perfectly normal and expected.
Title: Re: Accessing Ship Orientation
Post by: The E on April 15, 2015, 07:53:59 am
The value range for those should be -180 to 180.
Title: Re: Accessing Ship Orientation
Post by: AdmiralRalwood on April 15, 2015, 07:24:33 pm
The value range for those should be -180 to 180.
Other code heavily implies that angles.p, .b, and .h should be in radians...
Title: Re: Accessing Ship Orientation
Post by: Admiral MS on April 16, 2015, 03:41:21 am
The angles .p, .b and .h are, as far as I remember, in radians. Just be aware of the coordinate system is not exactly the same that is usually used in actual flight applications. Also don't rely too much on information about orientations in FRED or SEXPs (see http://scp.indiegames.us/mantis/view.php?id=2023).