annotate TaskManager/Test/simple_render/viewer.cpp @ 48:70a0ac46133e

*** empty log message ***
author gongo
date Fri, 15 Feb 2008 16:09:42 +0900
parents aa11038dbdc1
children 64ef030deb22
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
1 #include <iostream>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
2 #include <SDL.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
3 #include <SDL_opengl.h>
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
4 #include <math.h>
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
5 #include <unistd.h>
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
6 #include "polygon.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
7 //#include "demonstration.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
8 //#include "scene.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
9 #include "viewer.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
10 #include "sys.h"
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
11 using namespace std;
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
12
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
13 #define redMask 0x00ff0000
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
14 #define greenMask 0x0000ff00
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
15 #define blueMask 0x000000ff
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
16 #define alphaMask 0
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
17
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
18 extern int create_sgp(Polygon *sg, SceneGraphPack *sgp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
19 extern int update_sgp(SceneGraphPack *sgp, SceneGraphPack *_sgp);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
20 extern int create_pp(SceneGraphPack *sgp, PolygonPack *pp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
21
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
22 Viewer::Viewer(int b, int w, int h)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
23 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
24 bpp = b;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
25 width = w;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
26 height = h;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
27 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
28
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
29
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
30 void Viewer::sdl_init()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
31 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
32 if( SDL_Init( SDL_INIT_VIDEO ) < 0 )
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
33 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
34 fprintf(stderr,"Couldn't initialize SDL: %s\n",SDL_GetError());
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
35 exit( 1 );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
36 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
37 screen = SDL_SetVideoMode( width, height, bpp, SDL_HWSURFACE );
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
38 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
39
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
40
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
41 int Viewer::get_ticks()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
42 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
43 int time;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
44 time = SDL_GetTicks();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
45 return time;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
46 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
47
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
48 bool Viewer::quit_check()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
49 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
50 bool quit = false;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
51 SDL_Event event;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
52 while(SDL_PollEvent(&event))
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
53 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
54 if(event.type==SDL_QUIT)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
55 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
56 quit = true;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
57 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
58 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
59 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
60 return quit;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
61 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
62
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
63 void Viewer::quit()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
64 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
65 SDL_Quit();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
66 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
67
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
68
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
69 void Viewer::swap_buffers()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
70 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
71 SDL_GL_SwapBuffers();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
72 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
73
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
74
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
75 void Viewer::write_pixel(int x, int y,float z, Uint32 rgb) {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
76 SDL_PixelFormat *pf;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
77 pf = screen->format;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
78 //printf("x:%d y:%d z:%d\n",x,y,z);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
79
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
80 //cout << "write_pixel" << endl;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
81 //cout << x << " " << y << endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
82
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
83 //cout << SDL_MapRGB(pf,0,0,150) << endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
84
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
85 x += width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
86 y += height/2;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
87
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
88 static int diffz,diffz1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
89 diffz1 = diffz;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
90 diffz = (zRow[x][y]>z);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
91 if(diffz != diffz1) {
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
92 //printf("diffz :%d zRow[%d][%d] = %f z = %f\n",diffz,x,y,zRow[x][y],z);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
93 }
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
94 //printf("x:%d,y:%d,z:%f,zRow:%f\n",x,y,z,zRow[x][y]);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
95 if(z < zRow[x][y]) {
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
96 // printf("x:%d,y:%d,z:%d\n",x,y,z,zRow);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
97 if(x < width && x > 0 && y > 0 && y < height)
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
98 {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
99 //pixels[width*y + x] = SDL_MapRGB(pf,70,70,71);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
100 zRow[x][y] = z;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
101 y = height - y;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
102 pixels[width*y + x] = rgb;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
103 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
104 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
105 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
106
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
107 void Viewer::write_line(float x1, float y1, float x2, float y2, Uint32 rgb)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
108 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
109 //cout << "write_line("<< x1 << "," << y1 << "," << x2 << "," << y2 << ")"<< endl;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
110
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
111 //Uint32 rgb = 9830400;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
112
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
113 if(x1 > x2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
114 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
115 float x=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
116 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
117 x=x1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
118 y=y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
119 x1 = x2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
120 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
121 x2 = x;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
122 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
123 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
124 float s = y1;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
125
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
126 if((int)x1 == (int)x2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
127 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
128 if(y1 > y2)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
129 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
130 float y=0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
131 y = y1;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
132 y1 = y2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
133 y2 = y;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
134 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
135 for(float i=y1; i<y2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
136 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
137 //write_pixel((int)x1,(int)i);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
138 write_pixel((int)x1,(int)i,0,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
139 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
140 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
141 else
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
142 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
143 float t = (y2 - y1)/(x2 - x1);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
144 if(t < -1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
145 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
146 float f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
147 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
148 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
149 for(float a=(int)t; a<0; a++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
150 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
151 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
152 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
153 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
154 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
155 f += t-(int)t;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
156 if(f <= -1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
157 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
158 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
159 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
160 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
161 s--;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
162 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
163 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
164 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
165 else if(t <= 1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
166 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
167 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
168 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
169 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
170 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
171 s += t;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
172 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
173 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
174 else
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
175 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
176 float f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
177 for(float i=x1; i<x2; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
178 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
179 for(float a=0; a<(int)t; a++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
180 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
181 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
182 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
183 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
184 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
185 f += t-(int)t;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
186 if(f >= 1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
187 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
188 //write_pixel((int)i,(int)s);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
189 write_pixel((int)i,(int)s,0,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
190 f = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
191 s++;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
192 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
193 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
194 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
195 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
196 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
197
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
198 void Viewer::write_triangle(float x1, float y1, float x2, float y2, float x3, float y3, Uint32 rgb)
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
199 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
200 write_line(x1,y1,x2,y2,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
201 write_line(x2,y2,x3,y3,rgb);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
202 write_line(x3,y3,x1,y1,rgb);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
203 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
204
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
205 void Viewer::clean_pixels()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
206 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
207 for(int i=0; i<width*height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
208 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
209 pixels[i] = 0x00;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
210 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
211 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
212
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
213 void Viewer::graph_line()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
214 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
215 int xl = width*height/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
216 int yl = width/2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
217 for(int i=0; i<width; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
218 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
219 for(int t=0; t<height; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
220 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
221 pixels[width*t+i] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
222 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
223 pixels[xl +i] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
224 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
225 for(int i=0; i<height; i++)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
226 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
227 for(int t=0; t<width; t+=20)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
228 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
229 pixels[i*width+t] = 0x5a;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
230 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
231 pixels[i*width+yl] = 0xff;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
232 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
233 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
234
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
235
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
236 struct run_arg_t {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
237 int start_time;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
238 int this_time;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
239 int frames;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
240 SDL_Surface *bitmap;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
241 SDL_PixelFormat *pf;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
242 Uint32 background;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
243 Polygon *p;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
244 SceneGraphPack *sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
245 PolygonPack *pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
246 };
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
247
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
248 struct run_arg_t *arg;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
249
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
250 void
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
251 Viewer::run_init()
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
252 {
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
253 arg = new run_arg_t;
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
254 HTaskPtr task;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
255 int fd;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
256
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
257 fprintf(stderr, " ** %s **\n", __FUNCTION__);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
258
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
259 arg->start_time = get_ticks();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
260 arg->pf = screen->format;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
261 arg->background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
262 arg->p = new Polygon;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
263 arg->p->set_data("cube.xml");
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
264 arg->p->viewer = this;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
265 arg->sgp = new SceneGraphPack;
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
266 create_sgp(arg->p, arg->sgp);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
267 arg->pp = new PolygonPack;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
268
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
269 pixels = new Uint32[width*height];
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
270
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
271 graph_line();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
272
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
273 arg->bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32,
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
274 width*4, redMask, greenMask,
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
275 blueMask, alphaMask);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
276
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
277 fd = manager->open("ViewerRunLoop");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
278 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
279 manager->spawn_task(task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
280 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
281
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
282 void
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
283 Viewer::run_loop(void)
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
284 {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
285 HTaskPtr task_update_sgp = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
286 HTaskPtr task_create_pp = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
287 HTaskPtr task_finish = NULL;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
288 int fd_update_sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
289 int fd_create_pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
290 int fd_finish;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
291
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
292 HTaskPtr task;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
293 int fd;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
294
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
295 fprintf(stderr, " ** %s **\n", __FUNCTION__);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
296
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
297
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
298 if (quit_check()) {
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
299 arg->this_time = get_ticks();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
300 fd_finish = manager->open("ViewerRunFinish");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
301 task_finish = manager->create_task(fd_finish, 0, 0, 0, NULL);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
302 manager->spawn_task(task_finish);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
303 return;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
304 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
305
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
306 clean_pixels();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
307
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
308 zRow_init();
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
309 graph_line();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
310
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
311 fd_update_sgp = manager->open("UpdateSGP");
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
312 fd_create_pp = manager->open("CreatePP");
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
313 fd = manager->open("ViewerRunDraw");
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
314 task_update_sgp = manager->create_task(fd_update_sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
315 sizeof(SceneGraphPack),
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
316 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
317 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
318 NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
319 task_create_pp = manager->create_task(fd_create_pp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
320 sizeof(SceneGraphPack),
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
321 (unsigned int)arg->sgp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
322 (unsigned int)arg->pp,
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
323 NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
324 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
325
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
326 manager->set_task_depend(task_update_sgp, task);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
327 manager->set_task_depend(task_create_pp, task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
328
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
329 manager->spawn_task(task_update_sgp);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
330 manager->spawn_task(task_create_pp);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
331 manager->spawn_task(task);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
332 }
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
333
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
334 void
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
335 Viewer::run_draw(void)
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
336 {
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
337 HTaskPtr task;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
338 int fd;
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
339
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
340
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
341 fprintf(stderr, " ** %s **\n", __FUNCTION__);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
342
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
343 arg->p->draw(arg->pp); // test draw of PolygonPack
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
344
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
345 SDL_BlitSurface(arg->bitmap, NULL, screen, NULL);
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
346 SDL_UpdateRect(screen, 0, 0, 0, 0);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
347
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
348 //swap_buffers();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
349 arg->frames++;
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
350
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
351 fd = manager->open("ViewerRunLoop");
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
352 task = manager->create_task(fd, 0, 0, 0, NULL);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
353 manager->spawn_task(task);
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
354 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
355
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
356 void
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
357 Viewer::run_finish(void)
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
358 {
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
359 fprintf(stderr, " ** %s **\n", __FUNCTION__);
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
360
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
361 if (arg->this_time != arg->start_time) {
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
362 cout<< ((float)arg->frames/(arg->this_time-arg->start_time))*1000.0 << " FPS\n";
42
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
363 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
364
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
365 SDL_FreeSurface(arg->bitmap);
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
366 delete [] pixels;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
367 arg->p->delete_data();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
368 delete arg->p;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
369 delete arg->sgp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
370 delete arg->pp;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
371 quit();
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
372
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
373 delete arg;
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
374 }
aa11038dbdc1 *** empty log message ***
gongo
parents: 38
diff changeset
375
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
376 #if 0
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
377 void Viewer::run()
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
378 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
379 int frames = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
380 int start_time, this_time;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
381
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
382 HTaskPtr task_create_sgp = NULL;
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
383 HTaskPtr task_update_sgp = NULL;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
384 HTaskPtr task_create_pp = NULL;
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
385 int fd_create_sgp;
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
386 int fd_update_sgp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
387 int fd_create_pp;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
388
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
389 start_time = get_ticks();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
390
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
391 SDL_Surface *bitmap = NULL;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
392 SDL_PixelFormat *pf;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
393 pf = screen->format;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
394
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
395 Uint32 background;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
396 background = SDL_MapRGB(screen->format, 0x00, 0x00, 0x00);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
397
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
398 pixels = new Uint32[width*height];
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
399
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
400 Polygon *p = new Polygon;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
401 p->set_data("cube.xml");
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
402 //p->set_data("cube-p.xml");
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
403
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
404 p->viewer = this;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
405 //p->screen = screen;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
406
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
407 SceneGraphPack *sgp = new SceneGraphPack;
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
408 create_sgp(p, sgp);
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
409
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
410 PolygonPack *pp = new PolygonPack;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
411
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
412 graph_line();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
413
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
414 float r = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
415 float x = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
416 float y = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
417 float z = 0;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
418
35
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
419 bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32,
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
420 width*4, redMask, greenMask,
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
421 blueMask, alphaMask);
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
422
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
423 // Loop until done.
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
424 while(1)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
425 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
426 // Destroy our GL context, etc.
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
427 //if(quit_check() || scene->action_scene==NULL)
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
428 if(quit_check())
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
429 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
430 this_time = get_ticks();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
431 if (this_time != start_time)
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
432 {
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
433 cout<<((float)frames/(this_time-start_time))*1000.0<<" FPS\n";
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
434 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
435 SDL_FreeSurface(bitmap);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
436 delete pixels;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
437 p->delete_data();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
438 delete p;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
439 delete sgp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
440 delete pp;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
441 quit();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
442 break;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
443 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
444 /////////////////////
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
445 clean_pixels();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
446
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
447 this->zRow_init();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
448 graph_line();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
449
36
650e46810d04 *** empty log message ***
gongo
parents: 35
diff changeset
450 #if 0 // ここは update_sgp
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
451 if(r > 360) r = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
452 r+= 1.0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
453 // r= 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
454 p->angle[0] = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
455 p->angle[1] = r;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
456 p->angle[2] = 0;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
457 //p->child->angle[1] = r*2;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
458 //p->child->brother->angle[1] = r*3;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
459 //p->child->brother->child->angle[1] = r*4;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
460 x += 0.5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
461 y += 0.5;
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
462 z += 0.5;
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
463 p->xyz[0] = x;
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
464 p->xyz[1] = y;
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
465 p->xyz[2] = z;
35
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
466 //p->tree_draw();
36
650e46810d04 *** empty log message ***
gongo
parents: 35
diff changeset
467 #endif
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
468
37
cd0b54a564a9 *** empty log message ***
gongo
parents: 36
diff changeset
469 #if 0
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
470 update_sgp(sgp, sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
471 create_pp(pp, sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
472 #else
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
473 fd_update_sgp = manager->open("UpdateSGP");
29
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
474 fd_create_pp = manager->open("CreatePP");
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
475 task_update_sgp =
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
476 manager->create_task(fd_update_sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
477 sizeof(SceneGraphPack),
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
478 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
479 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
480 NULL);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
481 task_create_pp =
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
482 manager->create_task(fd_create_pp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
483 sizeof(SceneGraphPack),
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
484 (unsigned int)sgp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
485 (unsigned int)pp,
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
486 NULL);
e949a536a68d *** empty log message ***
gongo
parents: 28
diff changeset
487
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
488 manager->spawn_task(task_update_sgp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
489 manager->spawn_task(task_create_pp);
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
490 manager->run();
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
491 #endif
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
492
31
6a77b5e755ab *** empty log message ***
gongo
parents: 29
diff changeset
493 //p->draw(sgp); // test draw of SceneGraphPack
6a77b5e755ab *** empty log message ***
gongo
parents: 29
diff changeset
494 p->draw(pp); // test draw of PolygonPack
6a77b5e755ab *** empty log message ***
gongo
parents: 29
diff changeset
495
35
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
496 // 一回のみ生成で、その後は再利用
37
cd0b54a564a9 *** empty log message ***
gongo
parents: 36
diff changeset
497 //bitmap = SDL_CreateRGBSurfaceFrom((void *)pixels, width, height, 32,
cd0b54a564a9 *** empty log message ***
gongo
parents: 36
diff changeset
498 //width*4, redMask, greenMask,
cd0b54a564a9 *** empty log message ***
gongo
parents: 36
diff changeset
499 //blueMask, alphaMask);
cd0b54a564a9 *** empty log message ***
gongo
parents: 36
diff changeset
500
35
1e17e0b441a7 *** empty log message ***
gongo
parents: 31
diff changeset
501 //SDL_FillRect(screen, NULL, background);
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
502 SDL_BlitSurface(bitmap, NULL, screen, NULL);
38
babf9a330418 *** empty log message ***
gongo
parents: 37
diff changeset
503 SDL_UpdateRect(screen, 0, 0, 0, 0);
babf9a330418 *** empty log message ***
gongo
parents: 37
diff changeset
504
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
505
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
506 /////////////////////
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
507
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
508 //swap_buffers();
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
509 ++frames;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
510 }
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
511 }
48
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
512 #else
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
513 void Viewer::run() {}
70a0ac46133e *** empty log message ***
gongo
parents: 42
diff changeset
514 #endif
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
515
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
516 void
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
517 Viewer::zRow_init()
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
518 {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
519 for (int i = 0; i < width; i++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
520 for (int j = 0; j < height; j++) {
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
521 zRow[i][j] = 65535;
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
522 }
28
243ee0a1fe6f *** empty log message ***
gongo
parents: 26
diff changeset
523 }
26
3f68b2ef4fb0 *** empty log message ***
gongo
parents:
diff changeset
524 }