Skip to content

Commit

Permalink
update ak_transformCombine to use transform instead of node to make i…
Browse files Browse the repository at this point in the history
…t more generic
  • Loading branch information
recp committed Oct 21, 2023
1 parent 55b6651 commit 36d2025
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 25 deletions.
8 changes: 4 additions & 4 deletions include/ak/transform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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**
Expand Down
2 changes: 1 addition & 1 deletion src/bbox/scene.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
36 changes: 18 additions & 18 deletions src/transform/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand All @@ -94,50 +94,50 @@ 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;
}
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);
break;
}
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);
break;
}
case AKT_SKEW: {
AkSkew *skew;
skew = ak_objGet(transform);
skew = ak_objGet(transformItem);

ak_transformSkewMatrix(skew, tmp[0]);
glm_mat4_mul(mat, tmp, mat);
break;
}
}

transform = transform->next;
transformItem = transformItem->next;
}

if (transformGroup != node->transform->item) {
transformGroup = node->transform->item;
if (transformGroup != transform->item) {
transformGroup = transform->item;
goto again;
}

Expand Down
4 changes: 2 additions & 2 deletions src/transform/traverse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 36d2025

Please sign in to comment.