~ubuntu-branches/debian/sid/3depict/sid

« back to all changes in this revision

Viewing changes to src/lights.cpp

  • Committer: Bazaar Package Importer
  • Author(s): D Haley
  • Date: 2010-08-09 21:23:50 UTC
  • Revision ID: james.westby@ubuntu.com-20100809212350-cg6yumndhwi3bqws
Tags: upstream-0.0.1
ImportĀ upstreamĀ versionĀ 0.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *      lights.cpp - OpenGL Lighting implementation
 
3
 *      Copyright (C) 2007, D Haley 
 
4
 
 
5
 *      This program is free software: you can redistribute it and/or modify
 
6
 *      it under the terms of the GNU General Public License as published by
 
7
 *      the Free Software Foundation, either version 3 of the License, or
 
8
 *      (at your option) any later version.
 
9
 
 
10
 *      This program is distributed in the hope that it will be useful,
 
11
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 *      GNU General Public License for more details.
 
14
 
 
15
 *      You should have received a copy of the GNU General Public License
 
16
 *      along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
17
*/
 
18
 
 
19
#include "lights.h"
 
20
 
 
21
Light::Light() : active(false) 
 
22
{
 
23
        /*
 
24
        for(unsigned int ui=0; ui<3; ui++)
 
25
        {
 
26
                ambientColour[ui] = 1.0f;
 
27
                diffuseColour[ui] = 1.0f;
 
28
                specularColour[ui] = 1.0f;
 
29
        }*/
 
30
        origin = Point3D(0.0f,0.0f,0.0f);
 
31
}
 
32
 
 
33
Light::~Light()
 
34
{
 
35
}
 
36
 
 
37
void Light::setActive(bool b)
 
38
{
 
39
        active=b;
 
40
}
 
41
 
 
42
bool Light::isActive() const
 
43
{
 
44
        return active;
 
45
}
 
46
 
 
47
void Light::setLightNum(unsigned int ln)
 
48
{
 
49
        lightNum =ln;
 
50
}
 
51
 
 
52
void Light::setOrigin(const Point3D &p)
 
53
{
 
54
        origin=p;
 
55
}
 
56
 
 
57
void Light::setColour(unsigned int mode, float r, float g, float b)
 
58
{
 
59
        switch(mode)
 
60
        {
 
61
                case LIGHT_AMBIENT:
 
62
                        ambientColour[0] = r;
 
63
                        ambientColour[1] = g;
 
64
                        ambientColour[2] = b;
 
65
                        break;
 
66
                case LIGHT_DIFFUSE:
 
67
                        diffuseColour[0] = r;
 
68
                        diffuseColour[1] = g;
 
69
                        diffuseColour[2] = b;
 
70
                        break;
 
71
                case LIGHT_SPECULAR:
 
72
                        specularColour[0] = r;
 
73
                        specularColour[1] = g;
 
74
                        specularColour[2] = b;
 
75
                        break;
 
76
                default:
 
77
                        ASSERT(false);
 
78
        }
 
79
 
 
80
}
 
81
 
 
82
void Light::apply() const
 
83
{
 
84
        if(active)
 
85
        {
 
86
                float f[3];
 
87
                origin.copyValueArr(f);
 
88
                glEnable(lightNum);
 
89
                glLightfv(lightNum, GL_AMBIENT, ambientColour);
 
90
                glLightfv(lightNum, GL_DIFFUSE, diffuseColour);
 
91
                glLightfv(lightNum, GL_SPECULAR, specularColour);
 
92
                glLightfv(lightNum, GL_POSITION, f);
 
93
        }
 
94
        else
 
95
                glDisable(lightNum);
 
96
}
 
97