summaryrefslogtreecommitdiff
path: root/api/rs_matrix.spec
diff options
context:
space:
mode:
Diffstat (limited to 'api/rs_matrix.spec')
-rw-r--r--api/rs_matrix.spec105
1 files changed, 105 insertions, 0 deletions
diff --git a/api/rs_matrix.spec b/api/rs_matrix.spec
index 7afbefff..d69ad1ab 100644
--- a/api/rs_matrix.spec
+++ b/api/rs_matrix.spec
@@ -41,6 +41,111 @@ description:
transformation happens first. E.g. if you call @rsMatrixTranslate()
on a matrix that already does a scaling, the resulting matrix when applied
to a vector will first do the translation then the scaling.
+include:
+ #include "rs_vector_math.rsh"
+end:
+
+function: rsExtractFrustumPlanes
+# TODO Why always_inline?
+attrib: always_inline
+ret: void
+arg: const rs_matrix4x4* viewProj, "matrix to extract planes from"
+arg: float4* left, "left plane"
+arg: float4* right, "right plane"
+arg: float4* top, "top plane"
+arg: float4* bottom, "bottom plane"
+arg: float4* near, "near plane"
+arg: float4* far, "far plane"
+summary:
+description:
+ Computes 6 frustum planes from the view projection matrix
+inline:
+ // x y z w = a b c d in the plane equation
+ left->x = viewProj->m[3] + viewProj->m[0];
+ left->y = viewProj->m[7] + viewProj->m[4];
+ left->z = viewProj->m[11] + viewProj->m[8];
+ left->w = viewProj->m[15] + viewProj->m[12];
+
+ right->x = viewProj->m[3] - viewProj->m[0];
+ right->y = viewProj->m[7] - viewProj->m[4];
+ right->z = viewProj->m[11] - viewProj->m[8];
+ right->w = viewProj->m[15] - viewProj->m[12];
+
+ top->x = viewProj->m[3] - viewProj->m[1];
+ top->y = viewProj->m[7] - viewProj->m[5];
+ top->z = viewProj->m[11] - viewProj->m[9];
+ top->w = viewProj->m[15] - viewProj->m[13];
+
+ bottom->x = viewProj->m[3] + viewProj->m[1];
+ bottom->y = viewProj->m[7] + viewProj->m[5];
+ bottom->z = viewProj->m[11] + viewProj->m[9];
+ bottom->w = viewProj->m[15] + viewProj->m[13];
+
+ near->x = viewProj->m[3] + viewProj->m[2];
+ near->y = viewProj->m[7] + viewProj->m[6];
+ near->z = viewProj->m[11] + viewProj->m[10];
+ near->w = viewProj->m[15] + viewProj->m[14];
+
+ far->x = viewProj->m[3] - viewProj->m[2];
+ far->y = viewProj->m[7] - viewProj->m[6];
+ far->z = viewProj->m[11] - viewProj->m[10];
+ far->w = viewProj->m[15] - viewProj->m[14];
+
+ float len = length(left->xyz);
+ *left /= len;
+ len = length(right->xyz);
+ *right /= len;
+ len = length(top->xyz);
+ *top /= len;
+ len = length(bottom->xyz);
+ *bottom /= len;
+ len = length(near->xyz);
+ *near /= len;
+ len = length(far->xyz);
+ *far /= len;
+test: none
+end:
+
+function: rsIsSphereInFrustum
+attrib: always_inline
+ret: bool
+arg: float4* sphere, "float4 representing the sphere"
+arg: float4* left, "left plane"
+arg: float4* right, "right plane"
+arg: float4* top, "top plane"
+arg: float4* bottom, "bottom plane"
+arg: float4* near, "near plane"
+arg: float4* far, "far plane"
+summary:
+description:
+ Checks if a sphere is withing the 6 frustum planes
+inline:
+ float distToCenter = dot(left->xyz, sphere->xyz) + left->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(right->xyz, sphere->xyz) + right->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(top->xyz, sphere->xyz) + top->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(bottom->xyz, sphere->xyz) + bottom->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(near->xyz, sphere->xyz) + near->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ distToCenter = dot(far->xyz, sphere->xyz) + far->w;
+ if (distToCenter < -sphere->w) {
+ return false;
+ }
+ return true;
+test: none
end:
function: rsMatrixGet