Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
water.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
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 
23 #pragma once
24 
25 
26 #include "common/event.h"
27 
29 
30 
31 class CSoundInterface;
32 
33 
34 // Graphics module namespace
35 namespace Gfx {
36 
37 
38 class CEngine;
39 class CTerrain;
40 
45 struct WaterLine
46 {
48  short x, y;
51  short len;
54  float px1, px2, pz;
55 
56  WaterLine()
57  {
58  x = y = 0;
59  len = 0;
60  px1 = px2 = pz = 0.0f;
61  }
62 };
63 
68 struct WaterVapor
69 {
70  bool used;
71  ParticleType type;
72  Math::Vector pos;
73  float delay;
74  float time;
75  float last;
76 
77  WaterVapor()
78  {
79  used = false;
80  type = PARTIWATER;
81  delay = time = last = 0.0f;
82  }
83 };
84 
90 {
94  WATER_TT = 1,
96  WATER_TO = 2,
98  WATER_CT = 3,
100  WATER_CO = 4,
101 };
102 
116 class CWater
117 {
118 public:
119  CWater(CEngine* engine);
120  virtual ~CWater();
121 
122  void SetDevice(CDevice* device);
123  bool EventProcess(const Event &event);
125  void Flush();
127  void Create(WaterType type1, WaterType type2, const std::string& fileName,
128  Color diffuse, Color ambient, float level, float glint, Math::Vector eddy);
130  void DrawBack();
132  void DrawSurf();
133 
135  void SetLevel(float level);
137  float GetLevel();
139  float GetLevel(CObject* object);
140 
142  void SetLava(bool lava);
144  bool GetLava();
146 
148  void AdjustEye(Math::Vector &eye);
149 
150 protected:
152  bool EventFrame(const Event &event);
154  void LavaFrame(float rTime);
156  void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
158  bool GetWater(int x, int y);
160  void CreateLine(int x, int y, int len);
161 
163  void VaporFlush();
165  bool VaporCreate(ParticleType type, Math::Vector pos, float delay);
167  void VaporFrame(int i, float rTime);
168 
169 protected:
170  CEngine* m_engine;
171  CDevice* m_device;
172  CTerrain* m_terrain;
173  CParticle* m_particle;
174  CSoundInterface* m_sound;
175 
176  WaterType m_type[2];
177  std::string m_fileName;
179  float m_level;
181  float m_glint;
188  float m_time;
189  float m_lastLava;
190  int m_subdiv;
191 
195  float m_brickSize;
196 
197  std::vector<WaterLine> m_lines;
198  std::vector<WaterVapor> m_vapors;
199 
200  bool m_draw;
201  bool m_lava;
202  Color m_color;
203 };
204 
205 
206 } // namespace Gfx
207 
float GetLevel()
Returns the current level of water.
Definition: water.cpp:555
short len
Length in X direction (terrain coordinates)
Definition: water.h:52
bool GetWater(int x, int y)
Indicates if there is water in a given position.
Definition: water.cpp:436
ParticleType
Definition: particle.h:58
float px1
X (1, 2) and Z coordinates (world coordinates)
Definition: water.h:54
void AdjustEye(Math::Vector &eye)
Adjusts the eye of the camera, not to be in the water.
Definition: water.cpp:614
void SetLevel(float level)
Changes the level of the water.
Definition: water.cpp:547
void VaporFlush()
Removes all the steam jets.
Definition: water.cpp:148
WaterType
Mode of water display.
Definition: water.h:89
void DrawSurf()
Draws the flat surface of the water.
Definition: water.cpp:327
short x
Beginning of line (terrain coordinates)
Definition: water.h:49
Opaque texture.
Definition: water.h:96
float m_glint
Amplitude of reflections.
Definition: water.h:181
Particle engine.
Definition: particle.h:266
bool EventFrame(const Event &event)
Makes water evolve.
Definition: water.cpp:84
< shows the limits 4
Definition: particle.h:175
bool VaporCreate(ParticleType type, Math::Vector pos, float delay)
Creates a new steam.
Definition: water.cpp:153
Transparent texture.
Definition: water.h:94
void CreateLine(int x, int y, int len)
Updates the positions, relative to the ground.
Definition: water.cpp:460
No water.
Definition: water.h:92
2D point
Definition: point.h:46
void Create(WaterType type1, WaterType type2, const std::string &fileName, Color diffuse, Color ambient, float level, float glint, Math::Vector eddy)
Creates all expanses of water.
Definition: water.cpp:477
float m_level
Overall level.
Definition: water.h:179
Transparent color.
Definition: water.h:98
void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2)
Adjusts the position to normal, to imitate reflections on an expanse of water at rest.
Definition: water.cpp:248
void SetLava(bool lava)
Management of the mode of lava/water.
Definition: water.cpp:604
Color m_ambient
Ambient color.
Definition: water.h:187
Terrain loader/generator and manager.
Definition: terrain.h:220
Water strip.
Definition: water.h:45
Math::Vector m_eddy
Amplitude of swirls.
Definition: water.h:183
void LavaFrame(float rTime)
Makes evolve the steam jets on the lava.
Definition: water.cpp:98
The graphics engine.
Definition: engine.h:681
Color m_diffuse
Diffuse color.
Definition: water.h:185
Event types, structs and event queue.
Water manager/renderer.
Definition: water.h:116
Opaque color.
Definition: water.h:100
Particle rendering - CParticle class (aka particle)
3D (3x1) vector
Definition: vector.h:49
void VaporFrame(int i, float rTime)
Makes evolve a steam jet.
Definition: water.cpp:179
RGBA color.
Definition: color.h:35
float m_brickSize
Size of a item in an brick.
Definition: water.h:195
void DrawBack()
Draw the back surface of the water.
Definition: water.cpp:266
int m_brickCount
Number of brick*mosaics.
Definition: water.h:193
Event sent by system, interface or game.
Definition: event.h:687
Definition: object.h:372
Water particle effect.
Definition: water.h:68
Sound plugin interface.
Definition: sound.h:149
Abstract interface of graphics device.
Definition: device.h:235
void Flush()
Removes all the water.
Definition: water.cpp:539