Mercurial > hg > Game > Cerium
annotate TaskManager/Test/test_render/sys.cpp @ 206:f5784443dd50 draft
add Camera
author | gongo@gendarme.cr.ie.u-ryukyu.ac.jp |
---|---|
date | Thu, 29 Jan 2009 13:52:47 +0900 |
parents | be90197f90d4 |
children | c020ccff4627 |
rev | line source |
---|---|
160 | 1 #include <stdlib.h> |
109 | 2 #include <iostream> |
3 #include <math.h> | |
4 #include "sys.h" | |
5 using namespace std; | |
6 | |
7 void noMoreMemory() | |
8 { | |
9 cout << "can't allocate memory\n"; | |
10 exit(1); | |
11 } | |
12 | |
13 void matrix4x4(float *xyz, float *xyz1, float *xyz2) //xyz[16] | |
14 { | |
15 for(int t=0; t<16; t+=4) | |
16 { | |
17 for(int i=0; i<4; i++) | |
18 { | |
19 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]; | |
20 } | |
21 } | |
22 } | |
23 | |
24 void get_matrix( float *matrix, float *rxyz, float *txyz, float *stack) | |
25 { | |
26 float radx,rady,radz; | |
27 radx = rxyz[0]*3.14/180; | |
28 rady = rxyz[1]*3.14/180; | |
29 radz = rxyz[2]*3.14/180; | |
30 | |
31 float sinx = sin(radx); | |
32 float cosx = cos(radx); | |
33 float siny = sin(rady); | |
34 float cosy = cos(rady); | |
35 float sinz = sin(radz); | |
36 float cosz = cos(radz); | |
37 | |
206 | 38 /* View Transform */ |
109 | 39 matrix[0] = cosz*cosy+sinz*sinx*siny; |
174
2c7d9057dd5d
getScale()、getTapestry から、span->length に適切なテクスチャの選択に成功
gongo@localhost.localdomain
parents:
160
diff
changeset
|
40 matrix[1] = sinz*cosx; |
109 | 41 matrix[2] = -cosz*siny+sinz*sinx*cosy; |
42 matrix[3] = 0; | |
43 matrix[4] = -sinz*cosy+cosz*sinx*siny; | |
44 matrix[5] = cosz*cosx; | |
45 matrix[6] = sinz*siny+cosz*sinx*cosy; | |
46 matrix[7] = 0; | |
47 matrix[8] = cosx*siny; | |
48 matrix[9] = -sinx; | |
49 matrix[10] = cosx*cosy; | |
50 matrix[11] = 0; | |
51 matrix[12] = txyz[0]; | |
52 matrix[13] = txyz[1]; | |
53 matrix[14] = txyz[2]; | |
54 matrix[15] = 1; | |
55 | |
206 | 56 /* Perspective Transform */ |
57 #if 0 | |
58 float n = 0.0f; | |
59 float f = 1000.0f; | |
60 float a = 0.995f / (n-f); | |
61 float b = 1-((0.995*n)/(n-f)); | |
62 | |
63 matrix[0] *= a*txyz[2]+b; | |
64 matrix[5] *= a*txyz[2]+b; | |
65 #endif | |
66 | |
109 | 67 float m[16]; |
68 | |
69 for(int i=0; i<16; i++) | |
70 { | |
71 m[i] = matrix[i]; | |
72 } | |
73 | |
74 if(stack) | |
75 { | |
176 | 76 matrix4x4(matrix, m, stack); |
109 | 77 } |
78 | |
79 } | |
80 | |
81 void rotate_x(float *xyz, float r) | |
82 { | |
83 float rad = r*3.14/180; | |
84 | |
85 xyz[0] = xyz[0]; | |
86 xyz[1] = xyz[1]*cos(rad) - xyz[2]*sin(rad); | |
87 xyz[2] = xyz[1]*sin(rad) + xyz[2]*cos(rad); | |
88 } | |
89 | |
90 void rotate_y(float *xyz, float r) | |
91 { | |
92 float rad = r*3.14/180; | |
93 | |
94 xyz[0] = xyz[0]*cos(rad) + xyz[2]*sin(rad); | |
95 xyz[1] = xyz[1]; | |
96 xyz[2] = -xyz[0]*sin(rad) + xyz[2]*cos(rad); | |
97 } | |
98 | |
99 void rotate_z(float *xyz, float r) | |
100 { | |
101 float rad = r*3.14/180; | |
102 | |
103 xyz[0] = xyz[0]*cos(rad) - xyz[1]*sin(rad); | |
104 xyz[1] = xyz[0]*sin(rad) + xyz[1]*cos(rad); | |
105 xyz[2] = xyz[2]; | |
106 } | |
107 | |
108 void rotate(float *xyz, float *matrix) | |
109 { | |
110 float abc[4]; | |
111 abc[0] = xyz[0]; | |
112 abc[1] = xyz[1]; | |
113 abc[2] = xyz[2]; | |
114 abc[3] = xyz[3]; | |
115 | |
116 for(int i=0; i<4; i++) | |
117 { | |
118 //xyz[i] = abc[0]*rot[i] + abc[1]*rot[i+4] + abc[2]*rot[i+8] + abc[3]*rot[i+12]; | |
119 xyz[i] = abc[0]*matrix[i] + abc[1]*matrix[i+4] + abc[2]*matrix[i+8] + abc[3]*matrix[i+12]; | |
120 } | |
121 } | |
122 | |
123 | |
124 void translate(float *xyz, float x, float y, float z) | |
125 { | |
126 xyz[0] += x; | |
127 xyz[1] += y; | |
128 xyz[2] += z; | |
129 } |