GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
RayTracing.hh
Go to the documentation of this file.
1#ifndef RAYTRACING_HH
2#define RAYTRACING_HH
3
4#include "VectorTools.hh"
5#include "Effect.hh"
6
8{
9public:
11 {
13 };
15 Point ray_p1, Point ray_p2);
16
17};
18
19
20#if 0
22 Point ray_p1, Point ray_p2)
23{
25 return p;
26#if 0
27 Plane pl(center, ray_p1-center, ray_p2-center);
28 Point2d center_2d = { pl.CoordsX(center), pl.CoordsY(center) };
29 Point2d ray_p1_2d = { pl.CoordsX(ray_p1), pl.CoordsY(ray_p1) };
30 Point2d ray_p2_2d = { pl.CoordsX(ray_p2), pl.CoordsY(ray_p2) };
31 // 2 UNKNOWN VARIABLES
32
33 Point pos;
34 pos -= center;
35 bool b = pos.Dist() < 100.0;
36
37 // use 2d plane based on center, ray_p1, ray_p2
38 // find line_line intersection point between lines:
39 // 1) center -> surface
40 // 2) ray_p1 -> ray_p2
41 // Project the coordinates to 2d first.
42
43
44 // |-----|------|
45 // check all points, determine if they're inside or outside of object
46 // 2^3 different alternatives to check
47 // Can be split to two parts:
48 // |----|, 2^2 different alternatives to check:
49 // 0 0 = split to |---|---|, split not in this section
50 // 0 1 = split in this section
51 // 1 0 = split in this section
52 // 1 1 = split not in this section
53
54 // END OF 2 UNKNOWN VARIABLES
55 Point pos2 = pl.Navigate(res);
56 IntersectionPoint ipoint;
57 ipoint.p = pos2;
58 return ipoint;
59#endif
60}
61#endif
62#if 0
63bool FindRange(bool b1, bool b2)
64{
65 if (b1 && !b2) return true;
66 if (!b1 && b2) return true;
67 return false;
68}
69
70std::pair<Range<Point>, Range<Point> > Split(Range<Point> p)
71{
72 Point p1 = p.start;
73 Point p2 = p.end;
74 Point middle = Point(0.5*Vector(p1+Vector(p2)));
75 return std::make_pair(Range<Point>(p1,middle), Range<Point>(middle,p2));
76}
77#endif
78
80#if 0
82{
83 if (level==0) return range;
84 std::pair<Range<Point>, Range<Point> > p = Split(range);
85 return FindSurface(p.first, p.second, o, level);
86}
87
89{
90 bool b1 = o.Inside(range1.start);
91 bool b2 = o.Inside(range1.end);
92 bool b3 = o.Inside(range2.start);
93 bool b4 = o.Inside(range2.end);
94 bool in_this_section1 = FindRange(b1,b2);
95 bool in_this_section2 = FindRange(b3,b4);
96 std::vector<Range<Point> > res;
97 if (in_this_section1)
98 {
99 res.push_back(Range<Point>(range1.start, range1.end));
100 }
101 if (in_this_section2)
102 {
103 res.push_back(Range<Point>(range2.start, range2.end));
104 }
105 int s = res.size();
106 float d = 10000000.0;
107 Range<Point> result;
108 if (s!=0)
109 {
110 for(int i=0;i<s;i++)
111 {
112 Range<Point> p = FindSurface(res[i],o,level-1);
113 if (Vector(p.start-range1.start).Dist()<d)
114 {
115 d = Vector(p.start-range1.start).Dist();
116 result = p;
117 }
118 }
119 }
120 else
121 {
122 Range<Point> p1 = FindSurface(range1,o, level-1);
123 if (Vector(p1.start-range1.start).Dist()<d)
124 {
125 d = Vector(p1.start-range1.start).Dist();
126 result = p1;
127 }
128 Range<Point> p2 = FindSurface(range2,o, level-1);
129 if (Vector(p2.start-range1.start).Dist()<d)
130 {
131 d = Vector(p2.start-range1.start).Dist();
132 result = p2;
133 }
134 }
135 return result;
136}
137#endif
138
140{
141public:
142 // returns negative if inside object
143 // returns positive if outside of it
144 virtual float DistanceFromSurface(Point p) const=0;
145};
146
148{
149public:
151 Vector dir)
152 : /*next(next),*/ p1(p1), p2(p2), p3(p3), p4(p4), dir(dir) { }
153
154private:
155 //VolumeSpace &next;
156 Point p1,p2,p3,p4;
157 Vector dir;
158
159};
160#endif
Point IntersectionPoint(LinePlaneIntersection &c, Point line_p1, Point line_p2)
Definition Intersect.cc:30
Range< Point > FindSurface(Range< Point > range1, Range< Point > range2, VolumeObject &o, int level)
Definition VectorTools.hh:350
QuadVolumeSpace(VolumeSpace &next, Point p1, Point p2, Point p3, Point p4, Vector dir)
Definition RayTracing.hh:150
Definition Effect.hh:1305
T end
Definition Effect.hh:1310
T start
Definition Effect.hh:1309
Definition RayTracing.hh:8
IntersectPoint Intersect(Point center, float radius, Point ray_p1, Point ray_p2)
Definition VectorTools.hh:125
float Dist() const
Definition VectorTools.cc:141
Definition VolumeObjects.hh:130
virtual bool Inside(Point v) const
Definition VolumeObjects.hh:132
Definition RayTracing.hh:140
virtual float DistanceFromSurface(Point p) const =0
border radius
Definition gameapi_example.php:45
d
Definition meshpage.php:3895
Definition VectorTools.hh:910
Definition Parser.cc:60
float Dist() const
Definition VectorTools.cc:150
Definition RayTracing.hh:11
Point p
Definition RayTracing.hh:12