annotate TaskManager/Test/simple_render/trash/scene_graph_update.cpp @ 217:897aeb144569

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