summaryrefslogtreecommitdiff
path: root/src/extend/transform.c
blob: 6979e409ed5f85b9622284d5fb39d490ef093685 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#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);
	}
}

void transform_localtoworlddir(Transform* trans, Vec3* dir, Vec3* out) {
//RrRs
	

}