Fog effect when camera is inside cloud
[oweals/minetest.git] / src / content_mapblock.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #ifndef CONTENT_MAPBLOCK_HEADER
21 #define CONTENT_MAPBLOCK_HEADER
22 #include "util/numeric.h"
23 #include "nodedef.h"
24 #include <IMeshManipulator.h>
25
26 struct MeshMakeData;
27 struct MeshCollector;
28
29 struct LightFrame
30 {
31         f32 lightsA[8];
32         f32 lightsB[8];
33 };
34
35 class MapblockMeshGenerator
36 {
37 public:
38         MeshMakeData *data;
39         MeshCollector *collector;
40
41         INodeDefManager *nodedef;
42         scene::IMeshManipulator *meshmanip;
43
44 // options
45         bool enable_mesh_cache;
46
47 // current node
48         v3s16 blockpos_nodes;
49         v3s16 p;
50         v3f origin;
51         MapNode n;
52         const ContentFeatures *f;
53         u16 light;
54         LightFrame frame;
55         video::SColor color;
56         TileSpec tile;
57         float scale;
58
59 // lighting
60         void getSmoothLightFrame();
61         u16 blendLight(const v3f &vertex_pos);
62         video::SColor blendLightColor(const v3f &vertex_pos);
63         video::SColor blendLightColor(const v3f &vertex_pos, const v3f &vertex_normal);
64
65         void useTile(int index, bool disable_backface_culling);
66         void useDefaultTile(bool set_color = true);
67         void getTile(const v3s16 &direction, TileSpec &tile);
68
69 // face drawing
70         void drawQuad(v3f *vertices, const v3s16 &normal = v3s16(0, 0, 0));
71
72 // cuboid drawing!
73         void drawCuboid(const aabb3f &box, TileSpec *tiles, int tilecount,
74                 const u16 *lights , const f32 *txc);
75         void generateCuboidTextureCoords(aabb3f const &box, f32 *coords);
76         void drawAutoLightedCuboid(aabb3f box, const f32 *txc = NULL,
77                 TileSpec *tiles = NULL, int tile_count = 0);
78
79 // liquid-specific
80         bool top_is_same_liquid;
81         TileSpec tile_liquid;
82         TileSpec tile_liquid_top;
83         content_t c_flowing;
84         content_t c_source;
85         video::SColor color_liquid_top;
86         struct NeighborData {
87                 f32 level;
88                 content_t content;
89                 bool is_same_liquid;
90                 bool top_is_same_liquid;
91         };
92         NeighborData liquid_neighbors[3][3];
93         f32 corner_levels[2][2];
94
95         void prepareLiquidNodeDrawing();
96         void getLiquidNeighborhood();
97         void calculateCornerLevels();
98         f32 getCornerLevel(int i, int k);
99         void drawLiquidSides();
100         void drawLiquidTop();
101
102 // raillike-specific
103         // name of the group that enables connecting to raillike nodes of different kind
104         static const std::string raillike_groupname;
105         int raillike_group;
106         bool isSameRail(v3s16 dir);
107
108 // plantlike-specific
109         PlantlikeStyle draw_style;
110         v3f offset;
111         int rotate_degree;
112         bool random_offset_Y;
113         int face_num;
114
115         void drawPlantlikeQuad(float rotation, float quad_offset = 0,
116                 bool offset_top_only = false);
117
118 // firelike-specific
119         void drawFirelikeQuad(float rotation, float opening_angle,
120                 float offset_h, float offset_v = 0.0);
121
122 // drawtypes
123         void drawLiquidNode();
124         void drawGlasslikeNode();
125         void drawGlasslikeFramedNode();
126         void drawAllfacesNode();
127         void drawTorchlikeNode();
128         void drawSignlikeNode();
129         void drawPlantlikeNode();
130         void drawFirelikeNode();
131         void drawFencelikeNode();
132         void drawRaillikeNode();
133         void drawNodeboxNode();
134         void drawMeshNode();
135
136 // common
137         void errorUnknownDrawtype();
138         void drawNode();
139
140 public:
141         MapblockMeshGenerator(MeshMakeData *input, MeshCollector *output);
142         void generate();
143 };
144
145 #endif