Hi.
Long, long ago, SkyRanger-1 gave me the code to position objects based on the position/angles of an ‘anchor’ reference. (see at the bottom)
I’ve been using that code A LOT. It is the heart of my “http://www.nexusmods.com/oblivion/mods/29649/?”, where everything on the ship follows the rocking motion I apply to the hulk
Everything works fine because I know, in advance, the relative positions of the references when the anchor is at angles 0,0,0.
In other words, from the relative positions at angles 0,0,0, the code calculates the new relative positions and angles of all objects when the hulk is rotated/tilted.
Now, I want to rock the player and other actors along.
Problem is that they move around, as opposed to the mast and crates, which always are in the same place, relative to the hulk.
I figure that if I can calculate the relative position of the player on the tilted ship, I can recalculate it as I rock the ship.
In other words, I need to create a function that does exactly the reverse of what SkyRanger-1’s math does. If I feed this math with distances X1,Y1,Z1, it returns X2,Y2,Z2. Now I need a math to return the original X1,Y1,Z1 when fed values X2,Y2,Z2.
Does anyone have any tips on how I may do that? Some links to math sites/classes, perhaps?
I would appreciate any pointers you could give me.
scn zuCalcRelativePos
;---------------------------------------
;
;---------------------------------------
array_var oPos
float angXanchor
float angYanchor
float angZanchor
float dposX
float dposY
float dposZ
float posX
float posXanchor
float posY
float posYanchor
float posZ
float posZanchor
Float xtox
Float xtox2
Float xtoy
Float xtoy2
Float xtoz
Float xtoz2
Float ytox
Float ytox2
Float ytoy
Float ytoy2
Float ytoz
Float ytoz2
Float ztox
Float ztox2
Float ztoy
Float ztoy2
Float ztoz
Float ztoz2
begin Function { angXanchor angYanchor angZanchor dposX dposY dposZ }
let posXanchor := 0
let posYanchor := 0
let posZanchor := 0
;============================================================
; Modder's resource code by SkyRanger-1
;============================================================
; APPLY Z angle (simplified/optimized slightly since we know where the zeroes and ones were)
Set xtox to cos angZanchor
Set xtoy to -1 * sin angZanchor
Set xtoz to 0
Set ytox to sin angZanchor
Set ytoy to cos angZanchor
Set ytoz to 0
Set ztox to 0
Set ztoy to 0
Set ztoz to 1
; APPLY Y angle (not simplified/optimized, even though we know where a few zeros and ones were)
Set xtox2 to ( xtox * COS angYanchor ) + ( -1 * xtoz * SIN angYanchor )
Set xtoy2 to xtoy
Set xtoz2 to ( 1 * xtox * SIN angYanchor ) + ( xtoz * COS angYanchor )
Set ytox2 to ( ytox * COS angYanchor ) + ( -1 * ytoz * SIN angYanchor )
Set ytoy2 to ytoy
Set ytoz2 to ( 1 * ytox * SIN angYanchor ) + ( ytoz * COS angYanchor )
Set ztox2 to ( ztox * COS angYanchor ) + ( -1 * ztoz * SIN angYanchor )
Set ztoy2 to ztoy
Set ztoz2 to ( 1 * ztox * SIN angYanchor ) + ( ztoz * COS angYanchor )
; APPLY X angle (cannot be simplified/optimized)
Set xtox to xtox2
Set xtoy to ( xtoy2 * COS angXanchor ) + ( xtoz2 * SIN angXanchor )
Set xtoz to ( -1 * xtoy2 * SIN angXanchor ) + ( 1 * xtoz2 * COS angXanchor )
Set ytox to ytox2
Set ytoy to ( ytoy2 * COS angXanchor ) + ( ytoz2 * SIN angXanchor )
Set ytoz to ( -1 * ytoy2 * SIN angXanchor ) + ( 1 * ytoz2 * COS angXanchor )
Set ztox to ztox2
Set ztoy to ( ztoy2 * COS angXanchor ) + ( ztoz2 * SIN angXanchor )
Set ztoz to ( -1 * ztoy2 * SIN angXanchor ) + ( 1 * ztoz2 * COS angXanchor )
; NEW COORDINATES AFTER ROTATION
Set posX to posXanchor + dposX * xtox + dposY * ytox + dposZ * ztox
Set posY to posYanchor + dposX * xtoy + dposY * ytoy + dposZ * ztoy
Set posZ to posZanchor + dposX * xtoz + dposY * ytoz + dposZ * ztoz
let oPos := ar_construct stringmap
let oPos[zdposX] := posX
let oPos[zdposY] := posY
let oPos[zdposZ] := posZ
SetFunctionValue oPos
End