GameApi 28
Library used by GameApi Builder tool
Loading...
Searching...
No Matches
Light.hh
Go to the documentation of this file.
1
2
4{
5public:
6 virtual Color Env(Vector v) const=0;
7};
8
9class LightBitmap : public Bitmap<Color>
10{
11public:
13 int sx, int sy,
14 Point p, Vector u_x, Vector u_y,
15 Point center) : sx(sx), sy(sy), env(env), p(p), u_x(u_x), u_y(u_y), center(center) { }
16 int SizeX() const { return sx; }
17 int SizeY() const { return sy; }
18 Color Map(int x, int y) const
19 {
20 Point pp = p + (float(x)/sx)*u_x + (float(y)/sy)*u_y;
21 pp -= center;
22 return env.Env(Vector(pp));
23 }
24private:
25 int sx,sy;
27 Point p;
28 Vector u_x, u_y;
29 Point center;
30};
31
33{
34public:
35 virtual Color Dist(Vector v, Vector vv) const=0;
36};
37
39{
40public:
41 RadialLightDistribution(Color c1, Color c2, float dist) : c1(c1), c2(c2), dist(dist) { }
42 Color Dist(Vector v, Vector vv) const
43 {
44 float d = Vector::Dist(v,vv);
45 d/=dist;
46 if (d>=0.0 && d<=1.0)
47 return Color::Interpolate(c1,c2,d);
48 if (d<0.0)
49 return c1;
50 return c2;
51 }
52};
53
55{
56public:
58 {
59 Node n;
60 n.vec = v/v.Dist();
61 n.color = c;
62 arr.push_back(n);
63 }
64 Color Env(Vector v) const
65 {
66 v/=v.Dist();
67 int s = arr.Size();
68 float min_dist = 100000.0;
69 Color result(255,255,255);
70 for(int i=0;i<s;i++)
71 {
72 Node n = arr.Index(i);
73 Vector vv = n.vec;
74 vv/=vv.Dist();
75 float val = Vector::Dist(vv,v);
76 if (val < min_dist)
77 {
78 min_dist = val;
79 result = n.color->Dist(v,vv);
80 }
81 }
82 return result;
83 }
89private:
91};
struct Envi env
Definition Light.hh:55
Color Env(Vector v) const
Definition Light.hh:64
void push_back(Vector v, LightDistribution *next)
Definition Light.hh:57
Definition GraphI.hh:826
Definition VectorTools.hh:380
static unsigned int Interpolate(unsigned int pixel1, unsigned int pixel2, float val)
Definition VectorTools.hh:667
LightBitmap(LightingEnvironment &env, int sx, int sy, Point p, Vector u_x, Vector u_y, Point center)
Definition Light.hh:12
int SizeX() const
Definition Light.hh:16
Color Map(int x, int y) const
Definition Light.hh:18
int SizeY() const
Definition Light.hh:17
Definition Light.hh:33
virtual Color Dist(Vector v, Vector vv) const =0
Definition Light.hh:4
virtual Color Env(Vector v) const =0
RadialLightDistribution(Color c1, Color c2, float dist)
Definition Light.hh:41
Color Dist(Vector v, Vector vv) const
Definition Light.hh:42
Definition Effect.hh:1122
Definition VectorTools.hh:125
float Dist() const
Definition VectorTools.cc:141
d
Definition meshpage.php:3895
Definition Light.hh:85
Vector vec
Definition Light.hh:86
LightDistribution * color
Definition Light.hh:87
Definition Parser.cc:60