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-2016, 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 
28 
29 
30 class CSoundInterface;
31 struct Event;
32 
33 
34 // Graphics module namespace
35 namespace Gfx
36 {
37 
38 class CEngine;
39 class CTerrain;
40 
46 {
50  WATER_TT = 1,
52  WATER_TO = 2,
54  WATER_CT = 3,
56  WATER_CO = 4,
57 };
58 
72 class CWater
73 {
74 public:
75  CWater(CEngine* engine);
76  virtual ~CWater();
77 
78  bool EventProcess(const Event &event);
80  void Flush();
82  void Create(WaterType type1, WaterType type2, const std::string& fileName,
83  Color diffuse, Color ambient, float level, float glint, Math::Vector eddy);
85  void DrawBack();
87  void DrawSurf();
88 
90  void SetLevel(float level);
92  float GetLevel();
94  float GetLevel(CObject* object);
95 
97  void SetLava(bool lava);
99  bool GetLava();
101 
103  void AdjustEye(Math::Vector &eye);
104 
105 protected:
107  bool EventFrame(const Event &event);
109  void LavaFrame(float rTime);
111  void AdjustLevel(Math::Vector &pos, Math::Vector &norm, Math::Point &uv1, Math::Point &uv2);
113  bool GetWater(int x, int y);
115  void CreateLine(int x, int y, int len);
116 
118  void VaporFlush();
120  bool VaporCreate(ParticleType type, Math::Vector pos, float delay);
122  void VaporFrame(int i, float rTime);
123 
124 protected:
125  CEngine* m_engine = nullptr;
126  CDevice* m_device = nullptr;
127  CTerrain* m_terrain = nullptr;
128  CParticle* m_particle = nullptr;
129  CSoundInterface* m_sound = nullptr;
130 
131  WaterType m_type[2] = {};
132  std::string m_fileName;
134  float m_level = 0.0f;
136  float m_glint = 0.0f;
143  float m_time = 0.0f;
144  float m_lastLava = 0.0f;
145  int m_subdiv = 4;
146 
148  int m_brickCount = 0;
150  float m_brickSize = 0;
151 
156  struct WaterLine
157  {
159  short x = 0, y = 0;
162  short len = 0;
165  float px1 = 0, px2 = 0, pz = 0;
166  };
167  std::vector<WaterLine> m_lines;
168 
173  struct WaterVapor
174  {
175  bool used = false;
176  ParticleType type = PARTIWATER;
177  Math::Vector pos;
178  float delay = 0.0f;
179  float time = 0.0f;
180  float last = 0.0f;
181  };
182  std::vector<WaterVapor> m_vapors;
183 
184  bool m_draw = true;
185  bool m_lava = false;
186  Color m_color = Color(1.0f, 1.0f, 1.0f, 1.0f);
187 };
188 
189 
190 } // namespace Gfx
191 
float GetLevel()
Returns the current level of water.
Definition: water.cpp:550
bool GetWater(int x, int y)
Indicates if there is water in a given position.
Definition: water.cpp:431
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:609
Water strip.
Definition: water.h:156
void SetLevel(float level)
Changes the level of the water.
Definition: water.cpp:542
void VaporFlush()
Removes all the steam jets.
Definition: water.cpp:135
WaterType
Mode of water display.
Definition: water.h:45
void DrawSurf()
Draws the flat surface of the water.
Definition: water.cpp:317
Opaque texture.
Definition: water.h:52
float px1
X (1, 2) and Z coordinates (world coordinates)
Definition: water.h:165
float m_glint
Amplitude of reflections.
Definition: water.h:136
Particle engine.
Definition: particle.h:223
bool EventFrame(const Event &event)
Makes water evolve.
Definition: water.cpp:71
< shows the limits 3
Definition: particle.h:151
bool VaporCreate(ParticleType type, Math::Vector pos, float delay)
Creates a new steam.
Definition: water.cpp:143
Transparent texture.
Definition: water.h:50
void CreateLine(int x, int y, int len)
Updates the positions, relative to the ground.
Definition: water.cpp:455
No water.
Definition: water.h:48
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:472
float m_level
Overall level.
Definition: water.h:134
Transparent color.
Definition: water.h:54
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:238
void SetLava(bool lava)
Management of the mode of lava/water.
Definition: water.cpp:599
Color m_ambient
Ambient color.
Definition: water.h:142
Terrain loader/generator and manager.
Definition: terrain.h:147
Namespace for (new) graphics code.
Definition: app.h:49
Math::Vector m_eddy
Amplitude of swirls.
Definition: water.h:138
void LavaFrame(float rTime)
Makes evolve the steam jets on the lava.
Definition: water.cpp:85
The graphics engine.
Definition: engine.h:585
Color m_diffuse
Diffuse color.
Definition: water.h:140
Water manager/renderer.
Definition: water.h:72
Opaque color.
Definition: water.h:56
Water particle effect.
Definition: water.h:173
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:169
RGBA color.
Definition: color.h:39
float m_brickSize
Size of a item in an brick.
Definition: water.h:150
void DrawBack()
Draw the back surface of the water.
Definition: water.cpp:256
int m_brickCount
Number of brick*mosaics.
Definition: water.h:148
Event sent by system, interface or game.
Definition: event.h:735
Base class for all 3D in-game objects.
Definition: object.h:63
Sound plugin interface.
Definition: sound.h:60
Abstract interface of graphics device.
Definition: device.h:323
void Flush()
Removes all the water.
Definition: water.cpp:534