From b656c9415a8e7e3b5b7d8bf1f3c8a5444f830c79 Mon Sep 17 00:00:00 2001 From: chai Date: Sat, 22 Feb 2020 23:33:06 +0800 Subject: *misc --- src/extend/transform.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'src/extend/transform.c') diff --git a/src/extend/transform.c b/src/extend/transform.c index e69de29..7724614 100644 --- a/src/extend/transform.c +++ b/src/extend/transform.c @@ -0,0 +1,37 @@ +#include "transform.h" + +void transform_getpositionandrotation(Transform* trans, Vec3* pos, Quat* rot) { + *pos = trans->localposition; + *rot = trans->localrotation; + Transform* cur = trans->parent; + while (cur) { + /*按照srt的顺序计算pos*/ + vec3_scale3(pos, &cur->localscale, pos); + quat_applytovec3(&cur->localrotation, pos, pos); + vec3_plus(pos, &cur->localposition, pos); + /*计算旋转*/ + quat_multiply(&cur->localrotation, rot, rot); + + cur = cur->parent; + } +} + +void transform_getinvmatrixnoscale(Transform* trans, Mat4* worldToLocal) { + Vec3 pos; Quat rot; + transform_getpositionandrotation(trans, &pos, &rot); + quat_invert(&rot, &rot); + /*(TR)^-1 = R^-1T^-1*/ + quat_tomat4(&rot, worldToLocal); + vec3_scale(&pos, -1, &pos); + mat4_translate(worldToLocal, &pos, worldToLocal); +} + +void transform_getrotation(Transform* trans, Quat* rot) { + *rot = trans->localrotation; + Transform* cur = trans->parent; + while (cur) { + quat_multiply(&cur->localrotation, rot, rot); + } +} + + -- cgit v1.1-26-g67d0