added 3dengfx into the repo, probably not the correct version for this
[summerhack] / src / 3dengfx / src / 3dengfx / light.hpp
1 /*
2 Copyright 2004 John Tsiombikas <nuclear@siggraph.org>
3
4 This file is part of the 3dengfx, realtime visualization system.
5
6 3dengfx is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 3dengfx is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with 3dengfx; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19 */
20 #ifndef _LIGHT_HPP_
21 #define _LIGHT_HPP_
22
23 #include <string>
24 #include "n3dmath2/n3dmath2.hpp"
25 #include "gfx/animation.hpp"
26 #include "gfx/color.hpp"
27
28 #define LIGHTCOL_AMBIENT        1
29 #define LIGHTCOL_DIFFUSE        2
30 #define LIGHTCOL_SPECULAR       4
31
32 // abstract base class Light
33 class Light : public XFormNode {
34 protected:
35         Color ambient_color, diffuse_color, specular_color;
36         scalar_t intensity;
37         scalar_t attenuation[3];
38         bool cast_shadows;
39
40 public:
41         Light();
42         virtual ~Light();
43         
44         virtual void set_color(const Color &c, unsigned short color_flags = 0);
45         virtual void set_color(const Color &amb, const Color &diff, const Color &spec);
46         virtual Color get_color(unsigned short which) const;
47         
48         virtual void set_intensity(scalar_t intensity);
49         virtual scalar_t get_intensity() const;
50         
51         virtual void set_attenuation(scalar_t att0, scalar_t att1, scalar_t att2);
52         virtual scalar_t get_attenuation(int which) const;
53         virtual Vector3 get_attenuation_vector() const;
54
55         virtual void set_shadow_casting(bool shd);
56         virtual bool casts_shadows() const;
57         
58         virtual void set_gl_light(int n, unsigned long time = XFORM_LOCAL_PRS) const = 0;
59 };
60
61
62 class PointLight : public Light {
63 public:
64         PointLight(const Vector3 &pos=Vector3(0,0,0), const Color &col=Color(1.0f, 1.0f, 1.0f));
65         virtual ~PointLight();
66
67         virtual void set_gl_light(int n, unsigned long time = XFORM_LOCAL_PRS) const;
68 };
69
70 class DirLight : public Light {
71 private:
72         Vector3 dir;    // actually get rid of this and work with the PRS directly?
73
74 public:
75         DirLight(const Vector3 &dir=Vector3(0, 0, 1), const Color &col=Color(1.0f, 1.0f, 1.0f));
76         virtual ~DirLight();
77
78         Vector3 get_direction();
79         
80         virtual void set_gl_light(int n, unsigned long time = XFORM_LOCAL_PRS) const;
81 };
82
83 #endif  // _LIGHT_HPP_