diff --git a/include/ak/transform.h b/include/ak/transform.h index e12bf188..0d723737 100644 --- a/include/ak/transform.h +++ b/include/ak/transform.h @@ -81,13 +81,13 @@ ak_transformSkewMatrix(AkSkew * __restrict skew, * * if there is no transform then this returns identity matrix * - * @param node node - * @param matrix combined transform (must be aligned 16) + * @param transform transform + * @param matrix combined transform (must be aligned 16) */ AK_EXPORT void -ak_transformCombine(AkNode * __restrict node, - float * matrix); +ak_transformCombine(AkTransform * __restrict transform, + float * __restrict matrix); /*! * @brief combines all node's transform elements in **world coord sys** diff --git a/src/bbox/scene.c b/src/bbox/scene.c index e56f3ebd..302d44d6 100644 --- a/src/bbox/scene.c +++ b/src/bbox/scene.c @@ -45,7 +45,7 @@ ak_bbox_node(AkHeap * __restrict heap, matrixWorld = node->matrixWorld->val; - ak_transformCombine(node, node->matrix->val[0]); + ak_transformCombine(node->transform, node->matrix->val[0]); glm_mat4_mul(parentTrans, node->matrix->val, matrixWorld); if (node->geometry) { diff --git a/src/common.h b/src/common.h index ba732a58..4993faf0 100644 --- a/src/common.h +++ b/src/common.h @@ -24,6 +24,7 @@ #include "../include/ak/map.h" #include "../include/ak/type.h" #include "../include/ak/url.h" +#include "../include/ak/transform.h" #include "mem/common.h" diff --git a/src/transform/trans.c b/src/transform/trans.c index 5300e251..60e4371c 100644 --- a/src/transform/trans.c +++ b/src/transform/trans.c @@ -55,31 +55,31 @@ ak_transformSkewMatrix(AkSkew * __restrict skew, AK_EXPORT void -ak_transformCombine(AkNode * __restrict node, - float * matrix) { - AkObject *transform, *transformGroup; +ak_transformCombine(AkTransform * __restrict transform, + float * __restrict matrix) { + AkObject *transformItem, *transformGroup; mat4 mat = GLM_MAT4_IDENTITY_INIT; mat4 tmp; - if (!node->transform) + if (!transform || !matrix) goto ret; - transformGroup = node->transform->base; + transformGroup = transform->base; again: - transform = transformGroup; - while (transform) { - switch (transform->type) { + transformItem = transformGroup; + while (transformItem) { + switch (transformItem->type) { case AKT_MATRIX: { AkMatrix *matrix; - matrix = ak_objGet(transform); + matrix = ak_objGet(transformItem); glm_mat4_mul(mat, matrix->val, mat); break; } case AKT_LOOKAT: { AkLookAt *lookAt; - lookAt = ak_objGet(transform); + lookAt = ak_objGet(transformItem); glm_lookat(lookAt->val[0], lookAt->val[1], @@ -94,7 +94,7 @@ ak_transformCombine(AkNode * __restrict node, case AKT_ROTATE: { AkRotate *rotate; - rotate = ak_objGet(transform); + rotate = ak_objGet(transformItem); glm_rotate_make(tmp, rotate->val[3], rotate->val); glm_mat4_mul(mat, tmp, mat); break; @@ -102,14 +102,14 @@ ak_transformCombine(AkNode * __restrict node, case AKT_QUATERNION: { AkQuaternion *quat; - quat = ak_objGet(transform); + quat = ak_objGet(transformItem); glm_quat_mat4(quat->val, tmp); glm_mat4_mul(mat, tmp, mat); break; } case AKT_SCALE: { AkScale *scale; - scale = ak_objGet(transform); + scale = ak_objGet(transformItem); glm_scale_make(tmp, scale->val); glm_mat4_mul(mat, tmp, mat); @@ -117,7 +117,7 @@ ak_transformCombine(AkNode * __restrict node, } case AKT_TRANSLATE: { AkTranslate *translate; - translate = ak_objGet(transform); + translate = ak_objGet(transformItem); glm_translate_make(tmp, translate->val); glm_mat4_mul(mat, tmp, mat); @@ -125,7 +125,7 @@ ak_transformCombine(AkNode * __restrict node, } case AKT_SKEW: { AkSkew *skew; - skew = ak_objGet(transform); + skew = ak_objGet(transformItem); ak_transformSkewMatrix(skew, tmp[0]); glm_mat4_mul(mat, tmp, mat); @@ -133,11 +133,11 @@ ak_transformCombine(AkNode * __restrict node, } } - transform = transform->next; + transformItem = transformItem->next; } - if (transformGroup != node->transform->item) { - transformGroup = node->transform->item; + if (transformGroup != transform->item) { + transformGroup = transform->item; goto again; } diff --git a/src/transform/traverse.c b/src/transform/traverse.c index 79996037..5a542557 100644 --- a/src/transform/traverse.c +++ b/src/transform/traverse.c @@ -25,11 +25,11 @@ ak_transformCombineWorld(AkNode * __restrict node, mat4 mat; mat4 ptrans; - ak_transformCombine(node, mat[0]); + ak_transformCombine(node->transform, mat[0]); parentNode = node->parent; while (parentNode) { - ak_transformCombine(parentNode, ptrans[0]); + ak_transformCombine(parentNode->transform, ptrans[0]); glm_mat4_mul(ptrans, mat, mat); parentNode = parentNode->parent;