- Joined
- Jan 9, 2019
- Messages
- 102
JASS:
library RPEV requires RelativePlane
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
// ___________
// # RPEV ________________________
// (RelativePlaneElevatedVector)
// v1.0a, by Overfrost
//
// - implements VectorBase as vector of linked RelativePlane
// in (s,t,z) environment (e.g. (x,y) + (z) format)
//
// - y-axis points to the floor of linked plane's target
// therefore disregarding any z difference (no inclination)
//
// - z-axis always points upwards
//
// - elevation follows the formula (e = plane.slope * y)
//
// ______________
// # Requires:
//
// - RelativePlane
// hiveworkshop.com/threads/relativeplane.311626/
//
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
//! novjass
//
struct RPEV extends array
implement VectorExt
//-------------
// Instancers
//
static method create takes RelativePlane p returns thistype
// creates an instance linked to RelativePlane p and locks p once
//
method lock takes nothing returns nothing
method unlock takes nothing returns boolean
// unlock replaces destroy, returns true if it destroys
// unlocks linked plane on destroy
//
//---------
// Fields
//
real x
real y
real z
// from VectorExt, along with many others
//
RelativePlane plane
// when its instance changes, properly unlock the previous instance
// automatically locks the new instance once
//
readonly real fx
readonly real fy
readonly real fz // without elevation
// returns the non-relative coordinates of the vector
//
readonly real fe // elevation
readonly real ez // = fz + fe
//
//----------
// Methods
//
method refresh takes nothing returns thistype
// refreshes the plane, = plane.refresh()
// only needs to be called if the plane has possible changes
// automatically called on instance creation
// returns this (this instance)
//
//! endnovjass
//-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ----
//
struct RPEV extends array
implement AllocFast
//
implement VectorExt
//
private integer l
//
private RelativePlane o
//
method refresh takes nothing returns thistype
call o.refresh()
//
return this
endmethod
static method create takes RelativePlane ao returns thistype
local thistype this = allocate()
set l = 0
//
set x = 0
set y = 0
set z = 0
//
set o = ao
call ao.lock()
//
return refresh()
endmethod
//
method operator fx takes nothing returns real
return o.origin.tx + s*Cos(o.angle + t - 1.5707963)
endmethod
method operator fy takes nothing returns real
return o.origin.ty + s*Sin(o.angle + t - 1.5707963)
endmethod
method operator fz takes nothing returns real
return o.origin.tz + z
endmethod
//
method operator fe takes nothing returns real
return o.slope*y
endmethod
method operator ez takes nothing returns real
return fz + fe
endmethod
//
method operator plane takes nothing returns RelativePlane
return o
endmethod
method operator plane= takes RelativePlane ao returns nothing
call o.unlock()
//
set o = ao
call ao.lock()
endmethod
//
method lock takes nothing returns nothing
set l = l + 1
endmethod
method unlock takes nothing returns boolean
set l = l - 1
if (l < 0) then
//
call o.unlock()
//
call deallocate()
return true
endif
return false
endmethod
endstruct
endlibrary
No longer updated. Only serves as a reference.
Last edited: