GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Bitmap.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#ifndef BITMAP_HH
24#define BITMAP_HH
25
26#include "VectorTools.hh"
27#include "Buffer.hh"
28
29#if 0
30class VolumeObject
31{
32public:
33 virtual bool Inside(Point v) const { return false; }
34 bool EquRel(Point p1, Point p2) { return Inside(p1)==Inside(p2); }
35 virtual float Line(Point v, Point v2) const { return 0.0; }
36 virtual Color ColorValue(Point v) const { return Color(255,255,255); }
37 virtual float Value(Point v) const { return 0.0; }
38 virtual Vector Normal(Point v) const { return Vector(0.0,0.0,0.0); }
39 virtual ~VolumeObject() { }
40};
41
42
43class Phong : public VolumeObject
44{
45public:
46 Phong(VolumeObject &t, Point viewer, Point light, Color lightcolor, Color spec_color) : tt(t), light(light), lightcolor(lightcolor), spec_color(spec_color)
47 {
48 Vector l_p_v = Vector(viewer) + Vector(light);
49 halfway = l_p_v/l_p_v.Dist();
50 }
51 virtual bool Inside(Point v) const { return tt.Inside(v); }
52 virtual Vector Normal(Point v) const { return tt.Normal(v); }
53 virtual Color ColorValue(Point p) const
54 {
55 Vector normal = tt.Normal(p);
56 normal = normal/normal.Dist();
57 float col = Vector::DotProduct(normal, halfway);
58 float col2 = Vector::DotProduct(normal, light);
59 //col = 1.0 - col;
60 col = col*col;
61 //col = col*col;
62 //col = col*col;
63 //col = col*col;
64 //col += col2*0.5;
65 if (col < 0.0) col = 0.0;
66 if (col > 1.0) col = 1.0;
67 if (col2 < 0.0) col2 = 0.0;
68 if (col2 > 1.0) col2 = 1.0;
69 //std::cout << col << std::endl;
70 //col = col*col;
71 //col = col*col;
72 //col = col*col;
73 //col *=255.0;
74 //col2 *= 255.0;
75 Color c;
76 c.r = int(col*lightcolor.r+col2*spec_color.r);
77 c.g = int(col*lightcolor.g+col2*spec_color.g);
78 c.b = int(col*lightcolor.b+col2*spec_color.b);
79 if (c.r > 255) c.r = 255;
80 if (c.g > 255) c.g = 255;
81 if (c.b > 255) c.b = 255;
82 return c;
83 }
84
85private:
86 VolumeObject &tt;
87 Vector halfway;
88 Vector light;
89 Color lightcolor;
90 Color spec_color;
91};
92
93class Cone : public VolumeObject
94{
95public:
96 Cone(const Point &pos, const Vector &line, float rad1, float rad2);
97 bool Inside(Point v) const;
98 Vector Normal(Point v) const;
99
100 struct U
101 {
102 float line;
103 float alfa;
104 float r;
105 };
106 Point Part(const U &u);
107private:
108 Point pos;
109 Vector line;
110 float rad1;
111 float rad2;
112};
113class AndNot : public VolumeObject
114{
115public:
116 AndNot(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
117 bool Inside(Point v) const
118 {
119 return tt.Inside(v) && !kk.Inside(v);
120 }
121 Color ColorValue(Point v) const
122 {
123 if (tt.Inside(v-Vector(0.0,0.0,0.01)))
124 return kk.ColorValue(v);
125 return tt.ColorValue(v);
126 }
127 Vector Normal(Point v) const
128 {
129 if (tt.Inside(v-Vector(0.0,0.0,0.01)))
130 return -kk.Normal(v);
131 return tt.Normal(v);
132 }
133
134private:
135 VolumeObject &tt;
136 VolumeObject &kk;
137};
138
139class Or : public VolumeObject
140{
141public:
142 Or(VolumeObject &t, VolumeObject &k) : tt(t), kk(k) { }
143 bool Inside(Point v) const
144 {
145 return tt.Inside(v) || kk.Inside(v);
146 }
147 virtual Vector Normal(Point v) const
148 {
149 if (tt.Inside(v))
150 {
151 return tt.Normal(v);
152 }
153 else
154 {
155 return kk.Normal(v);
156 }
157 }
158 float Line(Point p, Point p2) const
159 {
160 float f1 = tt.Line(p,p2);
161 float f2 = kk.Line(p,p2);
162 if (f1 < 0.0) f1 = 0.0002;
163 if (f2 < 0.0) f2 = 0.0002;
164 if (f1 < 0.0001) return f2;
165 if (f2 < 0.0001) return f1;
166 return f2 < f1 ? f2 : f1;
167 }
168
169 Color ColorValue(Point v) const
170 {
171 if (tt.Inside(v) && kk.Inside(v))
172 {
173 Color tc = tt.ColorValue(v);
174 Color kc = kk.ColorValue(v);
175 tc.r += kc.r;
176 tc.b += kc.b;
177 tc.g += kc.g;
178 tc.r /= 2;
179 tc.g /= 2;
180 tc.b /= 2;
181 return tc;
182 }
183 else
184 if (tt.Inside(v))
185 {
186 return tt.ColorValue(v);
187 }
188 else if (kk.Inside(v))
189 {
190 return kk.ColorValue(v);
191 }
192 else
193 {
194 return Color(int(128.0*v.x),int(128.0*v.y),int(128.0*v.z));
195 }
196
197 }
198private:
199 VolumeObject &tt;
200 VolumeObject &kk;
201};
202
203class ColorSpec : public VolumeObject
204{
205public:
206 ColorSpec(VolumeObject &val_, Color c_) : c(c_), val(val_) { }
207 ColorSpec(VolumeObject &val_, int r, int g, int b) : c(r,g,b), val(val_) { }
208 Color ColorValue(Point /*v*/) const { return c; }
209 float Value(Point v) const { return val.Value(v); }
210 bool Inside(Point v) const { return val.Inside(v); }
211 float Line(Point v, Point v2) const { return val.Line(v,v2); }
212 Color LineColor(Point v, Point v2) const { return c; }
213 virtual Vector Normal(Point v) const { return val.Normal(v); }
214
215private:
216 Color c;
217 VolumeObject &val;
218};
219class VolumeBox : public VolumeObject
220{
221public:
222 VolumeBox(float x1, float y1, float z1,
223 float x2, float y2, float z2) : tl(x1,y1,z1), br(x2,y2,z2) { }
224 VolumeBox(Vector top_left, Vector bottom_right) : tl(top_left), br(bottom_right) { }
225 bool Inside(Point p) const
226 {
227 if (p.x < tl.dx) return false;
228 if (p.x > br.dx) return false;
229
230 if (p.y < tl.dy) return false;
231 if (p.y > br.dy) return false;
232
233 if (p.z < tl.dz) return false;
234 if (p.z > br.dz) return false;
235 return true;
236 }
237 //float Integral(Range x, Range y, Range z)
238 //{
239 //Rectangle r;
240 //Range z;
241 //}
242public:
243 //Range x,y,z;
244 Vector tl, br;
245};
246
247void RenderToBitmap(const VolumeObject &v, BufferRef bitmap);
248
249
250
251#endif
252#endif
SM Or(SM p1, SM p2)
Definition Language.hh:965
bool Inside(Rect r, Point2d p)
Definition Layout.hh:46
int r
Definition VectorTools.hh:744
int g
Definition VectorTools.hh:744
int b
Definition VectorTools.hh:744
Definition GameApi_vo.cc:1073
unsigned int ColorValue(Point p) const
Definition GameApi_vo.cc:1076
Phong(VectorVolumeObject *normal, Point lightpos, Color i_s, Color i_d, Color i_a, float k_s, float k_d, float k_a, float alfa)
Definition GameApi_vo.cc:1075
float Dist() const
Definition VectorTools.cc:141
static float DotProduct(const Vector &aVec, const Vector &aVec2)
Definition VectorTools.hh:185
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
P g(unsigned int c, EveryApi &ev)
Definition test.cpp:19
@ Normal
Definition httplib.h:3752
int f2(char c)
Definition test.cpp:51
Definition Buffer.hh:32
float x
Definition Parser.cc:60
float y
Definition Parser.cc:60
float z
Definition Parser.cc:60