GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Category.hh
Go to the documentation of this file.
1//
2// Copyright (C) 2009 Tero Pulkkinen
3// Released under LGPL License.
4//
5// This file is part of Polygon.
6//
7// Polygon is free software: you can redistribute it and/or modify
8// it under the terms of the GNU General Public License as published by
9// the Free Software Foundation, either version 3 of the License, or
10// (at your option) any later version.
11//
12// Polygon is distributed in the hope that it will be useful,
13// but WITHOUT ANY WARRANTY; without even the implied warranty of
14// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15// GNU General Public License for more details.
16//
17// You should have received a copy of the GNU Library General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21
22
23#include <vector>
24#include "VectorTools.hh"
25#include "Effect.hh"
26#include "Graph.hh"
27
28//
29// Objects
30//
32{
33};
35{
37};
39{
41};
43{
44 float sx;
45 float sy;
46 float sz;
47};
49{
50 float sx;
51 float sy;
52 float sz;
53};
55{
57};
59{
60 bool b;
61};
63{
65};
67{
68 unsigned int color;
69};
71{
72 int num;
73};
75{
76 int num;
77};
79{
80 int num;
81};
83{
84 int num;
85};
87{
88 float num;
89};
91{
93 unsigned int color;
94 int object;
95};
96template<class I, class T>
102template<class I, class T>
104{
106 Array<I,T> *array; // owned
107};
108
115{
116 std::vector<FaceCollection*> vec;
117};
119{
120 std::vector<int> vec;
121};
122template<class T>
124{
126 Bitmap<T> *bitmap; // owned
127};
128template<class T>
130{
132 Voxel<T> *voxel; // owned
133};
134template<class T>
145{
147};
149{
152
153};
176
178
179
180//
181// Arrows
182//
183// (UnitVectors, Cube, Point2) -> Point
184struct CubeArrow : public virtual Point2Object, public virtual UnitVectorsObject, public virtual CubeObject, public virtual PointObject
185{
186 void doit()
187 {
189 }
190};
191
192// (Vec) -> IndexObject && Arrow
193template<class Vec, class Arrow>
194struct IterateArrow : public virtual Vec, public virtual IndexObject, public Arrow
195{
196 void doit()
197 {
198 int size = Vec::array->Size();
199 for(int i=0;i<size;i++)
200 {
202 Arrow::doit();
203 }
204 }
205};
206
207template<class Vec, class Arrow>
208struct Iterate2Arrow : public virtual Vec, public virtual Index2Object, public Arrow
209{
210 void doit()
211 {
212 int size = Vec::array->Size();
213 for(int i=0;i<size;i++)
214 {
216 Arrow::doit();
217 }
218 }
219};
220
221// Top -> Matrix
222struct IdentityMatrixArrow : public virtual MatrixObject
223{
224 void doit() { m = Matrix::Identity(); }
225};
226
227// (Size, Point) -> Matrix -> Matrix
228struct ScaleTranslateArrow : public virtual SizeObject, public virtual PointObject, public virtual MatrixObject
229{
230 void doit() {
231 //std::cout << p.x << " " << p.y << " " << p.z << std::endl;
232
234 }
235};
236// (Matrix, Color, ObjectNum) -> Render
237struct MatrixColorArrow : public virtual MatrixObject,
238 public virtual ColorObject,
239 public virtual ObjectNumObject,
240 public virtual RenderObject
241{
248};
249// (Render,VBOState) -> ()
250struct RenderArrow : public virtual RenderObject, public virtual VBOStateObject
251{
252 void doit();
253};
254// List -> IndexList
255template<class T>
256struct IndexesArrow : public virtual T, public virtual IndexListObject
257{
258 void doit()
259 {
260 IndexListObject::vec.clear();
261 for(int i=0;i<T::vec.size();i++)
262 {
263 IndexListObject::vec.push_back(i);
264 }
265 }
266};
267// List<FaceCollection> -> IndexList
268class FaceCollectionIndexes : public IndexesArrow<FaceCollectionListObject>
269{
270};
271// () -> CubeList
272class SingleCubeArrow : public virtual CubeListObject
273{
274public:
275 void doit()
276 {
278 Cube2 c;
279 c.x = 5;
280 c.y = 5;
281 c.z = 5;
283 }
284};
285// voxel -> CubeList
286class MarchingCubesArrow : public virtual VoxelObject<bool>, public virtual CubeListObject
287{
288public:
289 void doit()
290 {
293 ptr->Init();
295 MarchingCubesVoxel vox(*voxel, *ptr);
296 vox.Gen();
297 }
298};
299
300// (RangeProduct, VolumeObject)->ContinuousVoxel
301class VolumeObjectVoxelArrow : public virtual RangeProductObject, public virtual VolumeObjectObject, public virtual ContinuousVoxelObject<bool>
302{
303public:
304 void doit()
305 {
306 //delete voxel;
307 //voxel = new VolumeVoxel(*volume, rx,ry,rz);
308 }
309};
310// (Cube, ContinuousVoxel) -> Voxel
311template<class T>
312class SampleVoxelArrow : public virtual CubeObject, public virtual ContinuousVoxelObject<T>, public virtual VoxelObject<T>
313{
314public:
320};
321
322// (VolumePosList, Index2)->(VolumeObject, Point2)
323class DerefVolumePosArrow : public virtual VolumePosListObject, public virtual Index2Object, public virtual VolumeObjectObject, public virtual Point2Object
324{
325public:
326 void doit()
327 {
328 std::pair<VolumeObject*, Point> pp = VolumePosListObject::array->Index(Index2Object::num);
331 Point2Object::p = pp.second;
332 }
333};
334
335// (CubeList, Index) -> Cube
336class DerefCubeArrow : public virtual CubeListObject, public virtual IndexObject, public virtual CubeObject
337{
338public:
340};
341// (Point, Size2) -> Color
342class ColorCubeArrow : public virtual PointObject, public virtual SizeObject2, public virtual ColorObject
343{
344public:
345 void doit() { ColorObject::color = Color::ColorCube(p.x, p.y, p.z, sx, sy, sz); }
346};
347//
348// Compositions
349//
350
351//
352// (UnitVectors, CubeList, Index, Point2, Size) -> Matrix
353// Modifies: Cube, Point, Matrix
355{
356public:
357 void doit()
358 {
359 DerefCubeArrow::doit(); // CubeList, Index -> Cube
360 CubeArrow::doit(); // UnitVectors, Cube, Point2 -> Point
361 IdentityMatrixArrow::doit(); // Top -> Matrix
362 ScaleTranslateArrow::doit(); // (Size, Point) -> Matrix -> Matrix
363 }
364};
365// (UnitVectors, CubeList, Index, Color, ObjectNum, VBOState, Point2, Size) -> ()
366// Modifies: Cube, Point, Matrix, Render
367
369{
370public:
371 void doit()
372 {
375 //std::cout << PointObject::p << std::endl;
380 }
381};
382// (UnitVectors, CubeList, Index, ObjectNum, VBOState, Point2, Size) -> ()
383// Modifies: Cube, Point, Matrix, Render, Color
384
386{
387public:
388 void doit()
389 {
390 DerefCubeTranslate::doit(); // (UnitVectors, CubeList, Index, Point2, Size) -> (Cube, Point, Matrix)
391 ColorCubeArrow::doit(); // (Point, Size2) -> Color
392 MatrixColorArrow::doit(); // (Matrix, Color, ObjectNum) -> Render
393 RenderArrow::doit(); // Render, VBOState -> ()
394 }
395};
396// (Cube, RangeProduct, VolumeObject, UnitVectors, Color, ObjectNum, VBOState, Point2, Size) -> ()
397// Modifies: ContinuousVoxel, Voxel, CubeList, Index, Cube, Point, Matrix, Render
398class VoxelRenderArrow : public VolumeObjectVoxelArrow, public SampleVoxelArrow<bool>, public MarchingCubesArrow, public IterateArrow<CubeListObject, ColorRender>
399{
400public:
401 void doit()
402 {
403 VolumeObjectVoxelArrow::doit(); // RangeProduct, VolumeObject->COntinuousVoxel
404 SampleVoxelArrow<bool>::doit(); // Cube, COntinuousVoxel -> Voxel
405 MarchingCubesArrow::doit(); // Voxel -> CubeList
406 IterateArrow<CubeListObject, ColorRender>::doit(); // CubeList -> IndexObject && (UnitVectors, CubeList, Index, ObjectNum, VBOState, Point2, Size) -> ()
407 }
408};
409
411{
412public:
413 void doit()
414 {
415 DerefVolumePosArrow::doit(); // (VolumePosList, Index2) -> (VolumeObject, Point2)
416 VoxelRenderArrow::doit(); // (Cube, RangeProduct, VolumeObject, UnitVectors, Color, ObjectNum, VBOState, Point2, Size) -> ()
417 }
418
419};
420
421// (VolumePosList, Cube, RangeProduct, UnitVectors, Color, ObjectNum, VBOState, Size) -> ()
422// Modifies: ContinuousVoxel, Voxel, CubeList, Index, Cube, Point, Matrix, Render, VolumeObject, Point2
423class VolumeCityArrow : public Iterate2Arrow<VolumePosListObject, DerefVoxelRenderArrow>
424{
425public:
426 void doit()
427 {
428 Iterate2Arrow<VolumePosListObject, DerefVoxelRenderArrow>::doit(); // VolumePosList -> Index2 && (VolumePosList, Index2, Cube, RangeProduct, UnitVectors, Color, ObjectNum, VBOState, Size) -> ()
429 }
430};
431
432//
433// Effects
434//
436{
437public:
439 void Init();
440 bool Frame(float time);
441private:
442 VolumeCityArrow vox;
443};
444
445
446//
447//
448// Categories
449//
450//
451// Category of relations
452#if 0
453template<class I>
454class Rel
455{
456public:
457 template<class A, class B>
458 struct Arrow
459 {
460 virtual I Size() const=0;
461 virtual std::pair<A,B> Subset(I i) const=0;
462 virtual bool Inside(A a, B b) const=0;
463 };
464 template<class A>
465 struct IndentityArrow : public Arrow<A,A>
466 {
467 IdentityArrow(A a) : a(a) { }
468 I Size() const { return I(1); }
469 std::pair<A,A> Subset(I i) const { return std::make_pair(a, a); }
470 bool Inside(A a1, A a2) const { return a1==a2; }
471 A a;
472 };
473 template<class A, class B, class C>
474 struct Composition : public Arrow<A,C>
475 {
476 public:
477 Composition(Arrow<A,B> &arr, Arrow<B,C> &arr2) : arr(arr), arr2(arr2),b(b) { }
478 I Size() const { return I(1); }
479 std::pair<A,C> Subset(I i) const
480 {
481 return std::make_pair(arr.Subset(i).first, arr2.Subset(i).second);
482 }
483 bool Inside(A a, C c) const
484 {
485 std::pair<A,B> p = Subset(0);
486 B b = p.second;
487 return arr.Inside(a,b) && arr2.Inside(b,c);
488 }
489 private:
490 Arrow<A,B> &arr;
491 Arrow<B,C> &arr2;
492 };
493 // Converse
494 template<class A, class B>
495 struct Converse : public Arrow<B,A>
496 {
497 Converse(Arrow<A,B> &f) : f(f) { }
498 I Size() const { return I(1); }
499 std::pair<B,A> Subset(I i) const
500 {
501 std::pair<A,B> p = f.Subset(i);
502 return std::make_pair(p.second, p.first);
503 }
504 bool Inside(B b, A a) const
505 {
506 return f.Inside(a,b);
507 }
508 Arrow<A,B> &f;
509 };
510};
511
512template<class A, class B, class I>
513class SetInRel : public Rel<I>::Arrow<A, B>
514{
515public:
516 SetInRel(Function<A,B> &func) : func(func) { }
517 std::pair<A,B> Subset(I i) const
518 {
519 A a = A::Index(i);
520 return std::make_pair(a, func.Index(a));
521 }
522 bool Inside(A a, B b) const
523 {
524 return func.Index(a)==b;
525 }
526private:
527 Function<A,B> &func;
528};
529
530template<class A, class B, class I>
531class ConcreteRelCategoryArrow : public Function<A,B>
532{
533public:
534 ConcreteRelCategoryArrow(Rel<I>::Arrow<A,B> &arr) : arr(arr) { }
535 B Index(A a) const
536 {
537 for(int i=0;i<arr.Size();i++)
538 {
539 if (a==arr.Subset(i).first)
540 return arr.Subset(i).second;
541 }
542 return B();
543 }
544private:
545 Rel<I>::Arrow<A,B> &arr;
546};
547#endif
P func(int c, EveryApi &ev)
Definition test.cpp:59
void Print(CubeListObject &cube)
Definition Category.cc:92
void cube(Matrix m, FaceStore &s)
Definition Functions.cc:10
bool Inside(Rect r, Point2d p)
Definition Layout.hh:46
Definition EffectI.hh:22
Definition Effect.hh:245
Definition GraphI.hh:826
void Init()
Definition Category.cc:47
CategoryEffect(Render *r)
Definition Category.hh:438
bool Frame(float time)
Definition Category.cc:54
Definition Category.hh:343
void doit()
Definition Category.hh:345
Definition Category.hh:386
void doit()
Definition Category.hh:388
static unsigned int ColorCube(float x, float y, float z, float sizex, float sizey, float sizez)
Definition VectorTools.hh:478
Definition GraphI.hh:1188
Definition Category.hh:337
void doit()
Definition Category.hh:339
Definition Category.hh:369
void doit()
Definition Category.hh:371
Definition Category.hh:355
void doit()
Definition Category.hh:357
Definition Category.hh:324
void doit()
Definition Category.hh:326
Definition Category.hh:411
void doit()
Definition Category.hh:413
Definition Category.hh:269
Definition EffectI.hh:212
FrameAnim(Render *render)
Definition Effect.hh:110
Definition EffectI.hh:11
virtual B Index(A a) const =0
Definition Graph.hh:4385
void Init()
Definition Graph.hh:4387
Definition Category.hh:287
void doit()
Definition Category.hh:289
Definition Graph.hh:4785
void Gen()
Definition Graph.hh:4788
Definition VectorTools.hh:279
static Matrix Translate(float x, float y, float z)
Definition VectorTools.cc:547
static Matrix Identity()
Definition VectorTools.cc:487
static Matrix Scale(float x, float y, float z)
Definition VectorTools.cc:556
Definition Effect.hh:1305
Definition Effect.hh:9514
Definition Category.hh:313
void doit()
Definition Category.hh:315
Definition Graph.hh:4033
Definition Category.hh:273
void doit()
Definition Category.hh:275
Definition Effect.hh:1083
Definition Effect.hh:10694
Definition VectorTools.hh:125
Definition Category.hh:424
void doit()
Definition Category.hh:426
Definition Category.hh:302
void doit()
Definition Category.hh:304
Definition VolumeObjects.hh:130
Definition Category.hh:399
void doit()
Definition Category.hh:401
Definition GraphI.hh:1131
n< br > font size
Definition meshpage.php:3536
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
ArrayObject()
Definition Category.hh:105
Array< I, T > * array
Definition Category.hh:106
BitmapObject()
Definition Category.hh:125
Bitmap< T > * bitmap
Definition Category.hh:126
Definition Category.hh:59
bool b
Definition Category.hh:60
Definition Category.hh:67
unsigned int color
Definition Category.hh:68
ContinuousVoxel< T > * voxel
Definition Category.hh:138
ContinuousVoxelObject()
Definition Category.hh:137
Definition Graph.hh:4410
int y
Definition Graph.hh:4412
int x
Definition Graph.hh:4411
int z
Definition Graph.hh:4413
Definition Category.hh:185
void doit()
Definition Category.hh:186
Definition Category.hh:149
Array< int, Cube2 > * array
Definition Category.hh:151
CubeListObject()
Definition Category.hh:150
Definition Category.hh:145
Cube2 cube
Definition Category.hh:146
Definition Category.hh:115
std::vector< FaceCollection * > vec
Definition Category.hh:116
FaceCollectionObject()
Definition Category.hh:111
FaceCollection * obj
Definition Category.hh:112
Definition Category.hh:87
float num
Definition Category.hh:88
Function< I, T > * func
Definition Category.hh:100
FunctionObject()
Definition Category.hh:99
Definition Category.hh:223
void doit()
Definition Category.hh:224
Definition Category.hh:83
int num
Definition Category.hh:84
Definition Category.hh:119
std::vector< int > vec
Definition Category.hh:120
Definition Category.hh:79
int num
Definition Category.hh:80
Definition Category.hh:257
void doit()
Definition Category.hh:258
Definition Category.hh:71
int num
Definition Category.hh:72
Definition Category.hh:209
void doit()
Definition Category.hh:210
Definition Category.hh:195
void doit()
Definition Category.hh:196
Definition Category.hh:241
void doit()
Definition Category.hh:242
Definition Category.hh:35
Matrix m
Definition Category.hh:36
Definition Category.hh:75
int num
Definition Category.hh:76
Definition Category.hh:32
Definition Category.hh:55
Point p
Definition Category.hh:56
Definition Category.hh:39
Point p
Definition Category.hh:40
Definition Parser.cc:60
Definition Category.hh:165
Range< float > rx
Definition Category.hh:166
Range< float > ry
Definition Category.hh:167
Range< float > rz
Definition Category.hh:168
Definition Category.hh:251
void doit()
Definition Category.cc:30
Definition Category.hh:91
unsigned int color
Definition Category.hh:93
int object
Definition Category.hh:94
Matrix m
Definition Category.hh:92
Definition Category.hh:229
void doit()
Definition Category.hh:230
Definition Category.hh:49
float sx
Definition Category.hh:50
float sz
Definition Category.hh:52
float sy
Definition Category.hh:51
Definition Category.hh:43
float sx
Definition Category.hh:44
float sz
Definition Category.hh:46
float sy
Definition Category.hh:45
Definition GameApi.h:42
Definition Category.hh:171
Vector u_z
Definition Category.hh:174
Vector u_x
Definition Category.hh:172
Vector u_y
Definition Category.hh:173
Definition Category.hh:141
VBOState vbostate
Definition Category.hh:142
Definition Category.hh:63
Vector v
Definition Category.hh:64
VolumeObject * volume
Definition Category.hh:162
VolumeObjectObject()
Definition Category.hh:161
VolumePosListObject()
Definition Category.hh:156
Array< int, std::pair< VolumeObject *, Point > > * array
Definition Category.hh:157
VoxelObject()
Definition Category.hh:131
Voxel< T > * voxel
Definition Category.hh:132