39
|
1 #include "scene_graph_update.h"
|
|
2
|
|
3 class SceneGraphUpdate : SpeTask {
|
|
4
|
|
5 SceneGraphUpdate() {
|
|
6 rbuf = _rbuf;
|
|
7 wbuf = _wbuf;
|
|
8 }
|
|
9
|
|
10 void
|
|
11 SceneGraphUpdate::matrix4x4(float *xyz, float *xyz1, float *xyz2) {
|
|
12 for(int t=0; t<16; t+=4) {
|
|
13 for(int i=0; i<4; i++) {
|
|
14 xyz[t+i] = xyz1[t]*xyz2[i] + xyz1[t+1]*xyz2[4+i] + xyz1[t+2]*xyz2[8+i]+ xyz1[t+3]*xyz2[12+i];
|
|
15 }
|
|
16 }
|
|
17 }
|
|
18
|
|
19 void
|
|
20 SceneGraphUpdate::get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) {
|
|
21 float radx,rady,radz;
|
|
22 radx = rxyz[0]*3.14/180;
|
|
23 rady = rxyz[1]*3.14/180;
|
|
24 radz = rxyz[2]*3.14/180;
|
|
25
|
|
26 float sinx = sin(radx);
|
|
27 float cosx = cos(radx);
|
|
28 float siny = sin(rady);
|
|
29 float cosy = cos(rady);
|
|
30 float sinz = sin(radz);
|
|
31 float cosz = cos(radz);
|
|
32
|
|
33 matrix[0] = cosz*cosy+sinz*sinx*siny;
|
|
34 matrix[1] =sinz*cosx;
|
|
35 matrix[2] = -cosz*siny+sinz*sinx*cosy;
|
|
36 matrix[3] = 0;
|
|
37 matrix[4] = -sinz*cosy+cosz*sinx*siny;
|
|
38 matrix[5] = cosz*cosx;
|
|
39 matrix[6] = sinz*siny+cosz*sinx*cosy;
|
|
40 matrix[7] = 0;
|
|
41 matrix[8] = cosx*siny;
|
|
42 matrix[9] = -sinx;
|
|
43 matrix[10] = cosx*cosy;
|
|
44 matrix[11] = 0;
|
|
45 matrix[12] = txyz[0];
|
|
46 matrix[13] = txyz[1];
|
|
47 matrix[14] = txyz[2];
|
|
48 matrix[15] = 1;
|
|
49
|
|
50 float m[16];
|
|
51 for(int i=0; i<16; i++) {
|
|
52 m[i] = matrix[i];
|
|
53 }
|
|
54
|
|
55 if(stack) {
|
|
56 matrix4x4(matrix, m, stack);
|
|
57 }
|
|
58 }
|
|
59
|
|
60
|
|
61 int
|
|
62 SceneGraphUpdate::run() {
|
|
63 SceneGraphPack *sgp = (SceneGraphPack*)rbuf;
|
|
64 for (int i = 0; i < sgp->size; i++) {
|
|
65 //SceneGraphNode *node = sgp->node[i];
|
|
66 (*my_func[sgp->node[i].move])(node);
|
|
67 (*my_func[sgp->node[i].interaction])(sgp->node[i], sgp);
|
|
68 if(sgp->node[i].pn != -1) {
|
|
69 get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, sgp->node[sgp->node[i].pn].translation);
|
|
70 }
|
|
71 else {
|
|
72 get_matrix(sgp->node[i].translation, sgp->node[i].angle, sgp->node[i].obj_pos, NULL);
|
|
73 }
|
|
74
|
|
75 copy(sgp->node, wbuf, sgp->node->size());
|
|
76 }
|
|
77 }
|
|
78
|
|
79
|
|
80 void
|
|
81 Boss::move(SceneGraphNode *node) {
|
|
82 x = x+1;
|
|
83 }
|
|
84
|
|
85
|
|
86 };
|