zenilib: zenilib/jni/external/zenilib/zeni_graphics/Light.cpp Source File

zenilib 0.5.3.0

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
Light.cpp
Go to the documentation of this file.
1 /* This file is part of the Zenipex Library (zenilib).
2 * Copyright (C) 2011 Mitchell Keith Bloch (bazald).
3 *
4 * zenilib is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * zenilib is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with zenilib. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <zeni_graphics.h>
19
20 #ifndef DISABLE_DX9
21 #include <d3dx9.h>
22 #endif
23
24 #ifndef DISABLE_GL
25 #if defined(REQUIRE_GL_ES)
26 #include <GLES/gl.h>
27 #else
28 #include <GL/glew.h>
29 #endif
30 #endif
31
32 namespace Zeni {
33
34 Light::Light(const Color &ambient_, const Color &diffuse_, const Color &specular_, const Point3f &position_, const Vector3f &spot_direction_)
35 : light_type(LIGHT_POINT),
36 diffuse(diffuse_),
37 specular(specular_),
38 ambient(ambient_),
39 position(position_),
40 spot_direction(spot_direction_),
41 range(float(pow(2.0f, 100.0f))),
42 spot_exponent(1.0f),
43 constant_attenuation(1.0f),
44 linear_attenuation(0.0f),
45 quadratic_attenuation(0.0f),
46 spot_theta(2*Global::pi),
47 spot_phi(2*Global::pi)
48 {
49 }
50
51 #ifndef DISABLE_GL_FIXED
52 void Light::set(const GLenum &number, Video_GL_Fixed &) const {
53 GLfloat pos[] = {position.x, position.y, position.z, 1.0f};
54
55 if(light_type == LIGHT_DIRECTIONAL) {
56 pos[0] = -spot_direction.x;
57 pos[1] = -spot_direction.y;
58 pos[2] = -spot_direction.z;
59 pos[3] = 0.0f;
60 }
61
62 glEnable(number);
63 glLightfv(number, GL_AMBIENT, reinterpret_cast<const GLfloat *>(&ambient));
64 glLightfv(number, GL_DIFFUSE, reinterpret_cast<const GLfloat *>(&diffuse));
65 glLightfv(number, GL_SPECULAR, reinterpret_cast<const GLfloat *>(&specular));
66 glLightfv(number, GL_POSITION, pos);
67 glLightfv(number, GL_SPOT_DIRECTION, reinterpret_cast<const GLfloat*>(&spot_direction));
68 glLightf(number, GL_SPOT_EXPONENT, spot_exponent);
69 glLightf(number, GL_SPOT_CUTOFF, spot_phi*90.0f/Global::pi); // halve
70 glLightf(number, GL_CONSTANT_ATTENUATION, constant_attenuation);
71 glLightf(number, GL_LINEAR_ATTENUATION, linear_attenuation);
72 glLightf(number, GL_QUADRATIC_ATTENUATION, quadratic_attenuation);
73 }
74 #endif
75
76 #ifndef DISABLE_GL_SHADER
77 void Light::set(const GLenum &number, Video_GL_Shader &vgl) const {
79 set(number, reinterpret_cast<Video_GL_Fixed &>(vgl));
80 }
81 #endif
82
83 #ifndef DISABLE_DX9
84 void Light::set(const DWORD &number, Video_DX9 &screen) const {
85 screen.get_d3d_device()->SetLight(number, reinterpret_cast<const D3DLIGHT9 *>(this));
86 screen.get_d3d_device()->LightEnable(number, TRUE);
87 }
88 #endif
89
90 }
pi
static const double pi
Definition: e_atan2.c:47
Zeni::Light::position
Point3f position
The position of the Light (irrelevant for directional lights or purely ambient lights) ...
Definition: Light.h:86
Zeni::Light::diffuse
Color diffuse
The diffuse Color.
Definition: Light.h:83
Zeni::Video_DX9
The Direct3D9 Rendering System.
Definition: Video_DX9.h:62
Zeni::Video_DX9::get_d3d_device
LPDIRECT3DDEVICE9 & get_d3d_device()
See DirectX Documentation for details.
Definition: Video_DX9.hxx:48
GLenum
unsigned int GLenum
Definition: gl2.h:23
GL_SPOT_CUTOFF
#define GL_SPOT_CUTOFF
Definition: glew_head.h:544
GL_SPOT_EXPONENT
#define GL_SPOT_EXPONENT
Definition: glew_head.h:543
f
GLclampf f
Definition: glew.h:3390
GL_DIFFUSE
#define GL_DIFFUSE
Definition: glew_head.h:539
Zeni::Light::light_type
LIGHT_TYPE light_type
The type of the Light.
Definition: Light.h:82
glLightf
#define glLightf
Definition: gl_mangle.h:985
Zeni::Light::specular
Color specular
The specular Color.
Definition: Light.h:84
Zeni::Light::set
void set(const GLenum &number, Video_GL_Fixed &screen) const
Definition: Light.cpp:52
d3dx9.h
Zeni::Light::spot_exponent
float spot_exponent
Similar to Falloff in OpenGL, describes the intensity of the Light from the inner cone to the outer c...
Definition: Light.h:89
Zeni::Point3f
A 3D Point represented with floats.
Definition: Coordinate.h:133
Zeni::Light::constant_attenuation
float constant_attenuation
Part of the equation describing the weakening of Light over distance. Read online for more informatio...
Definition: Light.h:90
range
GLenum GLint * range
Definition: glew.h:3391
GL_CONSTANT_ATTENUATION
#define GL_CONSTANT_ATTENUATION
Definition: glew_head.h:545
GL_SPOT_DIRECTION
#define GL_SPOT_DIRECTION
Definition: glew_head.h:542
Zeni::Vector3f
A Featureful 3-Space Vector Class.
Definition: Vector3f.h:58
Zeni::LIGHT_DIRECTIONAL
Definition: Light.h:55
Zeni::Video_GL_Fixed
The OpenGL Rendering System.
Definition: Video_GL_Fixed.h:70
Zeni::Global::pi
const float pi
pi == 3.1415926...
Definition: Vector3f.cpp:27
glEnable
#define glEnable
Definition: gl_mangle.h:441
Zeni::LIGHT_POINT
Definition: Light.h:55
GL_LINEAR_ATTENUATION
#define GL_LINEAR_ATTENUATION
Definition: glew_head.h:546
Zeni::Video_GL_Shader
The OpenGL Rendering System.
Definition: Video_GL_Shader.h:70
Zeni::Point3f::y
float y
Definition: Coordinate.h:152
Zeni::Point3f::z
float z
Definition: Coordinate.h:152
GLfloat
khronos_float_t GLfloat
Definition: gl2.h:33
GL_AMBIENT
#define GL_AMBIENT
Definition: glew_head.h:538
glLightfv
#define glLightfv
Definition: gl_mangle.h:986
GL_SPECULAR
#define GL_SPECULAR
Definition: glew_head.h:540
DWORD
typedef DWORD(WINAPI *XInputGetState_t)(DWORD dwUserIndex
Zeni::Light::linear_attenuation
float linear_attenuation
Part of the equation describing the weakening of Light over distance. Read online for more informatio...
Definition: Light.h:91
Zeni::Light::spot_phi
float spot_phi
The angle, in radians, describing the size of the outer cone (automatically decreases theta if necess...
Definition: Light.h:94
Zeni::Light::Light
Light(const Color &ambient=Color(1.0f, 0.0f, 0.0f, 0.0f), const Color &diffuse=Color(1.0f, 1.0f, 1.0f, 1.0f), const Color &specular=Color(1.0f, 1.0f, 1.0f, 1.0f), const Point3f &position=Point3f(0.0f, 0.0f, 0.0f), const Vector3f &spot_direction=Vector3f(0.0f, 0.0f,-1.0f))
An Alternative to the numerous setter functions.
Definition: Light.cpp:34
Zeni::Light::quadratic_attenuation
float quadratic_attenuation
Part of the equation describing the weakening of Light over distance. Read online for more informatio...
Definition: Light.h:92
zeni_graphics.h
Zeni::Light::spot_direction
Point3f spot_direction
The direction of the Light (relevent only to spotlights)
Definition: Light.h:87
GL_QUADRATIC_ATTENUATION
#define GL_QUADRATIC_ATTENUATION
Definition: glew_head.h:547
TRUE
#define TRUE
Definition: ftobjs.h:53
Zeni::Light::ambient
Color ambient
The ambient Color.
Definition: Light.h:85
GL_POSITION
#define GL_POSITION
Definition: glew_head.h:541
Zeni::Color
Color.
Definition: Color.h:41
Zeni::Point3f::x
float x
Definition: Coordinate.h:152