Author Topic: Accessing Ship Orientation  (Read 5438 times)

0 Members and 1 Guest are viewing this topic.

Accessing Ship Orientation
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
« Last Edit: April 14, 2015, 08:25:30 pm by lukeopai »

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Accessing Euler Angles - roll, pitch, yaw
If there is, it's probably in the Lua scripting, and if there's not, that's probably where it should go.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Accessing Euler Angles - roll, pitch, yaw
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".
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Accessing Euler Angles - roll, pitch, yaw
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!


 
Re: Accessing Euler Angles - roll, pitch, yaw
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!

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Accessing Euler Angles - roll, pitch, yaw
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
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Accessing Euler Angles - roll, pitch, yaw
Excellent suggestion.  Thanks!

 
Re: Accessing Euler Angles - roll, pitch, yaw
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.

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Accessing Euler Angles - roll, pitch, yaw
Then you do need to run code every frame, and use mn.Missiontime to read the current timestamp.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: Accessing Euler Angles - roll, pitch, yaw
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

 

Offline m!m

  • 211
Re: Accessing Euler Angles - roll, pitch, yaw
You could try LuaSockets but I am not sure if FSO properly handles loading external DLLs.

 
Re: Accessing Ship Orientation

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

 
Re: Accessing Ship Orientation
Having negative values in radians is perfectly normal and expected.
The good Christian should beware of mathematicians, and all those who make empty prophecies. The danger already exists that the mathematicians have made a covenant with the devil to darken the spirit and to confine man in the bonds of Hell.

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Accessing Ship Orientation
The value range for those should be -180 to 180.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline AdmiralRalwood

  • 211
  • The Cthulhu programmer himself!
    • Skype
    • Steam
    • Twitter
Re: Accessing Ship Orientation
The value range for those should be -180 to 180.
Other code heavily implies that angles.p, .b, and .h should be in radians...
Ph'nglui mglw'nafh Codethulhu GitHub wgah'nagl fhtagn.

schrödinbug (noun) - a bug that manifests itself in running software after a programmer notices that the code should never have worked in the first place.

When you gaze long into BMPMAN, BMPMAN also gazes into you.

"I am one of the best FREDders on Earth" -General Battuta

<Aesaar> literary criticism is vladimir putin

<MageKing17> "There's probably a reason the code is the way it is" is a very dangerous line of thought. :P
<MageKing17> Because the "reason" often turns out to be "nobody noticed it was wrong".
(the very next day)
<MageKing17> this ****ing code did it to me again
<MageKing17> "That doesn't really make sense to me, but I'll assume it was being done for a reason."
<MageKing17> **** ME
<MageKing17> THE REASON IS PEOPLE ARE STUPID
<MageKing17> ESPECIALLY ME

<MageKing17> God damn, I do not understand how this is breaking.
<MageKing17> Everything points to "this should work fine", and yet it's clearly not working.
<MjnMixael> 2 hours later... "God damn, how did this ever work at all?!"
(...)
<MageKing17> so
<MageKing17> more than two hours
<MageKing17> but once again we have reached the inevitable conclusion
<MageKing17> How did this code ever work in the first place!?

<@The_E> Welcome to OpenGL, where standards compliance is optional, and error reporting inconsistent

<MageKing17> It was all working perfectly until I actually tried it on an actual mission.

<IronWorks> I am useful for FSO stuff again. This is a red-letter day!
* z64555 erases "Thursday" and rewrites it in red ink

<MageKing17> TIL the entire homing code is held up by shoestrings and duct tape, basically.

 
Re: Accessing Ship Orientation
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).
Here goes scripting and copy paste coding
Freespace RTS Mod
Checkpoint/Shipsaveload script