I really hope these aren't coded in the engine. If not, some functions that focus on 3D vectors and associated functions.
// --------------------------------------------------------------
//
// Vector functions
//
// --------------------------------------------------------------
#constant PI 3.14159265358979
type Vector3
x as float
y as float
z as float
endtype
function VMake(x as float, y as float, z as float)
o as Vector3
o.x = x
o.y = y
o.z = z
endfunction o
function VDot(v1 as Vector3, v2 as Vector3)
endfunction v1.x * v2.x + v1.y * v2.y + v1.z * v2.z
function VCross(a as Vector3, b as Vector3)
o as Vector3
o = VMake(a.y*b.z-a.z*b.y, a.z*b.x-a.x*b.z, a.x*b.y-a.y*b.x)
endfunction o
function VNorm(v1 as Vector3)
res as Vector3
res = VDiv(v1, VMag(v1))
endfunction res
function VMult(v1 as Vector3, s as float)
o as Vector3
o.x = v1.x * s
o.y = v1.y * s
o.z = v1.z * s
endfunction o
function VDiv(v1 as Vector3, s as float)
o as Vector3
o.x = v1.x / s
o.y = v1.y / s
o.z = v1.z / s
endfunction o
function VAdd(v1 as Vector3, v2 as Vector3)
o as Vector3
o.x = v1.x + v2.x
o.y = v1.y + v2.y
o.z = v1.z + v2.z
endfunction o
function VSub(v1 as Vector3, v2 as Vector3)
o as Vector3
o.x = v1.x - v2.x
o.y = v1.y - v2.y
o.z = v1.z - v2.z
endfunction o
function VMag(v1 as Vector3)
r as float
r = Sqrt(v1.x^2 + v1.y^2 + v1.z^2)
endfunction r
function VMagSqrd(v1 as Vector3)
endfunction v1.x^2 + v1.y^2 + v1.z^2
function VDotAngle(v1 as Vector3, v2 as Vector3)
r as float
if VEqual(v1, v2) = 1
r = 500
else
r = ACos(VDot(v1,v2)/(VMag(v1)*VMag(v2)))
endif
endfunction r
//cheesy, done to allow for precision issues with floats
function VEqual(v1 as Vector3, v2 as Vector3)
vtest as Vector3
r as integer
vtest = VSub(v1, v2)
if abs(vtest.x) + abs(vtest.y) + abs(vtest.z) < 0.00000001
r = 1
else
r = 0
endif
endfunction r
// ray / sphere intersection for coded bounding spheres
function VIntersect(p as Vector3, s as Vector3, d as Vector3, r as float)
res as float
det as float
b as float
tv as Vector3
tv = VSub(p, s)
b = -1.0 * VDot(tv,d)
det = b * b - VDot(tv, tv) + r * r
if det < 0
res = -1.0
else
det = Sqrt(det)
res = b - det
endif
endfunction res
function VObjectPos(obj as integer)
o as Vector3
o.x = GetObjectX(obj)
o.y = GetObjectY(obj)
o.z = GetObjectZ(obj)
endfunction o
Type Quaternion
w as float
x as float
y as float
z as float
endtype
function GetCameraPositionV()
o as Vector3
o = VMake(GetCameraX(1), GetCameraY(1), GetCameraZ(1))
endfunction o
function SetCameraPositionV(o as Vector3)
SetCameraPosition(1, o.x, o.y, o.z)
endfunction
function GetCameraAngleV()
o as Vector3
o = VMake(GetCameraAngleX(1), GetCameraAngleY(1), GetCameraAngleZ(1))
endfunction o
function GetCameraLookVector()
o as Vector3
s as Vector3
s = GetCameraPositionV()
MoveCameraLocalZ(1,1)
o = GetCameraPositionV()
SetCameraPositionV(s)
o = VSub(o,s)
endfunction o
function Max(f1 as float, f2 as float)
res as float
res = f1
if f2 > f1
res = f2
endif
endfunction res
function Min(f1 as float, f2 as float)
res as float
res = f1
if f2 < f1
res = f2
endif
endfunction res
Born. Currently living.