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
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.
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.
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.
26 #include <OgreLight.h>
32 extern SBS *sbs; //external pointer to the SBS engine
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)
36 //creates a light object
40 //1 - directional light
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
48 object = new Object();
49 object->SetValues(this, sbs->object, "Light", name, false);
55 /*light = sbs->engine->CreateLight(name, sbs->ToRemote(position), sbs->ToRemote(radius), csColor(color_r, color_g, color_b), CS_LIGHT_DYNAMICTYPE_DYNAMIC);
58 light->SetType(CS_LIGHT_POINTLIGHT);
60 light->SetType(CS_LIGHT_DIRECTIONAL);
62 light->SetType(CS_LIGHT_SPOTLIGHT);
64 light->SetSpecularColor(csColor(spec_color_r, spec_color_g, spec_color_b));
67 light->SetDirectionalCutoffRadius(directional_cutoff_radius);
69 light->SetSpotLightFalloff(spot_falloff_inner, spot_falloff_outer);*/
71 sbs->AddLightHandle(this);
73 SetRotation(rotation);
76 //sbs->area->GetLights()->Add(light);
81 if (sbs->FastDelete == false)
83 //sbs->area->GetLights()->Remove(light);
84 sbs->DeleteLightHandle(this);
91 //prepare light for use
94 void Light::Move(const Ogre::Vector3 position, bool relative_x, bool relative_y, bool relative_z)
96 //move light - this can only be done on movable lights
98 if (relative_x == false)
99 pos.x = sbs->ToRemote(Origin.x + position.x);
101 pos.x = light->GetCenter().x + sbs->ToRemote(position.x);
102 if (relative_y == false)
103 pos.y = sbs->ToRemote(Origin.y + position.y);
105 pos.y = light->GetCenter().y + sbs->ToRemote(position.y);
106 if (relative_z == false)
107 pos.z = sbs->ToRemote(Origin.z + position.z);
109 pos.z = light->GetCenter().z + sbs->ToRemote(position.z);
110 light->GetMovable()->SetPosition(pos);
111 light->GetMovable()->UpdateMove();*/
114 Ogre::Vector3 Light::GetPosition()
116 //return sbs->ToLocal(light->GetMovable()->GetPosition());
117 return Ogre::Vector3(0, 0, 0);
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)
124 //light->SetColor(csColor(color_r, color_g, color_b));
125 //light->SetSpecularColor(csColor(spec_color_r, spec_color_g, spec_color_b));
128 void Light::SetRotation(const Ogre::Vector3& rotation)
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);
137 light->GetMovable()->UpdateMove();*/
140 void Light::Rotate(const Ogre::Vector3& rotation, float speed)
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));
149 Ogre::Vector3 Light::GetRotation()
151 return Ogre::Vector3(rotX, rotY, rotZ);