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-2015, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.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 
48 {
52  WATER_TT = 1,
54  WATER_TO = 2,
56  WATER_CT = 3,
58  WATER_CO = 4,
59 };
60 
74 class CWater
75 {
76 public:
77  CWater(CEngine* engine);
78  virtual ~CWater();
79 
80  void SetDevice(CDevice* device);
81  bool EventProcess(const Event &event);
83  void Flush();
85  void Create(WaterType type1, WaterType type2, const std::string& fileName,
86  Color diffuse, Color ambient, float level, float glint, Math::Vector eddy);
88  void DrawBack();
90  void DrawSurf();
91 
93  void SetLevel(float level);
95  float GetLevel();
97  float GetLevel(CObject* object);
98 
100  void SetLava(bool lava);
102  bool GetLava();
104 
106  void AdjustEye(Math::Vector &eye);
107 
108 protected:
110  bool EventFrame(const Event &event);
112  void LavaFrame(float rTime);
114  void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
116  bool GetWater(int x, int y);
118  void CreateLine(int x, int y, int len);
119 
121  void VaporFlush();
123  bool VaporCreate(ParticleType type, Math::Vector pos, float delay);
125  void VaporFrame(int i, float rTime);
126 
127 protected:
128  CEngine* m_engine = nullptr;
129  CDevice* m_device = nullptr;
130  CTerrain* m_terrain = nullptr;
131  CParticle* m_particle = nullptr;
132  CSoundInterface* m_sound = nullptr;
133 
134  WaterType m_type[2] = {};
135  std::string m_fileName;
137  float m_level = 0.0f;
139  float m_glint = 0.0f;
146  float m_time = 0.0f;
147  float m_lastLava = 0.0f;
148  int m_subdiv = 4;
149 
151  int m_brickCount = 0;
153  float m_brickSize = 0;
154 
159  struct WaterLine
160  {
162  short x = 0, y = 0;
165  short len = 0;
168  float px1 = 0, px2 = 0, pz = 0;
169  };
170  std::vector<WaterLine> m_lines;
171 
176  struct WaterVapor
177  {
178  bool used = false;
179  ParticleType type = PARTIWATER;
180  Math::Vector pos;
181  float delay = 0.0f;
182  float time = 0.0f;
183  float last = 0.0f;
184  };
185  std::vector<WaterVapor> m_vapors;
186 
187  bool m_draw = true;
188  bool m_lava = false;
189  Color m_color = Color(1.0f, 1.0f, 1.0f, 1.0f);
190 };
191 
192 
193 } // namespace Gfx
194 
float GetLevel()
Returns the current level of water.
Definition: water.cpp:543
bool GetWater(int x, int y)
Indicates if there is water in a given position.
Definition: water.cpp:424
ParticleType
Definition: particle.h:63
void AdjustEye(Math::Vector &eye)
Adjusts the eye of the camera, not to be in the water.
Definition: water.cpp:602
Water strip.
Definition: water.h:159
void SetLevel(float level)
Changes the level of the water.
Definition: water.cpp:535
void VaporFlush()
Removes all the steam jets.
Definition: water.cpp:136
WaterType
Mode of water display.
Definition: water.h:47
void DrawSurf()
Draws the flat surface of the water.
Definition: water.cpp:315
Opaque texture.
Definition: water.h:54
float px1
X (1, 2) and Z coordinates (world coordinates)
Definition: water.h:168
float m_glint
Amplitude of reflections.
Definition: water.h:139
Particle engine.
Definition: particle.h:223
bool EventFrame(const Event &event)
Makes water evolve.
Definition: water.cpp:72
< shows the limits 3
Definition: particle.h:151
bool VaporCreate(ParticleType type, Math::Vector pos, float delay)
Creates a new steam.
Definition: water.cpp:141
Transparent texture.
Definition: water.h:52
void CreateLine(int x, int y, int len)
Updates the positions, relative to the ground.
Definition: water.cpp:448
No water.
Definition: water.h:50
2D point
Definition: point.h:50
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:465
float m_level
Overall level.
Definition: water.h:137
Transparent color.
Definition: water.h:56
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:236
void SetLava(bool lava)
Management of the mode of lava/water.
Definition: water.cpp:592
Color m_ambient
Ambient color.
Definition: water.h:145
Terrain loader/generator and manager.
Definition: terrain.h:145
Namespace for (new) graphics code.
Definition: app.h:49
Math::Vector m_eddy
Amplitude of swirls.
Definition: water.h:141
void LavaFrame(float rTime)
Makes evolve the steam jets on the lava.
Definition: water.cpp:86
The graphics engine.
Definition: engine.h:620
Color m_diffuse
Diffuse color.
Definition: water.h:143
Event types, structs and event queue.
Water manager/renderer.
Definition: water.h:74
Opaque color.
Definition: water.h:58
Water particle effect.
Definition: water.h:176
Particle rendering - CParticle class (aka particle)
3D (3x1) vector
Definition: vector.h:53
void VaporFrame(int i, float rTime)
Makes evolve a steam jet.
Definition: water.cpp:167
RGBA color.
Definition: color.h:39
float m_brickSize
Size of a item in an brick.
Definition: water.h:153
void DrawBack()
Draw the back surface of the water.
Definition: water.cpp:254
int m_brickCount
Number of brick*mosaics.
Definition: water.h:151
Event sent by system, interface or game.
Definition: event.h:709
Base class for all 3D in-game objects.
Definition: object.h:59
Sound plugin interface.
Definition: sound.h:57
Abstract interface of graphics device.
Definition: device.h:268
void Flush()
Removes all the water.
Definition: water.cpp:527