OSDN Git Service

Year update
[skyscrapersim/skyscraper.git] / src / sbs / light.cpp
1 /* $Id$ */
2
3 /*
4         Scalable Building Simulator - Light Class
5         The Skyscraper Project - Version 1.8 Alpha
6         Copyright (C)2004-2011 Ryan Thoryk
7         http://www.skyscrapersim.com
8         http://sourceforge.net/projects/skyscraper
9         Contact - ryan@tliquest.net
10
11         This program is free software; you can redistribute it and/or
12         modify it under the terms of the GNU General Public License
13         as published by the Free Software Foundation; either version 2
14         of the License, or (at your option) any later version.
15
16         This program is distributed in the hope that it will be useful,
17         but WITHOUT ANY WARRANTY; without even the implied warranty of
18         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19         GNU General Public License for more details.
20
21         You should have received a copy of the GNU General Public License
22         along with this program; if not, write to the Free Software
23         Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24 */
25
26 #include <OgreLight.h>
27 #include "globals.h"
28 #include "sbs.h"
29 #include "unix.h"
30 #include "light.h"
31
32 extern SBS *sbs; //external pointer to the SBS engine
33
34 Light::Light(const char *name, int type, Ogre::Vector3 position, Ogre::Vector3 rotation, float radius, float max_distance, float color_r, float color_g, float color_b, float spec_color_r, float spec_color_g, float spec_color_b, float directional_cutoff_radius, float spot_falloff_inner, float spot_falloff_outer)
35 {
36         //creates a light object
37
38         //types are:
39         //0 - point light
40         //1 - directional light
41         //2 - spotlight
42
43         //if point light is used, direction and radius are ignored
44         //if directional light is used, position is ignored
45         //if spotlight is used, radius is ignored
46
47         //set up SBS object
48         object = new Object();
49         object->SetValues(this, sbs->object, "Light", name, false);
50
51         Type = type;
52         Name = name;
53         Origin = position;
54
55         /*light = sbs->engine->CreateLight(name, sbs->ToRemote(position), sbs->ToRemote(radius), csColor(color_r, color_g, color_b), CS_LIGHT_DYNAMICTYPE_DYNAMIC);
56
57         if (type == 0)
58                 light->SetType(CS_LIGHT_POINTLIGHT);
59         if (type == 1)
60                 light->SetType(CS_LIGHT_DIRECTIONAL);
61         if (type == 2)
62                 light->SetType(CS_LIGHT_SPOTLIGHT);
63
64         light->SetSpecularColor(csColor(spec_color_r, spec_color_g, spec_color_b));
65
66         if (type == 1)
67                 light->SetDirectionalCutoffRadius(directional_cutoff_radius);
68         if (type == 2)
69                 light->SetSpotLightFalloff(spot_falloff_inner, spot_falloff_outer);*/
70
71         sbs->AddLightHandle(this);
72
73         SetRotation(rotation);
74
75         //add light to world
76         //sbs->area->GetLights()->Add(light);
77 }
78
79 Light::~Light()
80 {
81         if (sbs->FastDelete == false)
82         {
83                 //sbs->area->GetLights()->Remove(light);
84                 sbs->DeleteLightHandle(this);
85         }
86         delete object;
87 }
88
89 void Light::Prepare()
90 {
91         //prepare light for use
92 }
93
94 void Light::Move(const Ogre::Vector3 position, bool relative_x, bool relative_y, bool relative_z)
95 {
96         //move light - this can only be done on movable lights
97         /*Ogre::Vector3 pos;
98         if (relative_x == false)
99                 pos.x = sbs->ToRemote(Origin.x + position.x);
100         else
101                 pos.x = light->GetCenter().x + sbs->ToRemote(position.x);
102         if (relative_y == false)
103                 pos.y = sbs->ToRemote(Origin.y + position.y);
104         else
105                 pos.y = light->GetCenter().y + sbs->ToRemote(position.y);
106         if (relative_z == false)
107                 pos.z = sbs->ToRemote(Origin.z + position.z);
108         else
109                 pos.z = light->GetCenter().z + sbs->ToRemote(position.z);
110         light->GetMovable()->SetPosition(pos);
111         light->GetMovable()->UpdateMove();*/
112 }
113
114 Ogre::Vector3 Light::GetPosition()
115 {
116         //return sbs->ToLocal(light->GetMovable()->GetPosition());
117         return Ogre::Vector3(0, 0, 0);
118 }
119
120 void Light::SetColor(float color_r, float color_g, float color_b, float spec_color_r, float spec_color_g, float spec_color_b)
121 {
122         //set color of light
123
124         //light->SetColor(csColor(color_r, color_g, color_b));
125         //light->SetSpecularColor(csColor(spec_color_r, spec_color_g, spec_color_b));
126 }
127
128 void Light::SetRotation(const Ogre::Vector3& rotation)
129 {
130         //rotate light
131         /*Ogre::Matrix3 rot = csXRotMatrix3(rotation.x) * csYRotMatrix3(rotation.y) * csZRotMatrix3(rotation.z);
132         csOrthoTransform ot (rot, light->GetMovable()->GetTransform().GetOrigin());
133         light->GetMovable()->SetTransform(ot);
134         rotX = rotation.x;
135         rotY = rotation.y;
136         rotZ = rotation.z;
137         light->GetMovable()->UpdateMove();*/
138 }
139
140 void Light::Rotate(const Ogre::Vector3& rotation, float speed)
141 {
142         //rotates light in a relative amount
143         rotX += rotation.x * speed;
144         rotY += rotation.y * speed;
145         rotZ += rotation.z * speed;
146         SetRotation(Ogre::Vector3(rotX, rotY, rotZ));
147 }
148
149 Ogre::Vector3 Light::GetRotation()
150 {
151         return Ogre::Vector3(rotX, rotY, rotZ);
152 }