GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Stream.hh
Go to the documentation of this file.
1
2#include "Graph.hh"
3#include "ObjectCreator.hh"
4
6{
7public:
9 void PolyLine(Point p1, Point p2) { PolyQuad(p1,p1,p2,p2); }
10 void TexLine(Point2d t1, Point2d t2) { TexQuad(t1,t1,t2,t2); }
11 void ColorLine(Color c1, Color c2) { ColorQuad(c1,c1,c2,c2); }
12 void NormalLine(QuadNormal n1, QuadNormal n2) { NormalQuad(n1,n1,n2,n2); }
13 void PolyTri(Point p1, Point p2, Point p3) { PolyQuad(p1,p2,p3,p3); }
14 void TexTri(Point2d t1, Point2d t2, Point2d t3) { TexQuad(t1,t2,t3,t3); }
15 void ColorTri(Color c1, Color c2, Color c3) { ColorQuad(c1,c2,c3,c3); }
16 void NormalTri(QuadNormal n1, QuadNormal n2, QuadNormal n3) { NormalQuad(n1,n2,n3,n3); }
17 void PolyQuad(Point p1, Point p2, Point p3, Point p4)
18 {
19 tmpquad.p1 = p1;
20 tmpquad.p2 = p2;
21 tmpquad.p3 = p3;
22 tmpquad.p4 = p4;
23 }
24 void TexQuad(Point2d t1, Point2d t2, Point2d t3, Point2d t4)
25 {
26 tmptex.t1 = t1;
27 tmptex.t2 = t2;
28 tmptex.t3 = t3;
29 tmptex.t4 = t4;
30 }
31 void ColorQuad(Color c1, Color c2, Color c3, Color c4)
32 {
33 tmpcolor.c1 = c1;
34 tmpcolor.c2 = c2;
35 tmpcolor.c3 = c3;
36 tmpcolor.c4 = c4;
37 }
39 {
40 tmpnormal.n1 = n1;
41 tmpnormal.n2 = n2;
42 tmpnormal.n3 = n3;
43 tmpnormal.n4 = n4;
44 }
45 void MeshFace()
46 {
47 quad.push_back(tmpquad);
48 m_poly = true;
49 }
51 {
52 normal.push_back(tmpnormal);
53 m_normal = true;
54 }
55 void TexFace()
56 {
57 tex.push_back(tmptex);
58 m_tex = true;
59 }
60 void ColorFace()
61 {
62 color.push_back(tmpcolor);
63 m_color = true;
64 }
65
66
67 void MeshFrame()
68 {
69 quadindex.push_back(quad.size());
70 }
71 void TexFrame()
72 {
73 texindex.push_back(tex.size());
74 }
76 {
77 colorindex.push_back(color.size());
78 }
80 {
81 normalindex.push_back(normal.size());
82 }
83
84public:
88 Normal tmpnormal;
89
90 std::vector<Quad> quad;
91 std::vector<Tex> tex;
92 std::vector<QuadColor> color;
93 std::vector<Normal> normal;
94
95 std::vector<int> quadindex;
96 std::vector<int> texindex;
97 std::vector<int> colorindex;
98 std::vector<int> normalindex;
99};
100
101class Stream3dMesh : public Mesh
102{
103public:
104 Stream3dMesh(Stream3d &s) : s(s) { }
105 virtual int NumFrames() const { return s.quadindex.size(); }
106 virtual int NumFaces(int framenum) const { return s.quadindex[0]; }
107 virtual int NumPoints() const { return 4; }
108 virtual Point FacePoint(int framenum, int face, int point) const
109 {
110 int index;
111 if (framenum==0) index=0;
112 else index = s.quadindex[framenum-1];
113
114 Quad q = s.quad[index+face];
115 if (point ==0) return q.p1;
116 if (point ==1) return q.p2;
117 if (point ==2) return q.p3;
118 if (point ==3) return q.p4;
119 }
120
121private:
122 Stream3d &s;
123};
125{
126public:
128 virtual int NumFrames() const { return s.normalindex.size(); }
129 virtual Vector PointNormal(int framenum, int face, int point) const
130 {
131 int index;
132 if (framenum==0) index=0;
133 else index = s.normalindex[framenum-1];
134 Normal n = s.normal[index+face];
135 if (point==0) return n.n1;
136 if (point==1) return n.n2;
137 if (point==2) return n.n3;
138 if (point==3) return n.n4;
139 }
140
141private:
142 Stream3d &s;
143};
144
145
147{
148public:
150 virtual int NumFrames() const { return s.normalindex.size(); }
151 virtual Point2d PointTexCoord(int framenum, int face, int point) const
152 {
153 int index;
154 if (framenum==0) index=0;
155 else index = s.texindex[framenum-1];
156 Tex t = s.tex[index+face];
157 if (point==0) return t.t1;
158 if (point==1) return t.t2;
159 if (point==2) return t.t3;
160 if (point==3) return t.t4;
161 }
162
163private:
164 Stream3d &s;
165};
166
167
169{
170public:
172 virtual int NumFrames() const { return s.colorindex.size(); }
173 virtual unsigned int VertexColor(int framenum, int face, int point) const
174 {
175 int index;
176 if (framenum==0) index=0;
177 else index = s.colorindex[framenum-1];
178 QuadColor c = s.color[index+face];
179 if (point==0) return c.c1.Pixel();
180 if (point==1) return c.c2.Pixel();
181 if (point==2) return c.c3.Pixel();
182 if (point==3) return c.c4.Pixel();
183 }
184
185private:
186 Stream3d &s;
187};
188
189
190
192{
193 return fptr(s);
194}
196{
197 s.PolyQuad(q.p1,q.p2,q.p3,q.p4);
198 s.MeshFace();
199 return s;
200}
202{
203 s.TexQuad(q.t1,q.t2,q.t3,q.t4);
204 s.TexFace();
205 return s;
206}
208{
209 s.NormalQuad(q.n1,q.n2,q.n3,q.n4);
210 s.NormalFace();
211 rturn s;
212}
214{
215 s.ColorQuad(q.p1,q.p2,q.p3,q.p4);
216 s.ColorFace();
217 rturn s;
218}
219
220
222{
223 if (s.m_poly) s.MeshFrame();
224 if (s.m_tex) s.TexFrame();
225 if (s.m_color) s.ColorFrame();
226 if (s.m_normal) s.NormalFrame();
227 s.m_poly = false;
228 s.m_tex = false;
229 s.m_color = false;
230 s.m_normal = false;
231 return s;
232}
233
234
235class Movement
236{
237public:
238 virtual float NumFrames() const=0;
239 virtual int NumObjects(float frame) const=0;
240 virtual Point Position(float frame, int obj) const { return Point(0.0,0.0,0.0); }
241 virtual Matrix Transform(float frame, int obj) const { Point p = Position(frame,obj); return Matrix::Translate(p.x,p.y,p.z); }
242 virtual int VertexFrame(float frame, int obj) const=0;
243 virtual int NormalFrame(float frame, int obj) const=0;
244 virtual int ColorFrame(float frame, int obj) const=0;
245 virtual int TexFrame(float frame, int obj) const=0;
246};
247
249void RenderMovement(Movement &m, float time, ArrayRender &r);
250
251
253{
254public:
256
257public:
260};
262{
263 return fptr(s);
264}
266{
267 s.poly = true;
268}
270{
271 s.poly = false;
272}
274{
275 if (poly)
276 {
277 }
278 if (tex)
279 {
280 }
281 if (color)
282 {
283 }
284 if (normal)
285 {
286 }
287}
289{
290 int faces = f.NumFaces();
291 for(int i=0;i<faces;i++)
292 {
293 int points = f.NumPoints(i);
294 if (points==3)
295 {
296 if (poly)
297 {
298 Point p1 = f.FacePoint(i, 0);
299 Point p2 = f.FacePoint(i, 1);
300 Point p3 = f.FacePoint(i, 2);
301 Quad q = { p1, p2, p3, p3 };
302 s.s << q;
303 }
304 if (tex)
305 {
306 Point2d t1 = f.TexCoord(i, 0);
307 Point2d t2 = f.TexCoord(i, 1);
308 Point2d t3 = f.TexCoord(i, 2);
309 Tex t = { t1, t2, t3, t3 };
310 s.s << t;
311 }
312 if (color)
313 {
314 Color c1 = f.Color(i, 0);
315 Color c2 = f.Color(i, 1);
316 Color c3 = f.Color(i, 2);
317 QuadColor c = { c1, c2, c3, c3 };
318 s.s << c;
319 }
320 if (normal)
321 {
322 Vector v1 = f.Normal(i, 0);
323 Vector v2 = f.Normal(i, 1);
324 Vector v3 = f.Normal(i, 2);
325 QuadNormal n = { v1, v2, v3, v3 };
326 s.s << n;
327 }
328 }
329 if (points==4)
330 {
331 if (poly)
332 {
333 Point p1 = f.FacePoint(i, 0);
334 Point p2 = f.FacePoint(i, 1);
335 Point p3 = f.FacePoint(i, 2);
336 Point p4 = f.FacePoint(i, 3);
337 Quad q = { p1, p2, p3, p4 };
338 s.s << q;
339 }
340 if (tex)
341 {
342 Point2d t1 = f.TexCoord(i, 0);
343 Point2d t2 = f.TexCoord(i, 1);
344 Point2d t3 = f.TexCoord(i, 2);
345 Point2d t4 = f.TexCoord(i, 3);
346 Tex t = { t1, t2, t3, t4 };
347 s.s << t;
348 }
349 if (color)
350 {
351 Color c1 = f.Color(i, 0);
352 Color c2 = f.Color(i, 1);
353 Color c3 = f.Color(i, 2);
354 Color c4 = f.Color(i, 3);
355 QuadColor c = { c1, c2, c3, c4 };
356 s.s << c;
357 }
358 if (normal)
359 {
360 Vector v1 = f.Normal(i, 0);
361 Vector v2 = f.Normal(i, 1);
362 Vector v3 = f.Normal(i, 2);
363 Vector v4 = f.Normal(i, 3);
364 QuadNormal n = { v1, v2, v3, v4 };
365 s.s << n;
366 }
367 }
368 }
369 return s;
370}
371
Stream3d & endmesh(Stream3d &s)
Definition Stream.hh:221
ObjectStream & clearpoly(ObjectStream &s)
Definition Stream.hh:269
ObjectStream & setpoly(ObjectStream &s)
Definition Stream.hh:265
void RenderMovement(Movement &m, float time, ArrayRender &r)
Definition Stream.cc:13
Stream3d & operator<<(Stream3d &s, Stream3d &(*fptr)(Stream3d &s))
Definition Stream.hh:191
void PrepareStream(Stream3d &s, ArrayRender &r)
Definition Stream.cc:2
Definition Effect.hh:11461
Definition VectorTools.hh:380
unsigned int Pixel()
Definition VectorTools.hh:426
Definition EffectI.hh:212
Definition VectorTools.hh:279
static Matrix Translate(float x, float y, float z)
Definition VectorTools.cc:547
Definition Effect.hh:11389
Definition Effect.hh:11346
Definition Effect.hh:11366
Definition Effect.hh:11256
Definition GraphI.hh:1884
virtual Matrix Transform(float frame, int obj) const
Definition Stream.hh:241
virtual int NormalFrame(float frame, int obj) const =0
virtual int TexFrame(float frame, int obj) const =0
virtual int NumObjects(float frame) const =0
virtual void frame(MainLoopEnv &e)=0
virtual Point Position(float frame, int obj) const
Definition Stream.hh:240
virtual int VertexFrame(float frame, int obj) const =0
virtual int ColorFrame(float frame, int obj) const =0
virtual float NumFrames() const =0
Definition Graph.hh:8058
virtual unsigned int VertexColor(int framenum, int face, int point) const
Definition Stream.hh:173
virtual int NumFrames() const
Definition Stream.hh:172
Stream3dMeshColors(Stream3d &s)
Definition Stream.hh:171
virtual int NumFrames() const
Definition Stream.hh:128
virtual Vector PointNormal(int framenum, int face, int point) const
Definition Stream.hh:129
Stream3dMeshNormals(Stream3d &s)
Definition Stream.hh:127
virtual Point2d PointTexCoord(int framenum, int face, int point) const
Definition Stream.hh:151
Stream3dMeshTexCoords(Stream3d &s)
Definition Stream.hh:149
virtual int NumFrames() const
Definition Stream.hh:150
virtual int NumFrames() const
Definition Stream.hh:105
virtual int NumPoints() const
Definition Stream.hh:107
Stream3dMesh(Stream3d &s)
Definition Stream.hh:104
virtual Point FacePoint(int framenum, int face, int point) const
Definition Stream.hh:108
virtual int NumFaces(int framenum) const
Definition Stream.hh:106
Definition Stream.hh:6
bool m_color
Definition Stream.hh:8
void MeshFrame()
Definition Stream.hh:67
Normal tmpnormal
Definition Stream.hh:88
void NormalFace()
Definition Stream.hh:50
void MeshFace()
Definition Stream.hh:45
bool m_tex
Definition Stream.hh:8
void PolyQuad(Point p1, Point p2, Point p3, Point p4)
Definition Stream.hh:17
void TexTri(Point2d t1, Point2d t2, Point2d t3)
Definition Stream.hh:14
std::vector< int > texindex
Definition Stream.hh:96
Tex tmptex
Definition Stream.hh:86
std::vector< QuadColor > color
Definition Stream.hh:92
void ColorLine(Color c1, Color c2)
Definition Stream.hh:11
void ColorFace()
Definition Stream.hh:60
void PolyLine(Point p1, Point p2)
Definition Stream.hh:9
void ColorTri(Color c1, Color c2, Color c3)
Definition Stream.hh:15
void PolyTri(Point p1, Point p2, Point p3)
Definition Stream.hh:13
std::vector< int > quadindex
Definition Stream.hh:95
std::vector< int > normalindex
Definition Stream.hh:98
void NormalTri(QuadNormal n1, QuadNormal n2, QuadNormal n3)
Definition Stream.hh:16
QuadColor tmpcolor
Definition Stream.hh:87
void NormalFrame()
Definition Stream.hh:79
void NormalLine(QuadNormal n1, QuadNormal n2)
Definition Stream.hh:12
std::vector< int > colorindex
Definition Stream.hh:97
std::vector< Tex > tex
Definition Stream.hh:91
std::vector< Normal > normal
Definition Stream.hh:93
std::vector< Quad > quad
Definition Stream.hh:90
void ColorQuad(Color c1, Color c2, Color c3, Color c4)
Definition Stream.hh:31
void TexLine(Point2d t1, Point2d t2)
Definition Stream.hh:10
Quad tmpquad
Definition Stream.hh:85
bool m_poly
Definition Stream.hh:8
void TexFrame()
Definition Stream.hh:71
void ColorFrame()
Definition Stream.hh:75
bool m_normal
Definition Stream.hh:8
void NormalQuad(QuadNormal n1, QuadNormal n2, QuadNormal n3, QuadNormal n4)
Definition Stream.hh:38
void TexQuad(Point2d t1, Point2d t2, Point2d t3, Point2d t4)
Definition Stream.hh:24
void TexFace()
Definition Stream.hh:55
Definition VectorTools.hh:125
background color
Definition gameapi_example.php:46
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
Definition Stream.hh:253
bool poly
Definition Stream.hh:259
Stream3d & s
Definition Stream.hh:258
ObjectStream(Stream3d &s)
Definition Stream.hh:255
bool tex
Definition Stream.hh:259
bool color
Definition Stream.hh:259
bool normal
Definition Stream.hh:259
Definition VectorTools.hh:910
Definition Parser.cc:60
float x
Definition Parser.cc:60
float y
Definition Parser.cc:60
float z
Definition Parser.cc:60
Definition GraphI.hh:714
Color c2
Definition GraphI.hh:715
Color c4
Definition GraphI.hh:715
Color c3
Definition GraphI.hh:715
Color c1
Definition GraphI.hh:715
Definition GraphI.hh:710
Vector n2
Definition GraphI.hh:711
Vector n4
Definition GraphI.hh:711
Vector n1
Definition GraphI.hh:711
Vector n3
Definition GraphI.hh:711
Definition GraphI.hh:702
Point p3
Definition GraphI.hh:703
Point p1
Definition GraphI.hh:703
Point p2
Definition GraphI.hh:703
Point p4
Definition GraphI.hh:703
Definition GraphI.hh:706
Point2d t4
Definition GraphI.hh:707
Point2d t1
Definition GraphI.hh:707
Point2d t3
Definition GraphI.hh:707
Point2d t2
Definition GraphI.hh:707