From 623141f339d5066ed6b96ad70ab45fb294e3e612 Mon Sep 17 00:00:00 2001 From: Brecht Van Lommel Date: Thu, 8 Mar 2018 06:19:17 +0100 Subject: Code refactor: add DecomposedTransform. This is in preparation of making Transform affine only, and also gives us a little extra type safety so we don't accidentally treat it as a regular 4x4 matrix. --- intern/cycles/util/util_projection.h | 2 +- intern/cycles/util/util_transform.cpp | 4 ++-- intern/cycles/util/util_transform.h | 35 +++++++++++++++++++++++++---------- 3 files changed, 28 insertions(+), 13 deletions(-) (limited to 'intern/cycles/util') diff --git a/intern/cycles/util/util_projection.h b/intern/cycles/util/util_projection.h index 0b8ff032120..8073568046d 100644 --- a/intern/cycles/util/util_projection.h +++ b/intern/cycles/util/util_projection.h @@ -21,7 +21,7 @@ CCL_NAMESPACE_BEGIN -/* Data Types */ +/* 4x4 projection matrix, perspective or orthographic. */ typedef struct ProjectionTransform { float4 x, y, z, w; /* rows */ diff --git a/intern/cycles/util/util_transform.cpp b/intern/cycles/util/util_transform.cpp index c1270545339..edb53cc06b7 100644 --- a/intern/cycles/util/util_transform.cpp +++ b/intern/cycles/util/util_transform.cpp @@ -202,7 +202,7 @@ float4 transform_to_quat(const Transform& tfm) return qt; } -static void transform_decompose(Transform *decomp, const Transform *tfm) +static void transform_decompose(DecomposedTransform *decomp, const Transform *tfm) { /* extract translation */ decomp->y = make_float4(tfm->x.w, tfm->y.w, tfm->z.w, 0.0f); @@ -247,7 +247,7 @@ static void transform_decompose(Transform *decomp, const Transform *tfm) decomp->w = make_float4(scale.y.z, scale.z.x, scale.z.y, scale.z.z); } -void transform_motion_decompose(MotionTransform *decomp, const MotionTransform *motion, const Transform *mid) +void transform_motion_decompose(DecomposedMotionTransform *decomp, const MotionTransform *motion, const Transform *mid) { transform_decompose(&decomp->pre, &motion->pre); transform_decompose(&decomp->mid, mid); diff --git a/intern/cycles/util/util_transform.h b/intern/cycles/util/util_transform.h index 52022292d0b..65166e325e8 100644 --- a/intern/cycles/util/util_transform.h +++ b/intern/cycles/util/util_transform.h @@ -37,16 +37,26 @@ typedef struct Transform { #endif } Transform; -/* transform decomposed in rotation/translation/scale. we use the same data - * structure as Transform, and tightly pack decomposition into it. first the - * rotation (4), then translation (3), then 3x3 scale matrix (9). */ - typedef struct ccl_may_alias MotionTransform { Transform pre; Transform mid; Transform post; } MotionTransform; +/* Transform decomposed in rotation/translation/scale. we use the same data + * structure as Transform, and tightly pack decomposition into it. first the + * rotation (4), then translation (3), then 3x3 scale matrix (9). */ + +typedef struct DecomposedTransform { + float4 x, y, z, w; +} DecomposedTransform; + +typedef struct ccl_may_alias DecomposedMotionTransform { + DecomposedTransform pre; + DecomposedTransform mid; + DecomposedTransform post; +} DecomposedMotionTransform; + /* Functions */ ccl_device_inline float3 transform_point(const Transform *t, const float3 a) @@ -384,7 +394,7 @@ ccl_device_inline Transform transform_quick_inverse(Transform M) return R; } -ccl_device_inline void transform_compose(Transform *tfm, const Transform *decomp) +ccl_device_inline void transform_compose(Transform *tfm, const DecomposedTransform *decomp) { /* rotation */ float q0, q1, q2, q3, qda, qdb, qdc, qaa, qab, qac, qbb, qbc, qcc; @@ -420,9 +430,9 @@ ccl_device_inline void transform_compose(Transform *tfm, const Transform *decomp tfm->w = make_float4(0.0f, 0.0f, 0.0f, 1.0f); } -ccl_device void transform_motion_interpolate(Transform *tfm, const ccl_global MotionTransform *motion, float t) +ccl_device void transform_motion_interpolate(Transform *tfm, const ccl_global DecomposedMotionTransform *motion, float t) { - Transform decomp; + DecomposedTransform decomp; /* linear interpolation for rotation and scale */ if(t < 0.5f) { @@ -446,12 +456,12 @@ ccl_device void transform_motion_interpolate(Transform *tfm, const ccl_global Mo transform_compose(tfm, &decomp); } -ccl_device void transform_motion_interpolate_constant(Transform *tfm, ccl_constant MotionTransform *motion, float t) +ccl_device void transform_motion_interpolate_constant(Transform *tfm, ccl_constant DecomposedMotionTransform *motion, float t) { /* possible optimization: is it worth it adding a check to skip scaling? * it's probably quite uncommon to have scaling objects. or can we skip * just shearing perhaps? */ - Transform decomp; + DecomposedTransform decomp; /* linear interpolation for rotation and scale */ if(t < 0.5f) { @@ -479,13 +489,18 @@ ccl_device void transform_motion_interpolate_constant(Transform *tfm, ccl_consta class BoundBox2D; +ccl_device_inline bool operator==(const DecomposedTransform& A, const DecomposedTransform& B) +{ + return memcmp(&A, &B, sizeof(DecomposedTransform)) == 0; +} + ccl_device_inline bool operator==(const MotionTransform& A, const MotionTransform& B) { return (A.pre == B.pre && A.post == B.post); } float4 transform_to_quat(const Transform& tfm); -void transform_motion_decompose(MotionTransform *decomp, const MotionTransform *motion, const Transform *mid); +void transform_motion_decompose(DecomposedMotionTransform *decomp, const MotionTransform *motion, const Transform *mid); Transform transform_from_viewplane(BoundBox2D& viewplane); #endif -- cgit v1.2.3