Because AppGameKit is not particularly equipped with 3D mathematics. I have implemented a couple of functions from the c ++ library glm to AGK.
A small feature have these functions.
Functions, which have in the beginning a result parameter, return this value as well.
For Example:
Note: This example serves no purpose.
v0 as Vec3
v1 as Vec3
v3 as Vec3
...
// put some values in these vectors.
...
Vec3Mul(v0, v0, v2)
Vec3Mul(v1, v1, v2)
Vec3Normalize(v0, v0)
Vec3Normalize(v1, v1)
Vec3Mul(v2, v0, v1)
You can theoretically write instead...
v0 as Vec3
v1 as Vec3
v3 as Vec3
...
// put some values in these vectors.
...
Vec3Mul(v2, Vec3Normalize(v0, Vec3Mul(v0, v0, v2)), Vec3Normalize(v1, Vec3Mul(v1, v1, v2)))
Here is the list of functions at a glance:
Types:
Vec2
Vec3
Vec4
mat4
/ * Quat (quaternion) will follow * /
Vec2 functions:
Function Vec2Add(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2Sub(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2Mul(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2MulByValue(result Ref As Vec2, v As Vec2, value# As Float)
Function Vec2Div(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2DivByValue(result Ref As Vec2, v As Vec2, value# As Float)
Function Vec2IsEqual(v1 As Vec2, v2 As Vec2)
Function Vec2Abs(result ref As Vec2, v As Vec2)
Function Vec2Mix(result Ref As Vec2, v1 As Vec2, v2 As Vec2, s As Vec2)
Function Vec2MixByValue(result Ref As Vec2, v1 As Vec2, v2 As Vec2, s# As Float)
Function Vec2Floor(result Ref As Vec2, v As Vec2)
Function Vec2Trunc(result Ref As Vec2, v As Vec2)
Function Vec2Mod(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2ModByValue(result Ref As Vec2, v As Vec2, value# As Float)
Function Vec2Min(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2MinByValue(result Ref As Vec2, v As Vec2, value# As Float)
Function Vec2Max(result Ref As Vec2, v1 As Vec2, v2 As Vec2)
Function Vec2MaxByValue(result Ref As Vec2, v As Vec2, value# As Float)
Function Vec2Fract(result Ref As Vec2, v As Vec2)
Function Vec2Ceil(result Ref As Vec2, v As Vec2)
Function Vec2Round(result Ref As Vec2, v As Vec2)
Function Vec2Clamp(result Ref As Vec2, v As Vec2, min As Vec2, max As Vec2)
Function Vec2ClampByValue(result Ref As Vec2, v As Vec2, min# As Float, max# As Float)
Function Vec2Dot(v1 As Vec2, v2 As Vec2)
Function Vec2LengthSq(v As Vec2)
Function Vec2Length(v As Vec2)
Function Vec2DistanceSq(v1 As Vec2, v2 As Vec2)
Function Vec2Distance(v1 As Vec2, v2 As Vec2)
Function Vec2Normalize(result Ref As Vec2, v As Vec2)
Function Vec2Reflect(result Ref As Vec2, v As Vec2, n As Vec2)
Function Vec2Refract(result Ref As Vec2, v As Vec2, n As Vec2, eta# As Float)
Function Vec2Set(result As Vec4, x As Float, y As Float)
Vec3 functions:
Function Vec3Add(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3Sub(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3Mul(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3MulByValue(result Ref As Vec3, v As Vec3, value# As Float)
Function Vec3Div(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3DivByValue(result Ref As Vec3, v As Vec3, value# As Float)
Function Vec3IsEqual(v1 As Vec3, v2 As Vec3)
Function Vec3Abs(result ref As Vec3, v As Vec3)
Function Vec3Mix(result Ref As Vec3, v1 As Vec3, v2 As Vec3, s As Vec3)
Function Vec3MixByValue(result Ref As Vec3, v1 As Vec3, v2 As Vec3, s# As Float)
Function Vec3Floor(result Ref As Vec3, v As Vec3)
Function Vec3Trunc(result Ref As Vec3, v As Vec3)
Function Vec3Mod(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3ModByValue(result Ref As Vec3, v As Vec3, value# As Float)
Function Vec3Min(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3MinByValue(result Ref As Vec3, v As Vec3, value# As Float)
Function Vec3Max(result Ref As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3MaxByValue(result Ref As Vec3, v As Vec3, value# As Float)
Function Vec3Fract(result Ref As Vec3, v As Vec3)
Function Vec3Ceil(result Ref As Vec3, v As Vec3)
Function Vec3Round(result Ref As Vec3, v As Vec3)
Function Vec3Clamp(result Ref As Vec3, v As Vec3, min As Vec3, max As Vec3)
Function Vec3ClampByValue(result Ref As Vec3, v As Vec3, min# As Float, max# As Float)
Function Vec3Dot(v1 As Vec3, v2 As Vec3)
Function Vec3Cross(result As Vec3, v1 As Vec3, v2 As Vec3)
Function Vec3LengthSq(v As Vec3)
Function Vec3Length(v As Vec3)
Function Vec3DistanceSq(v1 As Vec3, v2 As Vec3)
Function Vec3Distance(v1 As Vec3, v2 As Vec3)
Function Vec3Normalize(result Ref As Vec3, v As Vec3)
Function Vec3Reflect(result Ref As Vec3, v As Vec3, n As Vec3)
Function Vec3Refract(result Ref As Vec3, v As Vec3, n As Vec3, eta# As Float)
Function Vec3Set(result As Vec4, x As Float, y As Float, z As Float)
Vec4 functions:
Function Vec4Add(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4Sub(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4Mul(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4MulByValue(result Ref As Vec4, v As Vec4, value# As Float)
Function Vec4Div(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4DivByValue(result Ref As Vec4, v As Vec4, value# As Float)
Function Vec4IsEqual(v1 As Vec4, v2 As Vec4)
Function Vec4Abs(result ref As Vec4, v As Vec4)
Function Vec4Mix(result Ref As Vec4, v1 As Vec4, v2 As Vec4, s As Vec4)
Function Vec4MixByValue(result Ref As Vec4, v1 As Vec4, v2 As Vec4, s# As Float)
Function Vec4Floor(result Ref As Vec4, v As Vec4)
Function Vec4Trunc(result Ref As Vec4, v As Vec4)
Function Vec4Mod(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4ModByValue(result Ref As Vec4, v As Vec4, value# As Float)
Function Vec4Min(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4MinByValue(result Ref As Vec4, v As Vec4, value# As Float)
Function Vec4Max(result Ref As Vec4, v1 As Vec4, v2 As Vec4)
Function Vec4MaxByValue(result Ref As Vec4, v As Vec4, value# As Float)
Function Vec4Fract(result Ref As Vec4, v As Vec4)
Function Vec4Ceil(result Ref As Vec4, v As Vec4)
Function Vec4Round(result Ref As Vec4, v As Vec4)
Function Vec4Clamp(result Ref As Vec4, v As Vec4, min As Vec4, max As Vec4)
Function Vec4ClampByValue(result Ref As Vec4, v As Vec4, min# As Float, max# As Float)
Function Vec4Dot(v1 As Vec4, v2 As Vec4)
Function Vec4LengthSq(v As Vec4)
Function Vec4Length(v As Vec4)
Function Vec4DistanceSq(v1 As Vec4, v2 As Vec4)
Function Vec4Distance(v1 As Vec4, v2 As Vec4)
Function Vec4Normalize(result Ref As Vec4, v As Vec4)
Function Vec4Reflect(result Ref As Vec4, v As Vec4, n As Vec4)
Function Vec4Refract(result Ref As Vec4, v As Vec4, n As Vec4, eta# As Float)
Function Vec4Set(result As Vec4, x As Float, y As Float, z As Float, w As Float)
Mat4 functions:
Function Mat4Identity(result ref As Mat4)
Function Mat4SetDiagonal(result ref As Mat4, value# As Float)
Function Mat4Frustum(result ref As Mat4, l# As Float, r# As Float, t# as Float, b# As Float, n# As Float, f# As Float)
Function Mat4InfinitePerspective(result ref As Mat4, fov# As Float, aspect# As Float, near# As Float)
Function Mat4LookAt(result ref As Mat4, eye As Vec3, position As Vec3, up As Vec3)
Function Mat4Ortho(result ref As Mat4, l As Float, r As Float, t As Float, b As Float, n As Float, f As Float)
Function Mat4Perspective(result ref As Mat4, fov As Float, aspect As Float, near As Float, far As Float)
Function Mat4Rotate(result ref As Mat4, m As Mat4, angle As Float, v As Vec3)
Function Mat4Scale(result ref As Mat4, m As Mat4, scale As Vec3)
Function Mat4Translate(result ref As Mat4, m As Mat4, v As Vec3)
Function Mat4GetColumn(result ref As Vec4, m As Mat4, Column As Integer)
Function Mat4SetColumn(result ref As Mat4, v As Vec4, Column As Integer)
Function Mat4GetRow(result ref As Vec4, m As Mat4, Row As Integer)
Function Mat4SetRow(result ref As Mat4, v As Vec4, Row As Integer)
If you miss some important functions then say it me.
Have fun and comments are welcome.
MadBit.