GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
VolumeObjects.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 Library GNU General Public License
18// along with Polygon. If not, see <http://www.gnu.org/licenses/>.
19//
20
21
22#ifndef VOLUMEOBJECTS_HH
23#define VOLUMEOBJECTS_HH
24
25#include "VectorTools.hh"
26#include "Buffer.hh"
27#include "Effect.hh"
28#include <stdlib.h>
29#include <math.h>
30#include <string>
31#include <iostream>
32#include "Shader.hh"
33
34#if 0
35template<class T>
36class Member
37{
38public:
39 virtual bool Inside(T t) const=0;
40};
41
42template<class X, class Y>
43class FunctionMember : public Member<X>
44{
45public:
46 FunctionMember(Member<Y> &m, Function<X,Y> &f) : m(m), f(f) { }
47 bool Inside(X x) const
48 {
49 Y y = f.Index(x);
50 return m.Inside(y);
51 }
52private:
53 Member<Y> &m;
54 Function<X,Y> &f;
55};
56
57template<class X, class Y>
58class Intersection : public Member<std::pair<X,Y> >
59{
60public:
61 Intersection(Member<X> &m1, Member<Y> &m2) : m1(m1), m2(m2), f1(f1), f2(f2) { }
62 bool Inside(std::pair<X,Y> xy) const
63 {
64 X x = xy.first;
65 Y y = xy.second;
66 return m1.Inside(x) && m2.Inside(y);
67 }
68private:
69 Member<X> &m1;
70 Member<Y> &m2;
71};
72
73template<class A>
74class Diagonal : public Function<A, std::pair<A,A> >, public Member<std::pair<A,A> >
75{
76public:
77 std::pair<A,A> Index(A a) { return make_pair(a,a); }
78 bool Inside(std::pair<A,A> &aa) { return aa.first == aa.second; }
79};
80
81template<class A, class B>
82class GraphX : public Function<std::pair<A,A>, std::pair<A,B> >, public Member<std::pair<A,B> >
83{
84public:
85 GraphX(Function<A,B> &ab) : ab(ab) { }
86 std::pair<A,B> Index(std::pair<A,A> &aa)
87 {
88 return make_pair(aa.first, ab.Index(aa.second));
89 }
90 bool Inside(std::pair<A,B> p) const
91 {
92 //TODO
93 }
94private:
95 Function<A,B> &ab;
96};
97
98template<class X, class Y>
99class Equalizer : public Member<X>
100{
101public:
102 Equalizer(Function<X,Y> &f1, Function<X,Y> &f2) : g_f1(f1), g_f2(f2), i(g_f1, g_f2) { }
103 bool Inside(X x) const
104 {
105 std::pair<X,X> p = d.Index(x);
106 std::pair<X,Y> p_f = g_f1.Index(p);
107 return i.Inside(p_f);
108 }
109private:
110 Diagonal<X> d;
111 Intersection<std::pair<X,Y>, std::pair<X,Y> > i;
112 GraphX<X,Y> g_f1;
113 Graphx<X,Y> g_f2;
114};
115template<class A, class B>
116class First : public Function<std::pair<A,B>, A>
117{
118public:
119
120};
121
122#endif
124{
127};
128
130{
131public:
132 virtual bool Inside(Point v) const { return false; }
133 bool EquRel(Point p1, Point p2) { return Inside(p1)==Inside(p2); }
134 virtual float Line(Point v, Point v2) const { return 0.0; }
135 virtual Color ColorValue(Point v) const { return Color(255,255,255); }
136 virtual float Value(Point v) const { return 0.0; }
137 virtual Vector Normal(Point v) const { return Vector(0.0,0.0,0.0); }
138 virtual ~VolumeObject() { }
139#if 0
140 struct Triplet
141 {
142 O o;
143 Point p;
144 };
145 virtual Triplet InsideTriplet(Point v) const=0;
146#endif
147};
148
150{
151public:
152 Bounding_x(float x, VolumeObject *next, VolumeObject *next2) : x(x), next(next), next2(next2) { }
153 bool Inside(Point p) const
154 {
155 if (p.x < x) { return next->Inside(p); }
156 return next2->Inside(p);
157 }
158
159private:
160 float x;
161 VolumeObject *next;
162 VolumeObject *next2;
163};
165{
166public:
167 Bounding_y(float y, VolumeObject *next, VolumeObject *next2) : y(y), next(next), next2(next2) { }
168 bool Inside(Point p) const
169 {
170 if (p.y < y) { return next->Inside(p); }
171 return next2->Inside(p);
172 }
173
174private:
175 float y;
176 VolumeObject *next;
177 VolumeObject *next2;
178};
180{
181public:
182 Bounding_z(float z, VolumeObject *next, VolumeObject *next2) : z(z), next(next), next2(next2) { }
183 bool Inside(Point p) const
184 {
185 if (p.z < z) { return next->Inside(p); }
186 return next2->Inside(p);
187 }
188
189private:
190 float z;
191 VolumeObject *next;
192 VolumeObject *next2;
193};
194
196{
197public:
198 BoundingSphereVolumeObject(Point center, float radius,
199 VolumeObject *next) : center(center), radius(radius), next(next) { }
200 bool Inside(Point p) const
201 {
202 Point p2 = p;
203 p2-=Vector(center);
204 if (p2.Dist() < radius) { return next->Inside(p); }
205 return false;
206 }
207private:
208 Point center;
209 float radius;
210 VolumeObject *next;
211};
212
213
214
215class BitmapVolume; // see Graph.hh
216
218{
219public:
220 MatrixVolumeObject(VolumeObject *obj, Matrix m) : obj(obj), m(m) { }
221 virtual bool Inside(Point v) const {
222 Point p = v*m;
223 return obj->Inside(p);
224 }
225 virtual float Line(Point v, Point v2) const {
226 Point p1 = v*m;
227 Point p2 = v2*m;
228 return obj->Line(p1,p2);
229 }
230 virtual Color ColorValue(Point v) const {
231 Point p = v*m;
232 return obj->ColorValue(p);
233 }
234 virtual float Value(Point v) const {
235 Point p = v*m;
236 return obj->Value(p);
237 }
238 virtual Vector Normal(Point v) const {
239 Point p=v*m;
240 return obj->Normal(p);
241 }
242private:
243 VolumeObject *obj;
244 Matrix m;
245};
246
247class FloatVolumeObject {
248public:
249 virtual float FloatValue(Point p) const=0;
250 virtual Vector FloatNormal(Point p) const; // uses partial derivatives
251 virtual ~FloatVolumeObject() { }
252};
253
255{
256public:
257 LightFloatVolume(float dist) :dist(dist){ }
258 float FloatValue(Point p) const
259 {
260 float d = sqrt(p.x*p.x+p.y*p.y+p.z*p.z);
261 float di = (dist-d)/dist;
262 if (di>1.0) di=1.0;
263 if (di<0.0) di=0.0;
264 return di;
265 }
266private:
267 float dist;
268};
269
271{
272public:
273 JuliaFloatVolumeObject(Point2d c, float limit) : c(c),limit(limit) { }
274 float FloatValue(Point x) const;
275private:
276 Point2d c;
277 float limit;
278};
279
281{
282public:
283 MandelbrotFloatVolumeObject(Point2d x, float limit) : x(x),limit(limit) { }
284 float FloatValue(Point c) const;
285private:
286 Point2d x;
287 float limit;
288};
289
290
291
293{
294public:
295 MinDistFloatVolume(Curve<Point> &curve) : curve(curve) { }
296 float FloatValue(Point p) const
297 {
298 ClosestDistanceFromCurve::DistRes res = closest.MinDistanceFromCurve(curve, p);
299 return res.distance;
300 }
301private:
302 Curve<Point> &curve;
304};
305
307public:
308 virtual unsigned int ColorValue(Point p) const=0;
309 virtual ~ColorVolumeObject() { }
310};
311
313public:
314 virtual Vector VectorValue(Point p) const=0;
316};
317
319public:
321 : f1(f1), f2(f2) { }
322 virtual float FloatValue(Point p) const
323 {
324 return std::min(f1->FloatValue(p), f2->FloatValue(p));
325 }
326private:
327 FloatVolumeObject *f1, *f2;
328};
329
330
332public:
335 virtual float FloatValue(Point p) const
336 {
337 return f1->FloatValue(p)+f2->FloatValue(p);
338 }
339private:
340 FloatVolumeObject *f1, *f2;
341};
342
343
345public:
347 float dx, float dy, float dz) : next(next),
348 dx(dx), dy(dy), dz(dz) { }
349 virtual float FloatValue(Point p) const
350 {
351 p-=Vector(dx,dy,dz);
352 return next->FloatValue(p);
353 }
354private:
355 FloatVolumeObject *next;
356 float dx,dy,dz;
357};
358
360public:
362 : f1(f1), f2(f2) { }
363 virtual float FloatValue(Point p) const
364 {
365 return std::max(f1->FloatValue(p), f2->FloatValue(p));
366 }
367private:
368 FloatVolumeObject *f1, *f2;
369};
370
372{
373public:
374 SubVolume(FloatVolumeObject &obj, float start_range, float end_range) : obj(obj), start_range(start_range), end_range(end_range) { }
375 virtual bool Inside(Point v) const {
376 float val = obj.FloatValue(v);
377 return val>=start_range && val<=end_range;
378 }
379
380private:
381 FloatVolumeObject &obj;
382 float start_range;
383 float end_range;
384};
385
386
387
388
390{
391public:
392 virtual bool Inside(Point p, float time) const=0;
393};
394
396{
397public:
398 VolumeObjectFunction(const VolumeObject &next, Function<Point,Point> &f) : next(next), f(f) { }
399 virtual bool Inside(Point v) const
400 {
401 return next.Inside(f.Index(v));
402 }
404 {
405 return next.ColorValue(f.Index(v));
406 }
407
408private:
409 const VolumeObject &next;
411};
412
413template<class T>
414class VolumeObjectFunction2 : public Function<T, bool>
415{
416public:
418 bool Index(T t) const
419 {
420 return v.Inside(f.Index(t));
421 }
422private:
424 VolumeObject &v;
425};
426
428{
429public:
430 ColorCubeVolume(VolumeObject *next_) : next(next_) { }
431 bool Inside(Point v) const { return next->Inside(v); }
432 float Line(Point v, Point v2) const { return next->Line(v,v2); }
433 virtual Vector Normal(Point v) const { return next->Normal(v); }
435 {
436 Color c;
437 c.r = int(v.x*255.0);
438 c.g = int(v.y*255.0);
439 c.b = int(v.z*255.0);
440 return c;
441 }
442private:
443 VolumeObject *next;
444};
445
446#if 0
447class SphereSurfaceVolume : public VolumeObject
448{
449public:
450 SphereSurfaceVolume(Point origo, float radius, float gap) : origo(origo), radius(radius),gap(gap) { }
451 bool Inside(Point v) const
452 {
453 v-=origo;
454 float d = v.Dist();
455 if (d>radius-gap && d <radius+gap)
456 {
457 return true;
458 }
459 return false;
460 }
461private:
462 Point origo;
463 float radius;
464 float gap;
465};
466#endif
467
468//#if 0
470{
471public:
472 SphereVolume(Point origo, float radius);
473 bool Inside(Point v) const ;
474 float Line(Point v, Point v2) const;
475 Vector Normal(Point v) const;
476
478
479 struct R_p // equivalence relation from sets for mathematics
480 {
483 bool b;
484 };
485#if 0
486 virtual Triplet InsideTriplet(Point v) const
487 {
488 Triplet t;
489 t.o = o;
490 t.p = v;
491 return t;
492 }
493#endif
494private:
495 float radius;
496 float radius_x_radius;
497 Point origo;
498#if 0
499 O o;
500#endif
501};
502//#endif
504{
505public:
506 ConeVolume(const Point &pos, const Vector &line, float rad1, float rad2);
507 bool Inside(Point v) const;
508 Vector Normal(Point v) const;
509
510 struct U
511 {
512 float line;
513 float alfa;
514 float r;
515 };
516 Point Part(const U &u);
517private:
518 Point pos;
519 Vector line;
520 float rad1;
521 float rad2;
522};
523
525{
526public:
527 CubeVolume(float minx, float maxx,
528 float miny, float maxy,
529 float minz, float maxz)
530 : minx(minx), maxx(maxx),
531 miny(miny), maxy(maxy),
532 minz(minz), maxz(maxz) { }
533
534 bool Inside(Point p) const
535 {
536 if (p.x<minx || p.x>maxx) return false;
537 if (p.y<miny || p.y>maxy) return false;
538 if (p.z<minz || p.z>maxz) return false;
539 return true;
540 }
541
542private:
543 float minx, maxx;
544 float miny, maxy;
545 float minz, maxz;
546};
547
548
550{
551public:
552 SphereTextureVolume(const VolumeObject &next, const BufferRef &texture, const Point &center, float multx, float multy) : centerreq(center), multx(multx), multy(multy), next(&next) { }
553 float Value(Point v) const { return next->Value(v); }
554 bool Inside(Point v) const { return next->Inside(v); }
555 virtual Vector Normal(Point v) const { return next->Normal(v); }
556
558 {
559 Point center = centerreq;
560 float x=p.x-center.x, y=p.y -center.y, z=p.z-center.z;
561 float r = sqrtf(x*x+y*y+z*z);
562 float alfa = acosf(z/r);
563 float beta = atan2f(y,x);
564 //
565
566 int tx = int(alfa/3.14159*(texture.width)*multx);
567 int ty = int((3.14159+beta)/3.14159/2.0*(texture.height)*multy);
568 tx %= texture.width;
569 ty %= texture.height;
570 //if (tx > texture->width) tx = 0;
571 //if (ty > texture->height) ty = 0;
572 //if (tx < 0) tx = 0;
573 //if (ty < 0) ty = 0;
574 unsigned int color = texture.buffer[tx+ty*texture.ydelta];
575 return Color(color);
576
577 }
578private:
579 mutable BufferRef texture;
580 const Point &centerreq;
581 float multx, multy;
582 const VolumeObject *next;
583};
584
586{
587public:
588 ColorMixVolume(const VolumeObject &t, const VolumeObject &k) : t(&t), k(&k) { }
589 bool Inside(Point v) const
590 {
591 return t->Inside(v);
592 }
594 {
595 Color ct = t->ColorValue(v);
596 Color ck = k->ColorValue(v);
597 unsigned int comb = Color::PixelCombine(ct.Pixel(),ck.Pixel());
598 return Color(comb);
599 }
600private:
601 const VolumeObject *t;
602 const VolumeObject *k;
603};
604
606{
607public:
608 ColorSumVolume(const VolumeObject &t, const VolumeObject &k) : t(&t), k(&k) { }
609 bool Inside(Point v) const
610 {
611 return t->Inside(v);
612 }
614 {
615 Color ct = t->ColorValue(v);
616 Color ck = k->ColorValue(v);
617 //unsigned int comb = Color::PixelCombine(ct.Pixel(),ck.Pixel());
618 Color c;
619 c.r = ct.r + ck.r;
620 c.g = ct.g + ck.g;
621 c.b = ct.b + ck.b;
622 if (c.r > 255) c.r = 255;
623 if (c.g > 255) c.g = 255;
624 if (c.b > 255) c.b = 255;
625 return c;
626 }
627private:
628 const VolumeObject *t;
629 const VolumeObject *k;
630};
631
632
634{
635public:
636 AndVolume(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
637 bool Inside(Point v) const
638 {
639 return tt.Inside(v) && kk.Inside(v);
640 }
642 {
643 return tt.ColorValue(v);
644 }
645
646private:
647 VolumeObject &tt;
648 VolumeObject &kk;
649};
650
652{
653public:
654 AndNotVolume(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
655 bool Inside(Point v) const
656 {
657 return tt.Inside(v) && !kk.Inside(v);
658 }
660 {
661 if (tt.Inside(v-Vector(0.0,0.0,0.01)))
662 return kk.ColorValue(v);
663 return tt.ColorValue(v);
664 }
666 {
667 if (tt.Inside(v-Vector(0.0,0.0,0.01)))
668 return -kk.Normal(v);
669 return tt.Normal(v);
670 }
671
672private:
673 VolumeObject &tt;
674 VolumeObject &kk;
675};
676
677
679{
680public:
681 NotVolume(VolumeObject &t) : tt(t) { }
682 bool Inside(Point v) const
683 {
684 return !tt.Inside(v);
685 }
687 {
688 return tt.ColorValue(v);
689 }
690private:
691 VolumeObject &tt;
692};
693
694
696{
697public:
698 ImplyVolume(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
699 bool Inside(Point v) const
700 {
701 bool b1 = tt.Inside(v);
702 bool b2 = kk.Inside(v);
703 if (b1 && b2) return true;
704 if (b1 && !b2) return false;
705 if (!b1 && b2) return true;
706 if (!b1 && !b2) return true;
707 return false;
708 }
710 {
711 return tt.ColorValue(v);
712 }
713private:
714 VolumeObject &tt;
715 VolumeObject &kk;
716};
717
719{
720public:
721 EquivalenceVolume(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
722 bool Inside(Point v) const
723 {
724 bool b1 = tt.Inside(v);
725 bool b2 = kk.Inside(v);
726 if (b1 && b2) return true;
727 if (b1 && !b2) return false;
728 if (!b1 && b2) return false;
729 if (!b1 && !b2) return true;
730 return false;
731 }
733 {
734 return tt.ColorValue(v);
735 }
736private:
737 VolumeObject &tt;
738 VolumeObject &kk;
739};
740
741
742
743class OrVolume : public VolumeObject
744{
745public:
746 OrVolume(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
747 bool Inside(Point v) const
748 {
749 return tt.Inside(v) || kk.Inside(v);
750 }
751 virtual Vector Normal(Point v) const
752 {
753 if (tt.Inside(v))
754 {
755 return tt.Normal(v);
756 }
757 else
758 {
759 return kk.Normal(v);
760 }
761 }
762 float Line(Point p, Point p2) const
763 {
764 float f1 = tt.Line(p,p2);
765 float f2 = kk.Line(p,p2);
766 if (f1 < 0.0) f1 = 0.0002;
767 if (f2 < 0.0) f2 = 0.0002;
768 if (f1 < 0.0001) return f2;
769 if (f2 < 0.0001) return f1;
770 return f2 < f1 ? f2 : f1;
771 }
772
774 {
775 if (tt.Inside(v) && kk.Inside(v))
776 {
777 Color tc = tt.ColorValue(v);
778 Color kc = kk.ColorValue(v);
779 tc.r += kc.r;
780 tc.b += kc.b;
781 tc.g += kc.g;
782 tc.r /= 2;
783 tc.g /= 2;
784 tc.b /= 2;
785 return tc;
786 }
787 else
788 if (tt.Inside(v))
789 {
790 return tt.ColorValue(v);
791 }
792 else if (kk.Inside(v))
793 {
794 return kk.ColorValue(v);
795 }
796 else
797 {
798 return Color(int(128.0*v.x),int(128.0*v.y),int(128.0*v.z));
799 }
800
801 }
802private:
803 VolumeObject &tt;
804 VolumeObject &kk;
805};
806
807#if 0
808class OrVolumeArray : public VolumeObject
809{
810public:
811 OrVolumeArray(VolumeObject *array, int size) : array(array), size(size) {}
812
813private:
814 VolumeObject *array;
815 int size;
816};
817#endif
818
820{
821public:
822 ColorSpecVolume(VolumeObject &val_, Color c_) : c(c_), val(val_) { }
823 ColorSpecVolume(VolumeObject &val_, int r, int g, int b) : c(r,g,b), val(val_) { }
824 Color ColorValue(Point /*v*/) const { return c; }
825 float Value(Point v) const { return val.Value(v); }
826 bool Inside(Point v) const { return val.Inside(v); }
827 float Line(Point v, Point v2) const { return val.Line(v,v2); }
828 Color LineColor(Point v, Point v2) const { return c; }
829 virtual Vector Normal(Point v) const { return val.Normal(v); }
830
831private:
832 Color c;
833 VolumeObject &val;
834};
835template<class T>
837{
838public:
839 MoveVolume() : origo(Vector(0.0,0.0,0.0)), next(0) { }
840 MoveVolume(T &next_, Vector origo_) : origo(origo_), next(&next_) { }
841 MoveVolume(T &next_, float x, float y, float z) : origo(x,y,z), next(&next_) { }
842 void SetT(T &next_) { next = &next_; }
843 void SetOrigo(Vector v) { origo = v; }
844 bool Inside(Point p) const
845 {
846 //p = (-origo).ApplyPoint(p);
847 p.x -= origo.dx;
848 p.y -= origo.dy;
849 p.z -= origo.dz;
850 return next->Inside(p);
851 }
852 float Value(Point p) const
853 {
854 //p = (-origo).ApplyPoint(p);
855 p.x -= origo.dx;
856 p.y -= origo.dy;
857 p.z -= origo.dz;
858 return next->Value(p);
859 }
861 {
862 p.x -= origo.dx;
863 p.y -= origo.dy;
864 p.z -= origo.dz;
865 return next->ColorValue(p);
866 }
867private:
868 Vector origo;
869 T *next;
870};
871
873{
874public:
875 ScaleVolume(VolumeObject *next_, float scale_x, float scale_y, float scale_z) : next(next_), scale_x(scale_x), scale_y(scale_y), scale_z(scale_z) { }
876 bool Inside(Point p) const
877 {
878 p.x /= scale_x;
879 p.y /= scale_y;
880 p.z /= scale_z;
881 return next->Inside(p);
882 }
883 float Value(Point p) const
884 {
885 p.x /= scale_x;
886 p.y /= scale_y;
887 p.z /= scale_z;
888 return next->Value(p);
889 }
891 {
892 p.x /= scale_x;
893 p.y /= scale_y;
894 p.z /= scale_z;
895 return next->ColorValue(p);
896 }
897
898private:
899 VolumeObject *next;
900 float scale_x, scale_y, scale_z;
901};
902
903
905{
906public:
907 BoxVolume(float x1, float y1, float z1,
908 float x2, float y2, float z2) : tl(x1,y1,z1), br(x2,y2,z2) { }
909 BoxVolume(Vector top_left, Vector bottom_right) : tl(top_left), br(bottom_right) { }
910 bool Inside(Point p) const
911 {
912 if (p.x < tl.dx) return false;
913 if (p.x > br.dx) return false;
914
915 if (p.y < tl.dy) return false;
916 if (p.y > br.dy) return false;
917
918 if (p.z < tl.dz) return false;
919 if (p.z > br.dz) return false;
920 return true;
921 }
922 //float Integral(Range x, Range y, Range z)
923 //{
924 //Rectangle r;
925 //Range z;
926 //}
927
928public:
929 //Range x,y,z;
931};
932
933
935{
936public:
937 TorusVolume(Vector u_x, Vector u_y, float dist1_, float dist2_, Point center_) : plane(center_, u_x, u_y), dist1(dist1_), dist2(dist2_), center(center_) { }
938 bool Inside(Point p) const;
939
940private:
941 Plane plane;
942 float dist1; // defines dist of 1st circle from origo
943 float dist2; // torus dist
944 Point center;
945};
946
948{
949public:
950 Y_Accel(FaceCollection *coll, float y_0, float y_1, int count) : coll(coll), y_0(y_0), y_1(y_1), count(count) { }
951
952 void process()
953 {
954 vec.resize(count);
955 int s = coll->NumFaces();
956 for(int i=0;i<s;i++) {
957 Point p1 = coll->FacePoint(i,0);
958 Point p2 = coll->FacePoint(i,1);
959 Point p3 = coll->FacePoint(i,2);
960 Point p4 = coll->FacePoint(i,3 % coll->NumPoints(i));
961 float min_y = std::min(std::min(p1.y,p2.y),std::min(p3.y,p4.y));
962 float max_y = std::max(std::max(p1.y,p2.y),std::max(p3.y,p4.y));
963
964 float y = y_0;
965 float d = y_1-y_0;
966 for(int j=0;j<count;j++,y+=d) {
967 if (max_y>y) continue;
968 if (min_y<y+d) continue;
969 vec[j].push_back(i);
970 }
971 }
972 }
973 std::vector<int> *optimized_faces(float y) const {
974 float pos = y-y_0;
975 pos/=(y_1-y_0);
976 if (pos<0) pos=-pos;
977 int val = int(pos);
978 if (val>=0 && val<vec.size()) return &vec[val];
979 return &empty;
980 }
981private:
982 FaceCollection *coll;
983 float y_0;
984 float y_1;
985 int count;
986 mutable std::vector<std::vector<int> > vec;
987 mutable std::vector<int> empty;
988};
989
990
991#if 0
992class FaceCollectionVolume : public VolumeObject
993{
994public:
995 FaceCollectionVolume(FaceCollection *coll, Point p) : coll(coll),pp(p), accel(coll,-300.0, -290.0, 60) { accel.process(); }
996 bool Inside(Point p) const;
997private:
998 FaceCollection *coll;
999 Point pp;
1000 Y_Accel accel;
1001};
1002#endif
1003
1005{
1006public:
1007 Random() /*: seed1(555), seed2(999)*/ { }
1008 unsigned int next() { return rand(); /*seed1 += seed2; seed2 = seed1; return seed1 >> 16;*/ }
1009 float next_float() { float v = float(next())/float(maximum()); return v; }
1010 unsigned int maximum() { return RAND_MAX; /*return 0xffff;*/ }
1011private:
1012 //unsigned int seed1, seed2;
1013};
1014
1016{
1017public:
1018 RandomPointsInBox(int num, Point p, float x, float y, float z) : num(num),p(p), x(x), y(y), z(z) { }
1019
1020 int Size() const { return num; }
1021 Point Index(int i) const
1022 {
1023 Random r;
1024 float xp = double(r.next())/r.maximum()*x + p.x;
1025 float yp = double(r.next())/r.maximum()*y + p.y;
1026 float zp = double(r.next())/r.maximum()*z + p.z;
1027 return Point(xp,yp,zp);
1028 }
1029private:
1030 int num;
1031 Point p;
1032 float x,y,z;
1033};
1034
1036{
1037public:
1038 RandomVolumePolys(VolumeObject &vol, PointCollection &coll, int numfaces, Point p, float x, float y, float z) : vol(vol), coll(coll), numfaces(numfaces), p(p), x(x),y(y),z(z), facem(-999) { }
1039 void SetBox(Matrix m) { }
1040 virtual int NumFaces() const { return numfaces; }
1041 virtual int NumPoints(int face) const { return 3; }
1042 virtual Point FacePoint(int face, int point) const
1043 {
1044 if (face==facem)
1045 {
1046 return pointm_ + (coll.Index(point)*Matrix::XRotation(xrot)*Matrix::YRotation(yrot)*Matrix::ZRotation(zrot));
1047 }
1048
1049 while(1)
1050 {
1051 Random r;
1052 float xp = double(r.next())/r.maximum()*x + p.x;
1053 float yp = double(r.next())/r.maximum()*y + p.y;
1054 float zp = double(r.next())/r.maximum()*z + p.z;
1055 xrot = double(r.next())/r.maximum()*2.0*3.14159;
1056 yrot = double(r.next())/r.maximum()*2.0*3.14159;
1057 zrot = double(r.next())/r.maximum()*2.0*3.14159;
1058 pointm_ = Point(xp,yp,zp);
1059 if (vol.Inside(pointm_))
1060 break;
1061 }
1062 facem = face;
1063 pointm = point;
1064
1065 return pointm_ + (coll.Index(point)*Matrix::XRotation(xrot)*Matrix::YRotation(yrot)*Matrix::ZRotation(zrot));
1066 }
1067 virtual unsigned int Color(int face, int point) const
1068 {
1069 return Color::White().Pixel();
1070 }
1071 virtual Point2d TexCoord(int face, int point) const
1072 {
1073 Point2d p;
1074 p.x = 0;
1075 p.y = 0;
1076 return p;
1077 }
1078
1079 virtual Vector PointNormal(int face, int point) const
1080 {
1081 FacePoint(face,point);
1082 Point pa = coll.Index(0);
1083 Point pb = coll.Index(1);
1084 Point pc = coll.Index(2);
1085 Vector v = pb-pa;
1086 Vector v2 = pc-pa;
1088 }
1089 virtual int AttribI(int face, int point, int id) const
1090 {
1091 return 0;
1092 }
1093 virtual float Attrib(int face, int point, int id) const
1094 {
1095 FacePoint(face,point);
1096 Point p = pointm_;
1097 switch(id)
1098 {
1099 case AttrCenterX: return p.x;
1100 case AttrCenterY: return p.y;
1101 case AttrCenterZ: return p.z;
1102 }
1103 return 0.0;
1104 }
1105private:
1106 VolumeObject &vol;
1107 PointCollection &coll;
1108 int numfaces;
1109 Point p;
1110 float x,y,z;
1111 mutable int facem, pointm;
1112 mutable Point pointm_;
1113 mutable float xrot, yrot, zrot;
1114};
1115
1117{
1118public:
1119 MandelBulb(float n, Point p, Point center, float radius, int iterations) : n(n), p(p), sp(center,radius), iterations(iterations) { }
1120 bool Inside(Point C) const;
1121 Color ColorValue(Point C) const;
1122private:
1123 static Point Step(Point w);
1124 float n;
1125 Point p;
1126 SphereVolume sp;
1127 int iterations;
1128 int current_iteration_count;
1129};
1130
1132{
1133public:
1134 VolumeEffect(Render *r);
1135 ~VolumeEffect();
1136 void Init();
1137 bool Frame(float time);
1138private:
1139 VBOState vbostate;
1140 DiscardPiece discard;
1141 GouraudPiece gouraud;
1142 PieceShader piece;
1143};
1144
1146{
1147public:
1149 void Init();
1150 bool Frame(float time);
1151 //VBOState vbostate;
1153};
1154
1155
1156#endif
@ AttrCenterZ
Definition Effect.hh:74
@ AttrCenterY
Definition Effect.hh:73
@ AttrCenterX
Definition Effect.hh:72
GameApi::ML part(GameApi::EveryApi &ev, GameApi::ML ml, float x_trans, float y_rot, int x, int y, int mode=0)
Definition GameApi.cc:38016
size dy
Definition GameApi_gui.cc:1727
bool Inside(Rect r, Point2d p)
Definition Layout.hh:46
AK empty(int sx, int sy, int sz, float start_x, float end_x, float start_y, float end_y, float start_z, float end_z)
Definition accel.cc:723
AndNotVolume(VolumeObject &t, VolumeObject &k)
Definition VolumeObjects.hh:654
bool Inside(Point v) const
Definition VolumeObjects.hh:655
Color ColorValue(Point v) const
Definition VolumeObjects.hh:659
Vector Normal(Point v) const
Definition VolumeObjects.hh:665
AndVolume(VolumeObject &t, VolumeObject &k)
Definition VolumeObjects.hh:636
bool Inside(Point v) const
Definition VolumeObjects.hh:637
Color ColorValue(Point v) const
Definition VolumeObjects.hh:641
Definition Graph.hh:8379
BoundingSphereVolumeObject(Point center, float radius, VolumeObject *next)
Definition VolumeObjects.hh:198
bool Inside(Point p) const
Definition VolumeObjects.hh:200
bool Inside(Point p) const
Definition VolumeObjects.hh:153
Bounding_x(float x, VolumeObject *next, VolumeObject *next2)
Definition VolumeObjects.hh:152
bool Inside(Point p) const
Definition VolumeObjects.hh:168
Bounding_y(float y, VolumeObject *next, VolumeObject *next2)
Definition VolumeObjects.hh:167
bool Inside(Point p) const
Definition VolumeObjects.hh:183
Bounding_z(float z, VolumeObject *next, VolumeObject *next2)
Definition VolumeObjects.hh:182
BoxVolume(float x1, float y1, float z1, float x2, float y2, float z2)
Definition VolumeObjects.hh:907
BoxVolume(Vector top_left, Vector bottom_right)
Definition VolumeObjects.hh:909
bool Inside(Point p) const
Definition VolumeObjects.hh:910
Vector br
Definition VolumeObjects.hh:930
Vector tl
Definition VolumeObjects.hh:930
Definition Effect.hh:67
Definition Effect.hh:10220
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:433
bool Inside(Point v) const
Definition VolumeObjects.hh:431
ColorCubeVolume(VolumeObject *next_)
Definition VolumeObjects.hh:430
float Line(Point v, Point v2) const
Definition VolumeObjects.hh:432
Color ColorValue(Point v) const
Definition VolumeObjects.hh:434
ColorMixVolume(const VolumeObject &t, const VolumeObject &k)
Definition VolumeObjects.hh:588
bool Inside(Point v) const
Definition VolumeObjects.hh:589
Color ColorValue(Point v) const
Definition VolumeObjects.hh:593
Color ColorValue(Point) const
Definition VolumeObjects.hh:824
Color LineColor(Point v, Point v2) const
Definition VolumeObjects.hh:828
float Line(Point v, Point v2) const
Definition VolumeObjects.hh:827
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:829
bool Inside(Point v) const
Definition VolumeObjects.hh:826
float Value(Point v) const
Definition VolumeObjects.hh:825
ColorSpecVolume(VolumeObject &val_, Color c_)
Definition VolumeObjects.hh:822
ColorSpecVolume(VolumeObject &val_, int r, int g, int b)
Definition VolumeObjects.hh:823
ColorSumVolume(const VolumeObject &t, const VolumeObject &k)
Definition VolumeObjects.hh:608
bool Inside(Point v) const
Definition VolumeObjects.hh:609
Color ColorValue(Point v) const
Definition VolumeObjects.hh:613
Definition VolumeObjects.hh:306
virtual unsigned int ColorValue(Point p) const =0
virtual ~ColorVolumeObject()
Definition VolumeObjects.hh:309
Definition VectorTools.hh:380
unsigned int Pixel()
Definition VectorTools.hh:426
int r
Definition VectorTools.hh:744
int g
Definition VectorTools.hh:744
static Color White()
Definition VectorTools.hh:476
static unsigned int PixelCombine(unsigned int pixel1, unsigned int pixel2)
Definition VectorTools.hh:449
int b
Definition VectorTools.hh:744
bool Inside(Point v) const
Definition VolumeObjects.cc:84
Point Part(const U &u)
Definition VolumeObjects.cc:97
Vector Normal(Point v) const
Definition VolumeObjects.cc:104
ConeVolume(const Point &pos, const Vector &line, float rad1, float rad2)
Definition VolumeObjects.cc:80
CubeVolume(float minx, float maxx, float miny, float maxy, float minz, float maxz)
Definition VolumeObjects.hh:527
bool Inside(Point p) const
Definition VolumeObjects.hh:534
Definition EffectI.hh:30
Definition Equalizer.hh:2138
std::pair< K, K > Index(T t) const
Definition Equalizer.hh:2141
Definition Shader.hh:595
Definition Equalizer.hh:575
Equalizer(Compare< B > &comp, Function< A, B > &f1, Function< A, B > &f2)
Definition Equalizer.hh:577
EquivalenceVolume(VolumeObject &t, VolumeObject &k)
Definition VolumeObjects.hh:721
Color ColorValue(Point v) const
Definition VolumeObjects.hh:732
bool Inside(Point v) const
Definition VolumeObjects.hh:722
Definition EffectI.hh:212
Definition FloatVolumeObject.hh:11
virtual ~FloatVolumeObject()
Definition VolumeObjects.hh:251
virtual float FloatValue(Point p) const =0
virtual Vector FloatNormal(Point p) const
Definition VolumeObjects.cc:376
void Init()
Definition VolumeObjects.cc:293
FractalEffect(Render *r)
Definition VolumeObjects.hh:1148
RenderState vbostate
Definition VolumeObjects.hh:1152
bool Frame(float time)
Definition VolumeObjects.cc:330
FrameAnim(Render *render)
Definition Effect.hh:110
Definition EffectI.hh:11
virtual B Index(A a) const =0
Definition Shader.hh:340
Color ColorValue(Point v) const
Definition VolumeObjects.hh:709
bool Inside(Point v) const
Definition VolumeObjects.hh:699
ImplyVolume(VolumeObject &t, VolumeObject &k)
Definition VolumeObjects.hh:698
Definition Equalizer.hh:478
Intersection(PowerSet< A > &m, PowerSet< A > &m2)
Definition Equalizer.hh:480
JuliaFloatVolumeObject(Point2d c, float limit)
Definition VolumeObjects.hh:273
float FloatValue(Point x) const
Definition VolumeObjects.cc:392
float FloatValue(Point p) const
Definition VolumeObjects.hh:258
LightFloatVolume(float dist)
Definition VolumeObjects.hh:257
Color ColorValue(Point C) const
Definition VolumeObjects.cc:225
MandelBulb(float n, Point p, Point center, float radius, int iterations)
Definition VolumeObjects.hh:1119
bool Inside(Point C) const
Definition VolumeObjects.cc:257
float FloatValue(Point c) const
Definition VolumeObjects.cc:429
MandelbrotFloatVolumeObject(Point2d x, float limit)
Definition VolumeObjects.hh:283
virtual float Value(Point v) const
Definition VolumeObjects.hh:234
virtual float Line(Point v, Point v2) const
Definition VolumeObjects.hh:225
virtual bool Inside(Point v) const
Definition VolumeObjects.hh:221
virtual Color ColorValue(Point v) const
Definition VolumeObjects.hh:230
MatrixVolumeObject(VolumeObject *obj, Matrix m)
Definition VolumeObjects.hh:220
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:238
Definition VectorTools.hh:279
static Matrix XRotation(float rot)
Definition VectorTools.cc:498
static Matrix YRotation(float rot)
Definition VectorTools.cc:526
static Matrix ZRotation(float rot)
Definition VectorTools.cc:537
MaxFloatVolumeObject(FloatVolumeObject *f1, FloatVolumeObject *f2)
Definition VolumeObjects.hh:361
virtual float FloatValue(Point p) const
Definition VolumeObjects.hh:363
MinDistFloatVolume(Curve< Point > &curve)
Definition VolumeObjects.hh:295
float FloatValue(Point p) const
Definition VolumeObjects.hh:296
virtual float FloatValue(Point p) const
Definition VolumeObjects.hh:322
MinFloatVolumeObject(FloatVolumeObject *f1, FloatVolumeObject *f2)
Definition VolumeObjects.hh:320
MoveFloatVolumeObject(FloatVolumeObject *next, float dx, float dy, float dz)
Definition VolumeObjects.hh:346
virtual float FloatValue(Point p) const
Definition VolumeObjects.hh:349
bool Inside(Point p) const
Definition VolumeObjects.hh:844
void SetT(T &next_)
Definition VolumeObjects.hh:842
void SetOrigo(Vector v)
Definition VolumeObjects.hh:843
float Value(Point p) const
Definition VolumeObjects.hh:852
MoveVolume(T &next_, float x, float y, float z)
Definition VolumeObjects.hh:841
MoveVolume(T &next_, Vector origo_)
Definition VolumeObjects.hh:840
MoveVolume()
Definition VolumeObjects.hh:839
Color ColorValue(Point p) const
Definition VolumeObjects.hh:860
bool Inside(Point v) const
Definition VolumeObjects.hh:682
Color ColorValue(Point v) const
Definition VolumeObjects.hh:686
NotVolume(VolumeObject &t)
Definition VolumeObjects.hh:681
OrVolume(VolumeObject &t, VolumeObject &k)
Definition VolumeObjects.hh:746
float Line(Point p, Point p2) const
Definition VolumeObjects.hh:762
bool Inside(Point v) const
Definition VolumeObjects.hh:747
Color ColorValue(Point v) const
Definition VolumeObjects.hh:773
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:751
Definition Shader.hh:1251
Definition VectorTools.hh:350
PlusFloatVolumeObject(FloatVolumeObject *f1, FloatVolumeObject *f2)
Definition VolumeObjects.hh:333
virtual float FloatValue(Point p) const
Definition VolumeObjects.hh:335
Definition Effect.hh:2456
Point Index(int i) const
Definition VolumeObjects.hh:1021
int Size() const
Definition VolumeObjects.hh:1020
RandomPointsInBox(int num, Point p, float x, float y, float z)
Definition VolumeObjects.hh:1018
virtual Point FacePoint(int face, int point) const
Definition VolumeObjects.hh:1042
virtual unsigned int Color(int face, int point) const
Definition VolumeObjects.hh:1067
virtual int AttribI(int face, int point, int id) const
Definition VolumeObjects.hh:1089
void SetBox(Matrix m)
Definition VolumeObjects.hh:1039
virtual int NumFaces() const
Definition VolumeObjects.hh:1040
virtual int NumPoints(int face) const
Definition VolumeObjects.hh:1041
RandomVolumePolys(VolumeObject &vol, PointCollection &coll, int numfaces, Point p, float x, float y, float z)
Definition VolumeObjects.hh:1038
virtual Point2d TexCoord(int face, int point) const
Definition VolumeObjects.hh:1071
virtual float Attrib(int face, int point, int id) const
Definition VolumeObjects.hh:1093
virtual Vector PointNormal(int face, int point) const
Definition VolumeObjects.hh:1079
Definition VolumeObjects.hh:1005
float next_float()
Definition VolumeObjects.hh:1009
unsigned int next()
Definition VolumeObjects.hh:1008
unsigned int maximum()
Definition VolumeObjects.hh:1010
Random()
Definition VolumeObjects.hh:1007
Definition Effect.hh:9553
Definition Effect.hh:9514
float Value(Point p) const
Definition VolumeObjects.hh:883
ScaleVolume(VolumeObject *next_, float scale_x, float scale_y, float scale_z)
Definition VolumeObjects.hh:875
bool Inside(Point p) const
Definition VolumeObjects.hh:876
Color ColorValue(Point p) const
Definition VolumeObjects.hh:890
bool Inside(Point v) const
Definition VolumeObjects.hh:554
float Value(Point v) const
Definition VolumeObjects.hh:553
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:555
SphereTextureVolume(const VolumeObject &next, const BufferRef &texture, const Point &center, float multx, float multy)
Definition VolumeObjects.hh:552
Color ColorValue(Point p) const
Definition VolumeObjects.hh:557
Definition VolumeObjects.hh:470
SphereVolume(Point origo, float radius)
Definition Common3.cc:1030
Point Part(const SphericalPoint &part)
Definition Common3.cc:1045
float Line(Point v, Point v2) const
Definition Common3.cc:1052
bool Inside(Point v) const
Definition Common3.cc:1034
Vector Normal(Point v) const
Definition Common3.cc:1040
Definition VectorTools.hh:106
Definition Equalizer.hh:1287
SubVolume(FloatVolumeObject &obj, float start_range, float end_range)
Definition VolumeObjects.hh:374
virtual bool Inside(Point v) const
Definition VolumeObjects.hh:375
Definition VolumeObjects.hh:390
virtual bool Inside(Point p, float time) const =0
bool Inside(Point p) const
Definition VolumeObjects.cc:125
TorusVolume(Vector u_x, Vector u_y, float dist1_, float dist2_, Point center_)
Definition VolumeObjects.hh:937
Definition Effect.hh:10694
Definition VolumeObjects.hh:312
virtual Vector VectorValue(Point p) const =0
virtual ~VectorVolumeObject()
Definition VolumeObjects.hh:315
Definition VectorTools.hh:125
static Vector CrossProduct(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.hh:193
~VolumeEffect()
Definition VolumeObjects.cc:152
void Init()
Definition VolumeObjects.cc:157
bool Frame(float time)
Definition VolumeObjects.cc:186
VolumeEffect(Render *r)
Definition VolumeObjects.cc:146
bool Index(T t) const
Definition VolumeObjects.hh:418
VolumeObjectFunction2(Function< T, Point > &f, VolumeObject &v)
Definition VolumeObjects.hh:417
Color ColorValue(Point v) const
Definition VolumeObjects.hh:403
VolumeObjectFunction(const VolumeObject &next, Function< Point, Point > &f)
Definition VolumeObjects.hh:398
virtual bool Inside(Point v) const
Definition VolumeObjects.hh:399
Definition VolumeObjects.hh:130
virtual bool Inside(Point v) const
Definition VolumeObjects.hh:132
virtual Vector Normal(Point v) const
Definition VolumeObjects.hh:137
virtual ~VolumeObject()
Definition VolumeObjects.hh:138
virtual float Value(Point v) const
Definition VolumeObjects.hh:136
bool EquRel(Point p1, Point p2)
Definition VolumeObjects.hh:133
virtual float Line(Point v, Point v2) const
Definition VolumeObjects.hh:134
virtual Color ColorValue(Point v) const
Definition VolumeObjects.hh:135
Y_Accel(FaceCollection *coll, float y_0, float y_1, int count)
Definition VolumeObjects.hh:950
std::vector< int > * optimized_faces(float y) const
Definition VolumeObjects.hh:973
void process()
Definition VolumeObjects.hh:952
border radius
Definition gameapi_example.php:45
background color
Definition gameapi_example.php:46
d
Definition meshpage.php:3895
n< br > font size
Definition meshpage.php:3536
void array(const std::string &type, Module &m)
Definition bootstrap.hpp:23
double f(const std::string &, double, bool) noexcept
Definition profile_cpp_calls_2.cpp:4
int f2(char c)
Definition test.cpp:51
Definition Buffer.hh:32
Definition GameApi.h:30
Definition Effect.hh:10222
float distance
Definition Effect.hh:10223
Definition VolumeObjects.hh:511
float line
Definition VolumeObjects.hh:512
float r
Definition VolumeObjects.hh:514
float alfa
Definition VolumeObjects.hh:513
Definition GameApi.h:22
Definition VectorTools.hh:910
float x
Definition VectorTools.hh:911
Definition VolumeObjects.hh:124
Point p1
Definition VolumeObjects.hh:125
Point p2
Definition VolumeObjects.hh:126
Definition Parser.cc:60
float x
Definition Parser.cc:60
float Dist() const
Definition VectorTools.cc:150
float y
Definition Parser.cc:60
float z
Definition Parser.cc:60
Definition VolumeObjects.hh:480
Point p2
Definition VolumeObjects.hh:482
Point p1
Definition VolumeObjects.hh:481
bool b
Definition VolumeObjects.hh:483
Definition GameApi.h:42
num
Definition view.php:2821