Colobot
water.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2014, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsiteс.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "common/event.h"
29 
31 
32 
33 class CSoundInterface;
34 
35 
36 // Graphics module namespace
37 namespace Gfx {
38 
39 
40 class CEngine;
41 class CTerrain;
42 
47 struct WaterLine
48 {
50  short x, y;
53  short len;
56  float px1, px2, pz;
57 
58  WaterLine()
59  {
60  x = y = 0;
61  len = 0;
62  px1 = px2 = pz = 0.0f;
63  }
64 };
65 
70 struct WaterVapor
71 {
72  bool used;
73  ParticleType type;
74  Math::Vector pos;
75  float delay;
76  float time;
77  float last;
78 
79  WaterVapor()
80  {
81  used = false;
82  type = PARTIWATER;
83  delay = time = last = 0.0f;
84  }
85 };
86 
92 {
96  WATER_TT = 1,
98  WATER_TO = 2,
100  WATER_CT = 3,
102  WATER_CO = 4,
103 };
104 
118 class CWater
119 {
120 public:
121  CWater(CEngine* engine);
122  virtual ~CWater();
123 
124  void SetDevice(CDevice* device);
125  bool EventProcess(const Event &event);
127  void Flush();
129  void Create(WaterType type1, WaterType type2, const std::string& fileName,
130  Color diffuse, Color ambient, float level, float glint, Math::Vector eddy);
132  void DrawBack();
134  void DrawSurf();
135 
137  void SetLevel(float level);
139  float GetLevel();
141  float GetLevel(CObject* object);
142 
144  void SetLava(bool lava);
146  bool GetLava();
148 
150  void AdjustEye(Math::Vector &eye);
151 
152 protected:
154  bool EventFrame(const Event &event);
156  void LavaFrame(float rTime);
158  void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
160  bool GetWater(int x, int y);
162  void CreateLine(int x, int y, int len);
163 
165  void VaporFlush();
167  bool VaporCreate(ParticleType type, Math::Vector pos, float delay);
169  void VaporFrame(int i, float rTime);
170 
171 protected:
172  CEngine* m_engine;
173  CDevice* m_device;
174  CTerrain* m_terrain;
175  CParticle* m_particle;
176  CSoundInterface* m_sound;
177 
178  WaterType m_type[2];
179  std::string m_fileName;
181  float m_level;
183  float m_glint;
190  float m_time;
191  float m_lastLava;
192  int m_subdiv;
193 
197  float m_brickSize;
198 
199  std::vector<WaterLine> m_lines;
200  std::vector<WaterVapor> m_vapors;
201 
202  bool m_draw;
203  bool m_lava;
204  Color m_color;
205 };
206 
207 
208 } // namespace Gfx
209 
float GetLevel()
Returns the current level of water.
Definition: water.cpp:557
short len
Length in X direction (terrain coordinates)
Definition: water.h:54
bool GetWater(int x, int y)
Indicates if there is water in a given position.
Definition: water.cpp:438
ParticleType
Definition: particle.h:60
float px1
X (1, 2) and Z coordinates (world coordinates)
Definition: water.h:56
void AdjustEye(Math::Vector &eye)
Adjusts the eye of the camera, not to be in the water.
Definition: water.cpp:616
void SetLevel(float level)
Changes the level of the water.
Definition: water.cpp:549
void VaporFlush()
Removes all the steam jets.
Definition: water.cpp:150
WaterType
Mode of water display.
Definition: water.h:91
void DrawSurf()
Draws the flat surface of the water.
Definition: water.cpp:329
short x
Beginning of line (terrain coordinates)
Definition: water.h:51
Opaque texture.
Definition: water.h:98
float m_glint
Amplitude of reflections.
Definition: water.h:183
Particle engine.
Definition: particle.h:268
bool EventFrame(const Event &event)
Makes water evolve.
Definition: water.cpp:86
< shows the limits 4
Definition: particle.h:177
bool VaporCreate(ParticleType type, Math::Vector pos, float delay)
Creates a new steam.
Definition: water.cpp:155
Transparent texture.
Definition: water.h:96
void CreateLine(int x, int y, int len)
Updates the positions, relative to the ground.
Definition: water.cpp:462
No water.
Definition: water.h:94
2D point
Definition: point.h:49
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:479
float m_level
Overall level.
Definition: water.h:181
Transparent color.
Definition: water.h:100
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:250
void SetLava(bool lava)
Management of the mode of lava/water.
Definition: water.cpp:606
Color m_ambient
Ambient color.
Definition: water.h:189
Terrain loader/generator and manager.
Definition: terrain.h:222
Water strip.
Definition: water.h:47
Namespace for (new) graphics code.
Definition: app.h:49
Math::Vector m_eddy
Amplitude of swirls.
Definition: water.h:185
void LavaFrame(float rTime)
Makes evolve the steam jets on the lava.
Definition: water.cpp:100
The graphics engine.
Definition: engine.h:684
Color m_diffuse
Diffuse color.
Definition: water.h:187
Event types, structs and event queue.
Water manager/renderer.
Definition: water.h:118
Opaque color.
Definition: water.h:102
Particle rendering - CParticle class (aka particle)
3D (3x1) vector
Definition: vector.h:52
void VaporFrame(int i, float rTime)
Makes evolve a steam jet.
Definition: water.cpp:181
RGBA color.
Definition: color.h:38
float m_brickSize
Size of a item in an brick.
Definition: water.h:197
void DrawBack()
Draw the back surface of the water.
Definition: water.cpp:268
int m_brickCount
Number of brick*mosaics.
Definition: water.h:195
Event sent by system, interface or game.
Definition: event.h:678
Definition: object.h:357
Water particle effect.
Definition: water.h:70
Sound plugin interface.
Definition: sound.h:151
Abstract interface of graphics device.
Definition: device.h:251
void Flush()
Removes all the water.
Definition: water.cpp:541