Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
ShipSolid.cpp
Go to the documentation of this file.
1 /* Project Starshatter 4.5
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: Stars.exe
6  FILE: ShipSolid.cpp
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12 */
13 
14 #include "MemDebug.h"
15 #include "ShipSolid.h"
16 #include "Ship.h"
17 #include "Sim.h"
18 #include "StarSystem.h"
19 #include "TerrainRegion.h"
20 
21 #include "Game.h"
22 #include "Skin.h"
23 
24 // +--------------------------------------------------------------------+
25 
27 : ship(s), skin(0), in_soup(false)
28 {
29 }
30 
31 // +--------------------------------------------------------------------+
32 
34 {
35 }
36 
37 // +--------------------------------------------------------------------+
38 
39 void
41 {
42  true_eye_point = ref;
43  Solid::TranslateBy(ref);
44 }
45 
46 // +--------------------------------------------------------------------+
47 
48 void
49 ShipSolid::Render(Video* video, DWORD flags)
50 {
51  if (hidden || !visible || !video || Depth() > 5e6)
52  return;
53 
54  const Skin* s = 0;
55 
56  if (ship)
57  s = ship->GetSkin();
58  else
59  s = skin;
60 
61  if (s)
62  s->ApplyTo(model);
63 
64  bool fog = false;
65 
66  if (ship && ship->IsAirborne()) {
67  fog = true;
68 
70  double visibility = rgn->GetWeather().Visibility();
71  FLOAT fog_density = (FLOAT) (rgn->FogDensity() * 2.5e-5 * 1/visibility);
72  Color fog_color = rgn->FogColor();
73 
74  // Use BLACK fog on secondary lighting pass
75  // This will effectively "filter out" the highlights
76  // with distance...
77 
78  if (flags & Graphic::RENDER_ADD_LIGHT)
79  fog_color = Color::Black;
80 
81  video->SetRenderState(Video::FOG_ENABLE, true);
82  video->SetRenderState(Video::FOG_COLOR, fog_color.Value());
83  video->SetRenderState(Video::FOG_DENSITY, *((DWORD*) &fog_density));
84  }
85 
86  if (!fog) video->SetRenderState(Video::FOG_ENABLE, false);
87 
88  Solid::Render(video, flags);
89 
90  if (fog) video->SetRenderState(Video::FOG_ENABLE, false);
91 
92  if (s)
93  s->Restore(model);
94 }
95 
96