4 Scalable Building Simulator - Directional Indicator Class
5 The Skyscraper Project - Version 1.5 Alpha
6 Copyright (C)2005-2009 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.
27 #include "directional.h"
31 extern SBS *sbs; //external pointer to the SBS engine
33 DirectionalIndicator::DirectionalIndicator(int elevator, int floor, bool single, bool vertical, const char *BackTexture, const char *uptexture, const char *uptexture_lit, const char *downtexture, const char *downtexture_lit, float CenterX, float CenterZ, float voffset, const char *direction, float BackWidth, float BackHeight, bool ShowBack, float tw, float th)
35 //create a directional indicator
38 elevator_num = elevator;
40 Direction = direction;
41 UpTextureUnlit = uptexture;
42 UpTextureLit = uptexture_lit;
43 DownTextureUnlit = downtexture;
44 DownTextureLit = downtexture_lit;
51 csString buffer, buffer2, buffer3;
54 buffer = "Directional Indicator " + buffer2 + ":" + buffer3 + ":Back";
56 DirectionalMeshBack = sbs->engine->CreateSectorWallsMesh (sbs->area, buffer.GetData());
57 Directional_back_state = scfQueryInterface<iThingFactoryState> (DirectionalMeshBack->GetMeshObject()->GetFactory());
58 DirectionalMeshBack->SetZBufMode(CS_ZBUF_USE);
59 DirectionalMeshBack->SetRenderPriority(sbs->engine->GetObjectRenderPriority());
63 buffer = "Directional Indicator " + buffer2 + ":" + buffer3 + ":Up";
64 DirectionalMeshUp = CS::Geometry::GeneralMeshBuilder::CreateFactoryAndMesh(sbs->engine, sbs->area, buffer, buffer + " factory");
65 DirectionalMeshUp->SetZBufMode(CS_ZBUF_USE);
66 DirectionalMeshUp->SetRenderPriority(sbs->engine->GetObjectRenderPriority());
67 csRef<iMaterialWrapper> mat = sbs->engine->GetMaterialList()->FindByName(UpTextureUnlit);
68 DirectionalMeshUp->GetMeshObject()->SetMaterialWrapper(mat);
70 buffer = "Directional Indicator " + buffer2 + ":" + buffer3 + ":Down";
71 DirectionalMeshDown = CS::Geometry::GeneralMeshBuilder::CreateFactoryAndMesh(sbs->engine, sbs->area, buffer, buffer + " factory");
72 DirectionalMeshDown->SetZBufMode(CS_ZBUF_USE);
73 DirectionalMeshDown->SetRenderPriority(sbs->engine->GetObjectRenderPriority());
74 mat = sbs->engine->GetMaterialList()->FindByName(DownTextureUnlit);
75 DirectionalMeshDown->GetMeshObject()->SetMaterialWrapper(mat);
79 buffer = "Directional Indicator " + buffer2 + ":" + buffer3 + ":Arrow";
80 DirectionalMesh = CS::Geometry::GeneralMeshBuilder::CreateFactoryAndMesh(sbs->engine, sbs->area, buffer, buffer + " factory");
81 DirectionalMesh->SetZBufMode(CS_ZBUF_USE);
82 DirectionalMesh->SetRenderPriority(sbs->engine->GetAlphaRenderPriority());
83 DirectionalMesh->GetMeshObject()->SetMixMode(CS_FX_ALPHA);
84 csRef<iMaterialWrapper> mat = sbs->engine->GetMaterialList()->FindByName(UpTextureUnlit);
85 DirectionalMesh->GetMeshObject()->SetMaterialWrapper(mat);
88 sbs->ResetTextureMapping(true);
93 if (Direction == "front" || Direction == "back")
95 if (Direction == "front")
96 sbs->DrawWalls(true, false, false, false, false, false);
98 sbs->DrawWalls(false, true, false, false, false, false);
99 sbs->AddWallMain(Directional_back_state, "Panel", BackTexture, 0, CenterX - (BackWidth / 2), CenterZ, CenterX + (BackWidth / 2), CenterZ, BackHeight, BackHeight, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset, tw, th);
102 if (Direction == "left" || Direction == "right")
104 if (Direction == "left")
105 sbs->DrawWalls(true, false, false, false, false, false);
107 sbs->DrawWalls(false, true, false, false, false, false);
108 sbs->AddWallMain(Directional_back_state, "Panel", BackTexture, 0, CenterX, CenterZ + (BackWidth / 2), CenterX, CenterZ - (BackWidth / 2), BackHeight, BackHeight, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset, tw, th);
113 //create indicator lanterns
114 int bottomfloor = sbs->GetElevator(elevator)->GetBottomFloor();
115 int topfloor = sbs->GetElevator(elevator)->GetTopFloor();
117 if (Direction == "front" || Direction == "back")
121 if (Direction == "front")
124 x1 = CenterX - (BackWidth / 4);
125 x2 = CenterX + (BackWidth / 4);
130 x2 = CenterX - (BackWidth / 4);
131 x1 = CenterX + (BackWidth / 4);
135 if (Vertical == true)
137 if (floor > bottomfloor && floor < topfloor)
139 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 4), 1, 1);
140 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 7), 1, 1);
144 if (floor < topfloor)
145 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
146 if (floor > bottomfloor)
147 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
153 if (floor > bottomfloor && floor < topfloor)
156 if (Direction == "front")
158 x1 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7) * 4);
159 x2 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7) * 6);
160 x3 = (CenterX - (BackWidth / 2)) + (BackWidth / 7);
161 x4 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7) * 3);
165 x1 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7) * 6);
166 x2 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7) * 4);
167 x3 = (CenterX - (BackWidth / 2)) + ((BackWidth / 7)) * 3;
168 x4 = (CenterX - (BackWidth / 2)) + (BackWidth / 7);
170 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
171 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, x3, CenterZ + offset, x4, CenterZ + offset, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
175 if (floor < topfloor)
176 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
177 if (floor > bottomfloor)
178 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
183 sbs->AddGenWall(DirectionalMesh, UpTextureUnlit, x1, CenterZ + offset, x2, CenterZ + offset, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
189 if (Direction == "left")
192 z2 = CenterZ - (BackWidth / 4);
193 z1 = CenterZ + (BackWidth / 4);
199 z1 = CenterZ - (BackWidth / 4);
200 z2 = CenterZ + (BackWidth / 4);
204 if (Vertical == true)
206 if (floor > bottomfloor && floor < topfloor)
208 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 4), 1, 1);
209 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 7), 1, 1);
213 if (floor < topfloor)
214 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
215 if (floor > bottomfloor)
216 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
222 if (floor > bottomfloor && floor < topfloor)
225 if (Direction == "left")
227 z1 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7) * 6);
228 z2 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7) * 4);
229 z3 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7)) * 3;
230 z4 = (CenterZ - (BackWidth / 2)) + (BackWidth / 7);
234 z1 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7) * 4);
235 z2 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7) * 6);
236 z3 = (CenterZ - (BackWidth / 2)) + (BackWidth / 7);
237 z4 = (CenterZ - (BackWidth / 2)) + ((BackWidth / 7) * 3);
239 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
240 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, CenterX + offset, z3, CenterX + offset, z4, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
244 if (floor < topfloor)
245 sbs->AddGenWall(DirectionalMeshUp, UpTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
246 if (floor > bottomfloor)
247 sbs->AddGenWall(DirectionalMeshDown, DownTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 7) * 2, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + ((BackHeight / 7) * 2.5), 1, 1);
252 sbs->AddGenWall(DirectionalMesh, UpTextureUnlit, CenterX + offset, z1, CenterX + offset, z2, (BackHeight / 6) * 4, sbs->GetFloor(floor)->Altitude + sbs->GetFloor(floor)->InterfloorHeight + voffset + (BackHeight / 6), 1, 1);
254 sbs->ResetTextureMapping();
257 DirectionalIndicator::~DirectionalIndicator()
262 void DirectionalIndicator::Enabled(bool value)
265 if (value == IsEnabled)
268 sbs->EnableMesh(DirectionalMeshBack, value);
269 if (DirectionalMeshUp)
270 sbs->EnableMesh(DirectionalMeshUp, value);
271 if (DirectionalMeshDown)
272 sbs->EnableMesh(DirectionalMeshDown, value);
274 sbs->EnableMesh(DirectionalMesh, value);
279 void DirectionalIndicator::UpLight(bool value)
281 //turn on the 'up' directional light
282 if (value == UpStatus)
285 //exit if indicator is disabled
286 if (IsEnabled == false)
298 void DirectionalIndicator::DownLight(bool value)
300 //turn on the 'down' directional light
301 if (value == DownStatus)
304 //exit if indicator is disabled
305 if (IsEnabled == false)
317 void DirectionalIndicator::SetLights(int up, int down)
319 //set status of directional lights
320 //values are 0 for no change, 1 for on, and 2 for off
324 if (up == 1 && DirectionalMeshUp)
325 sbs->ChangeTexture(DirectionalMeshUp, UpTextureLit);
326 if (up == 2 && DirectionalMeshUp)
327 sbs->ChangeTexture(DirectionalMeshUp, UpTextureUnlit);
328 if (down == 1 && DirectionalMeshDown)
329 sbs->ChangeTexture(DirectionalMeshDown, DownTextureLit);
330 if (down == 2 && DirectionalMeshDown)
331 sbs->ChangeTexture(DirectionalMeshDown, DownTextureUnlit);
338 sbs->ChangeTexture(DirectionalMesh, UpTextureLit);
340 sbs->ChangeTexture(DirectionalMesh, DownTextureLit);
341 if (up == 2 || down == 2)
342 sbs->ChangeTexture(DirectionalMesh, UpTextureUnlit);