mirror of
https://github.com/minetest/minetest.git
synced 2024-11-30 11:33:44 +01:00
Cleanup selection mesh code, add shaders for halo and selection boxes
This commit is contained in:
parent
430195381d
commit
b44da4916a
@ -279,6 +279,9 @@ enable_clouds (Clouds) bool true
|
|||||||
# Use 3D cloud look instead of flat.
|
# Use 3D cloud look instead of flat.
|
||||||
enable_3d_clouds (3D clouds) bool true
|
enable_3d_clouds (3D clouds) bool true
|
||||||
|
|
||||||
|
# Method used to highlight selected object.
|
||||||
|
node_highlighting (Node highlighting) enum box box,halo
|
||||||
|
|
||||||
[***Filtering]
|
[***Filtering]
|
||||||
|
|
||||||
# Use mip mapping to scale textures. May slightly increase performance.
|
# Use mip mapping to scale textures. May slightly increase performance.
|
||||||
@ -482,9 +485,6 @@ desynchronize_mapblock_texture_animation (Desynchronize block animation) bool tr
|
|||||||
# Useful if there's something to be displayed right or left of hotbar.
|
# Useful if there's something to be displayed right or left of hotbar.
|
||||||
hud_hotbar_max_width (Maximum hotbar width) float 1.0
|
hud_hotbar_max_width (Maximum hotbar width) float 1.0
|
||||||
|
|
||||||
# Enable selection highlighting for nodes (disables selectionbox).
|
|
||||||
enable_node_highlighting (Node highlighting) bool false
|
|
||||||
|
|
||||||
# Enables caching of facedir rotated meshes.
|
# Enables caching of facedir rotated meshes.
|
||||||
enable_mesh_cache (Mesh cache) bool false
|
enable_mesh_cache (Mesh cache) bool false
|
||||||
|
|
||||||
|
4
client/shaders/default_shader/opengl_fragment.glsl
Normal file
4
client/shaders/default_shader/opengl_fragment.glsl
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
gl_FragColor = gl_Color;
|
||||||
|
}
|
9
client/shaders/default_shader/opengl_vertex.glsl
Normal file
9
client/shaders/default_shader/opengl_vertex.glsl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
uniform mat4 mWorldViewProj;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
gl_Position = mWorldViewProj * gl_Vertex;
|
||||||
|
|
||||||
|
gl_FrontColor = gl_BackColor = gl_Color;
|
||||||
|
}
|
9
client/shaders/selection_shader/opengl_fragment.glsl
Normal file
9
client/shaders/selection_shader/opengl_fragment.glsl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
uniform sampler2D baseTexture;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
vec2 uv = gl_TexCoord[0].st;
|
||||||
|
vec4 color = texture2D(baseTexture, uv);
|
||||||
|
color.rgb *= gl_Color.rgb;
|
||||||
|
gl_FragColor = color;
|
||||||
|
}
|
9
client/shaders/selection_shader/opengl_vertex.glsl
Normal file
9
client/shaders/selection_shader/opengl_vertex.glsl
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
uniform mat4 mWorldViewProj;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
|
{
|
||||||
|
gl_TexCoord[0] = gl_MultiTexCoord0;
|
||||||
|
gl_Position = mWorldViewProj * gl_Vertex;
|
||||||
|
|
||||||
|
gl_FrontColor = gl_BackColor = gl_Color;
|
||||||
|
}
|
@ -555,9 +555,9 @@
|
|||||||
# type: float
|
# type: float
|
||||||
# hud_hotbar_max_width = 1.0
|
# hud_hotbar_max_width = 1.0
|
||||||
|
|
||||||
# Enable selection highlighting for nodes (disables selectionbox).
|
# Selection highlighting method (box or halo)
|
||||||
# type: bool
|
# type: string
|
||||||
# enable_node_highlighting = false
|
# node_highlighting = box
|
||||||
|
|
||||||
# Enables caching of facedir rotated meshes.
|
# Enables caching of facedir rotated meshes.
|
||||||
# type: bool
|
# type: bool
|
||||||
|
@ -235,11 +235,9 @@ Client::Client(
|
|||||||
m_inventory_updated(false),
|
m_inventory_updated(false),
|
||||||
m_inventory_from_server(NULL),
|
m_inventory_from_server(NULL),
|
||||||
m_inventory_from_server_age(0.0),
|
m_inventory_from_server_age(0.0),
|
||||||
m_show_highlighted(false),
|
|
||||||
m_animation_time(0),
|
m_animation_time(0),
|
||||||
m_crack_level(-1),
|
m_crack_level(-1),
|
||||||
m_crack_pos(0,0,0),
|
m_crack_pos(0,0,0),
|
||||||
m_highlighted_pos(0,0,0),
|
|
||||||
m_map_seed(0),
|
m_map_seed(0),
|
||||||
m_password(password),
|
m_password(password),
|
||||||
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
|
m_chosen_auth_mech(AUTH_MECHANISM_NONE),
|
||||||
@ -1508,15 +1506,6 @@ int Client::getCrackLevel()
|
|||||||
return m_crack_level;
|
return m_crack_level;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::setHighlighted(v3s16 pos, bool show_highlighted)
|
|
||||||
{
|
|
||||||
m_show_highlighted = show_highlighted;
|
|
||||||
v3s16 old_highlighted_pos = m_highlighted_pos;
|
|
||||||
m_highlighted_pos = pos;
|
|
||||||
addUpdateMeshTaskForNode(old_highlighted_pos, false, true);
|
|
||||||
addUpdateMeshTaskForNode(m_highlighted_pos, false, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Client::setCrack(int level, v3s16 pos)
|
void Client::setCrack(int level, v3s16 pos)
|
||||||
{
|
{
|
||||||
int old_crack_level = m_crack_level;
|
int old_crack_level = m_crack_level;
|
||||||
@ -1601,7 +1590,6 @@ void Client::addUpdateMeshTask(v3s16 p, bool ack_to_server, bool urgent)
|
|||||||
// Debug: 1-6ms, avg=2ms
|
// Debug: 1-6ms, avg=2ms
|
||||||
data->fill(b);
|
data->fill(b);
|
||||||
data->setCrack(m_crack_level, m_crack_pos);
|
data->setCrack(m_crack_level, m_crack_pos);
|
||||||
data->setHighlighted(m_highlighted_pos, m_show_highlighted);
|
|
||||||
data->setSmoothLighting(m_cache_smooth_lighting);
|
data->setSmoothLighting(m_cache_smooth_lighting);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -456,9 +456,6 @@ public:
|
|||||||
int getCrackLevel();
|
int getCrackLevel();
|
||||||
void setCrack(int level, v3s16 pos);
|
void setCrack(int level, v3s16 pos);
|
||||||
|
|
||||||
void setHighlighted(v3s16 pos, bool show_higlighted);
|
|
||||||
v3s16 getHighlighted(){ return m_highlighted_pos; }
|
|
||||||
|
|
||||||
u16 getHP();
|
u16 getHP();
|
||||||
u16 getBreath();
|
u16 getBreath();
|
||||||
|
|
||||||
@ -609,12 +606,10 @@ private:
|
|||||||
Inventory *m_inventory_from_server;
|
Inventory *m_inventory_from_server;
|
||||||
float m_inventory_from_server_age;
|
float m_inventory_from_server_age;
|
||||||
PacketCounter m_packetcounter;
|
PacketCounter m_packetcounter;
|
||||||
bool m_show_highlighted;
|
|
||||||
// Block mesh animation parameters
|
// Block mesh animation parameters
|
||||||
float m_animation_time;
|
float m_animation_time;
|
||||||
int m_crack_level;
|
int m_crack_level;
|
||||||
v3s16 m_crack_pos;
|
v3s16 m_crack_pos;
|
||||||
v3s16 m_highlighted_pos;
|
|
||||||
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
|
// 0 <= m_daynight_i < DAYNIGHT_CACHE_COUNT
|
||||||
//s32 m_daynight_i;
|
//s32 m_daynight_i;
|
||||||
//u32 m_daynight_ratio;
|
//u32 m_daynight_ratio;
|
||||||
|
@ -171,7 +171,6 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
MeshCollector &collector)
|
MeshCollector &collector)
|
||||||
{
|
{
|
||||||
INodeDefManager *nodedef = data->m_gamedef->ndef();
|
INodeDefManager *nodedef = data->m_gamedef->ndef();
|
||||||
ITextureSource *tsrc = data->m_gamedef->tsrc();
|
|
||||||
scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
|
scene::ISceneManager* smgr = data->m_gamedef->getSceneManager();
|
||||||
scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
|
scene::IMeshManipulator* meshmanip = smgr->getMeshManipulator();
|
||||||
|
|
||||||
@ -1615,55 +1614,5 @@ void mapblock_mesh_generate_special(MeshMakeData *data,
|
|||||||
break;}
|
break;}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Caused by incorrect alpha blending, selection mesh needs to be created as
|
|
||||||
last element to ensure it gets blended correct over nodes with alpha channel
|
|
||||||
*/
|
|
||||||
// Create selection mesh
|
|
||||||
v3s16 p = data->m_highlighted_pos_relative;
|
|
||||||
if (data->m_show_hud &&
|
|
||||||
(p.X >= 0) && (p.X < MAP_BLOCKSIZE) &&
|
|
||||||
(p.Y >= 0) && (p.Y < MAP_BLOCKSIZE) &&
|
|
||||||
(p.Z >= 0) && (p.Z < MAP_BLOCKSIZE)) {
|
|
||||||
|
|
||||||
MapNode n = data->m_vmanip.getNodeNoEx(blockpos_nodes + p);
|
|
||||||
if(n.getContent() != CONTENT_AIR) {
|
|
||||||
// Get selection mesh light level
|
|
||||||
static const v3s16 dirs[7] = {
|
|
||||||
v3s16( 0, 0, 0),
|
|
||||||
v3s16( 0, 1, 0),
|
|
||||||
v3s16( 0,-1, 0),
|
|
||||||
v3s16( 1, 0, 0),
|
|
||||||
v3s16(-1, 0, 0),
|
|
||||||
v3s16( 0, 0, 1),
|
|
||||||
v3s16( 0, 0,-1)
|
|
||||||
};
|
|
||||||
|
|
||||||
u16 l = 0;
|
|
||||||
u16 l1 = 0;
|
|
||||||
for (u8 i = 0; i < 7; i++) {
|
|
||||||
MapNode n1 = data->m_vmanip.getNodeNoEx(blockpos_nodes + p + dirs[i]);
|
|
||||||
l1 = getInteriorLight(n1, -4, nodedef);
|
|
||||||
if (l1 > l)
|
|
||||||
l = l1;
|
|
||||||
}
|
|
||||||
video::SColor c = MapBlock_LightColor(255, l, 0);
|
|
||||||
data->m_highlight_mesh_color = c;
|
|
||||||
std::vector<aabb3f> boxes = n.getSelectionBoxes(nodedef);
|
|
||||||
TileSpec h_tile;
|
|
||||||
h_tile.material_flags |= MATERIAL_FLAG_HIGHLIGHTED;
|
|
||||||
h_tile.texture = tsrc->getTextureForMesh("halo.png",&h_tile.texture_id);
|
|
||||||
v3f pos = intToFloat(p, BS);
|
|
||||||
f32 d = 0.05 * BS;
|
|
||||||
for (std::vector<aabb3f>::iterator i = boxes.begin();
|
|
||||||
i != boxes.end(); ++i) {
|
|
||||||
aabb3f box = *i;
|
|
||||||
box.MinEdge += v3f(-d, -d, -d) + pos;
|
|
||||||
box.MaxEdge += v3f(d, d, d) + pos;
|
|
||||||
makeCuboid(&collector, box, &h_tile, 1, c, NULL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -137,8 +137,9 @@ void set_default_settings(Settings *settings)
|
|||||||
settings->setDefault("console_color", "(0,0,0)");
|
settings->setDefault("console_color", "(0,0,0)");
|
||||||
settings->setDefault("console_alpha", "200");
|
settings->setDefault("console_alpha", "200");
|
||||||
settings->setDefault("selectionbox_color", "(0,0,0)");
|
settings->setDefault("selectionbox_color", "(0,0,0)");
|
||||||
settings->setDefault("enable_node_highlighting", "false");
|
settings->setDefault("selectionbox_width", "2");
|
||||||
settings->setDefault("inventory_items_animations", "false");
|
settings->setDefault("inventory_items_animations", "false");
|
||||||
|
settings->setDefault("node_highlighting", "box");
|
||||||
settings->setDefault("crosshair_color", "(255,255,255)");
|
settings->setDefault("crosshair_color", "(255,255,255)");
|
||||||
settings->setDefault("crosshair_alpha", "255");
|
settings->setDefault("crosshair_alpha", "255");
|
||||||
settings->setDefault("hud_scaling", "1.0");
|
settings->setDefault("hud_scaling", "1.0");
|
||||||
@ -149,8 +150,7 @@ void set_default_settings(Settings *settings)
|
|||||||
settings->setDefault("enable_sound", "true");
|
settings->setDefault("enable_sound", "true");
|
||||||
settings->setDefault("sound_volume", "0.8");
|
settings->setDefault("sound_volume", "0.8");
|
||||||
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
|
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
|
||||||
settings->setDefault("selectionbox_width","2");
|
settings->setDefault("hud_hotbar_max_width", "1.0");
|
||||||
settings->setDefault("hud_hotbar_max_width","1.0");
|
|
||||||
settings->setDefault("enable_local_map_saving", "false");
|
settings->setDefault("enable_local_map_saving", "false");
|
||||||
|
|
||||||
settings->setDefault("mip_map", "false");
|
settings->setDefault("mip_map", "false");
|
||||||
|
@ -31,27 +31,9 @@ typedef enum {
|
|||||||
EYECOUNT = 2
|
EYECOUNT = 2
|
||||||
} paralax_sign;
|
} paralax_sign;
|
||||||
|
|
||||||
|
|
||||||
void draw_selectionbox(video::IVideoDriver* driver, Hud& hud,
|
|
||||||
std::vector<aabb3f>& hilightboxes, bool show_hud)
|
|
||||||
{
|
|
||||||
static const s16 selectionbox_width = rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
|
|
||||||
|
|
||||||
if (!show_hud)
|
|
||||||
return;
|
|
||||||
|
|
||||||
video::SMaterial oldmaterial = driver->getMaterial2D();
|
|
||||||
video::SMaterial m;
|
|
||||||
m.Thickness = selectionbox_width;
|
|
||||||
m.Lighting = false;
|
|
||||||
driver->setMaterial(m);
|
|
||||||
hud.drawSelectionBoxes(hilightboxes);
|
|
||||||
driver->setMaterial(oldmaterial);
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
|
void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
|
||||||
std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
video::IVideoDriver* driver, scene::ISceneManager* smgr,
|
||||||
scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
|
bool draw_wield_tool, Client& client,
|
||||||
gui::IGUIEnvironment* guienv )
|
gui::IGUIEnvironment* guienv )
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -85,10 +67,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
|
|||||||
camera.getCameraNode()->setTarget(focusPoint);
|
camera.getCameraNode()->setTarget(focusPoint);
|
||||||
smgr->drawAll();
|
smgr->drawAll();
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
if (show_hud)
|
if (show_hud) {
|
||||||
{
|
hud.drawSelectionMesh();
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
|
||||||
|
|
||||||
if (draw_wield_tool)
|
if (draw_wield_tool)
|
||||||
camera.drawWieldedTool(&leftMove);
|
camera.drawWieldedTool(&leftMove);
|
||||||
}
|
}
|
||||||
@ -115,10 +95,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
|
|||||||
camera.getCameraNode()->setTarget(focusPoint);
|
camera.getCameraNode()->setTarget(focusPoint);
|
||||||
smgr->drawAll();
|
smgr->drawAll();
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
if (show_hud)
|
if (show_hud) {
|
||||||
{
|
hud.drawSelectionMesh();
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
|
||||||
|
|
||||||
if (draw_wield_tool)
|
if (draw_wield_tool)
|
||||||
camera.drawWieldedTool(&rightMove);
|
camera.drawWieldedTool(&rightMove);
|
||||||
}
|
}
|
||||||
@ -144,16 +122,15 @@ void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
|
|||||||
irr::video::ECF_A8R8G8B8);
|
irr::video::ECF_A8R8G8B8);
|
||||||
}
|
}
|
||||||
|
|
||||||
video::ITexture* draw_image(const v2u32& screensize,
|
video::ITexture* draw_image(const v2u32 &screensize,
|
||||||
paralax_sign psign, const irr::core::matrix4& startMatrix,
|
paralax_sign psign, const irr::core::matrix4 &startMatrix,
|
||||||
const irr::core::vector3df& focusPoint, bool show_hud,
|
const irr::core::vector3df &focusPoint, bool show_hud,
|
||||||
video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
|
video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
|
||||||
Hud& hud, std::vector<aabb3f>& hilightboxes,
|
Hud &hud, bool draw_wield_tool, Client &client,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
|
||||||
video::SColor skycolor )
|
|
||||||
{
|
{
|
||||||
static video::ITexture* images[2] = { NULL, NULL };
|
static video::ITexture* images[2] = { NULL, NULL };
|
||||||
static v2u32 last_screensize = v2u32(0,0);
|
static v2u32 last_screensize = v2u32(0, 0);
|
||||||
|
|
||||||
video::ITexture* image = NULL;
|
video::ITexture* image = NULL;
|
||||||
|
|
||||||
@ -187,10 +164,8 @@ video::ITexture* draw_image(const v2u32& screensize,
|
|||||||
|
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
|
|
||||||
if (show_hud)
|
if (show_hud) {
|
||||||
{
|
hud.drawSelectionMesh();
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
|
||||||
|
|
||||||
if (draw_wield_tool)
|
if (draw_wield_tool)
|
||||||
camera.drawWieldedTool(&movement);
|
camera.drawWieldedTool(&movement);
|
||||||
}
|
}
|
||||||
@ -232,7 +207,7 @@ video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
||||||
Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
Hud& hud, video::IVideoDriver* driver,
|
||||||
scene::ISceneManager* smgr, const v2u32& screensize,
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
||||||
video::SColor skycolor )
|
video::SColor skycolor )
|
||||||
@ -248,7 +223,7 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
|||||||
|
|
||||||
/* create left view */
|
/* create left view */
|
||||||
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
||||||
focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
||||||
draw_wield_tool, client, guienv, skycolor);
|
draw_wield_tool, client, guienv, skycolor);
|
||||||
|
|
||||||
//Right eye...
|
//Right eye...
|
||||||
@ -267,10 +242,8 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
|||||||
|
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
|
|
||||||
if (show_hud)
|
if (show_hud) {
|
||||||
{
|
hud.drawSelectionMesh();
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
|
||||||
|
|
||||||
if(draw_wield_tool)
|
if(draw_wield_tool)
|
||||||
camera.drawWieldedTool(&rightMove);
|
camera.drawWieldedTool(&rightMove);
|
||||||
}
|
}
|
||||||
@ -293,7 +266,7 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
|
void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
|
||||||
Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
Hud& hud, video::IVideoDriver* driver,
|
||||||
scene::ISceneManager* smgr, const v2u32& screensize,
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
||||||
video::SColor skycolor )
|
video::SColor skycolor )
|
||||||
@ -309,12 +282,12 @@ void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
|
|||||||
|
|
||||||
/* create left view */
|
/* create left view */
|
||||||
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
||||||
focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
||||||
draw_wield_tool, client, guienv, skycolor);
|
draw_wield_tool, client, guienv, skycolor);
|
||||||
|
|
||||||
/* create right view */
|
/* create right view */
|
||||||
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
||||||
focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
||||||
draw_wield_tool, client, guienv, skycolor);
|
draw_wield_tool, client, guienv, skycolor);
|
||||||
|
|
||||||
/* create hud overlay */
|
/* create hud overlay */
|
||||||
@ -349,7 +322,7 @@ void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
|
void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
|
||||||
Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
Hud& hud, video::IVideoDriver* driver,
|
||||||
scene::ISceneManager* smgr, const v2u32& screensize,
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
||||||
video::SColor skycolor )
|
video::SColor skycolor )
|
||||||
@ -365,12 +338,12 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
|
|||||||
|
|
||||||
/* create left view */
|
/* create left view */
|
||||||
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
video::ITexture* left_image = draw_image(screensize, LEFT, startMatrix,
|
||||||
focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
||||||
draw_wield_tool, client, guienv, skycolor);
|
draw_wield_tool, client, guienv, skycolor);
|
||||||
|
|
||||||
/* create right view */
|
/* create right view */
|
||||||
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
video::ITexture* right_image = draw_image(screensize, RIGHT, startMatrix,
|
||||||
focusPoint, show_hud, driver, camera, smgr, hud, hilightboxes,
|
focusPoint, show_hud, driver, camera, smgr, hud,
|
||||||
draw_wield_tool, client, guienv, skycolor);
|
draw_wield_tool, client, guienv, skycolor);
|
||||||
|
|
||||||
/* create hud overlay */
|
/* create hud overlay */
|
||||||
@ -405,7 +378,7 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
|
|||||||
}
|
}
|
||||||
|
|
||||||
void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
||||||
Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
Hud& hud, video::IVideoDriver* driver,
|
||||||
scene::ISceneManager* smgr, const v2u32& screensize,
|
scene::ISceneManager* smgr, const v2u32& screensize,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
|
||||||
video::SColor skycolor)
|
video::SColor skycolor)
|
||||||
@ -438,11 +411,9 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
|||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
|
|
||||||
if (show_hud) {
|
if (show_hud) {
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
hud.drawSelectionMesh();
|
||||||
|
|
||||||
if (draw_wield_tool)
|
if (draw_wield_tool)
|
||||||
camera.drawWieldedTool(&leftMove);
|
camera.drawWieldedTool(&leftMove);
|
||||||
|
|
||||||
hud.drawHotbar(client.getPlayerItem());
|
hud.drawHotbar(client.getPlayerItem());
|
||||||
hud.drawLuaElements(camera.getOffset());
|
hud.drawLuaElements(camera.getOffset());
|
||||||
}
|
}
|
||||||
@ -467,11 +438,9 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
|||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
|
|
||||||
if (show_hud) {
|
if (show_hud) {
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
hud.drawSelectionMesh();
|
||||||
|
|
||||||
if (draw_wield_tool)
|
if (draw_wield_tool)
|
||||||
camera.drawWieldedTool(&rightMove);
|
camera.drawWieldedTool(&rightMove);
|
||||||
|
|
||||||
hud.drawHotbar(client.getPlayerItem());
|
hud.drawHotbar(client.getPlayerItem());
|
||||||
hud.drawLuaElements(camera.getOffset());
|
hud.drawLuaElements(camera.getOffset());
|
||||||
}
|
}
|
||||||
@ -482,23 +451,24 @@ void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
|
|||||||
camera.getCameraNode()->setTarget(oldTarget);
|
camera.getCameraNode()->setTarget(oldTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_plain(Camera& camera, bool show_hud, Hud& hud,
|
void draw_plain(Camera &camera, bool show_hud, Hud &hud,
|
||||||
std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
|
video::IVideoDriver *driver, bool draw_wield_tool,
|
||||||
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
|
Client &client, gui::IGUIEnvironment *guienv)
|
||||||
{
|
{
|
||||||
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
|
||||||
|
if (show_hud) {
|
||||||
draw_selectionbox(driver, hud, hilightboxes, show_hud);
|
hud.drawSelectionMesh();
|
||||||
|
if (draw_wield_tool) {
|
||||||
if(draw_wield_tool)
|
camera.drawWieldedTool();
|
||||||
camera.drawWieldedTool();
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
||||||
Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
|
Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
|
||||||
Mapper &mapper, gui::IGUIEnvironment *guienv,
|
Mapper &mapper, gui::IGUIEnvironment *guienv,
|
||||||
std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
|
const v2u32 &screensize, const video::SColor &skycolor,
|
||||||
video::SColor skycolor, bool show_hud, bool show_minimap)
|
bool show_hud, bool show_minimap)
|
||||||
{
|
{
|
||||||
TimeTaker timer("smgr");
|
TimeTaker timer("smgr");
|
||||||
|
|
||||||
@ -522,37 +492,37 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
|||||||
|
|
||||||
if (draw_mode == "anaglyph")
|
if (draw_mode == "anaglyph")
|
||||||
{
|
{
|
||||||
draw_anaglyph_3d_mode(camera, show_hud, hud, hilightboxes, driver,
|
draw_anaglyph_3d_mode(camera, show_hud, hud, driver,
|
||||||
smgr, draw_wield_tool, client, guienv);
|
smgr, draw_wield_tool, client, guienv);
|
||||||
draw_crosshair = false;
|
draw_crosshair = false;
|
||||||
}
|
}
|
||||||
else if (draw_mode == "interlaced")
|
else if (draw_mode == "interlaced")
|
||||||
{
|
{
|
||||||
draw_interlaced_3d_mode(camera, show_hud, hud, hilightboxes, driver,
|
draw_interlaced_3d_mode(camera, show_hud, hud, driver,
|
||||||
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
||||||
draw_crosshair = false;
|
draw_crosshair = false;
|
||||||
}
|
}
|
||||||
else if (draw_mode == "sidebyside")
|
else if (draw_mode == "sidebyside")
|
||||||
{
|
{
|
||||||
draw_sidebyside_3d_mode(camera, show_hud, hud, hilightboxes, driver,
|
draw_sidebyside_3d_mode(camera, show_hud, hud, driver,
|
||||||
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
||||||
show_hud = false;
|
show_hud = false;
|
||||||
}
|
}
|
||||||
else if (draw_mode == "topbottom")
|
else if (draw_mode == "topbottom")
|
||||||
{
|
{
|
||||||
draw_top_bottom_3d_mode(camera, show_hud, hud, hilightboxes, driver,
|
draw_top_bottom_3d_mode(camera, show_hud, hud, driver,
|
||||||
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
||||||
show_hud = false;
|
show_hud = false;
|
||||||
}
|
}
|
||||||
else if (draw_mode == "pageflip")
|
else if (draw_mode == "pageflip")
|
||||||
{
|
{
|
||||||
draw_pageflip_3d_mode(camera, show_hud, hud, hilightboxes, driver,
|
draw_pageflip_3d_mode(camera, show_hud, hud, driver,
|
||||||
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
smgr, screensize, draw_wield_tool, client, guienv, skycolor);
|
||||||
draw_crosshair = false;
|
draw_crosshair = false;
|
||||||
show_hud = false;
|
show_hud = false;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
draw_plain(camera, show_hud, hud, hilightboxes, driver,
|
draw_plain(camera, show_hud, hud, driver,
|
||||||
draw_wield_tool, client, guienv);
|
draw_wield_tool, client, guienv);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -31,9 +31,9 @@ void draw_load_screen(const std::wstring &text, IrrlichtDevice *device,
|
|||||||
bool clouds = true);
|
bool clouds = true);
|
||||||
|
|
||||||
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
|
||||||
Camera &camera, Client &client, LocalPlayer *player, Hud &hud,
|
Camera &camera, Client &client, LocalPlayer *player,
|
||||||
Mapper &mapper, gui::IGUIEnvironment *guienv,
|
Hud &hud, Mapper &mapper, gui::IGUIEnvironment *guienv,
|
||||||
std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
|
const v2u32 &screensize, const video::SColor &skycolor,
|
||||||
video::SColor skycolor, bool show_hud, bool show_minimap);
|
bool show_hud, bool show_minimap);
|
||||||
|
|
||||||
#endif /* DRAWSCENE_H_ */
|
#endif /* DRAWSCENE_H_ */
|
||||||
|
123
src/game.cpp
123
src/game.cpp
@ -57,6 +57,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "util/pointedthing.h"
|
#include "util/pointedthing.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "minimap.h"
|
#include "minimap.h"
|
||||||
|
#include "mapblock_mesh.h"
|
||||||
|
|
||||||
#include "sound.h"
|
#include "sound.h"
|
||||||
|
|
||||||
@ -288,14 +289,16 @@ inline bool isPointableNode(const MapNode &n,
|
|||||||
/*
|
/*
|
||||||
Find what the player is pointing at
|
Find what the player is pointing at
|
||||||
*/
|
*/
|
||||||
PointedThing getPointedThing(Client *client, v3f player_position,
|
PointedThing getPointedThing(Client *client, Hud *hud, const v3f &player_position,
|
||||||
v3f camera_direction, v3f camera_position, core::line3d<f32> shootline,
|
const v3f &camera_direction, const v3f &camera_position,
|
||||||
f32 d, bool liquids_pointable, bool look_for_object, v3s16 camera_offset,
|
core::line3d<f32> shootline, f32 d, bool liquids_pointable,
|
||||||
std::vector<aabb3f> &hilightboxes, ClientActiveObject *&selected_object)
|
bool look_for_object, const v3s16 &camera_offset,
|
||||||
|
ClientActiveObject *&selected_object)
|
||||||
{
|
{
|
||||||
PointedThing result;
|
PointedThing result;
|
||||||
|
|
||||||
hilightboxes.clear();
|
std::vector<aabb3f> *selectionboxes = hud->getSelectionBoxes();
|
||||||
|
selectionboxes->clear();
|
||||||
selected_object = NULL;
|
selected_object = NULL;
|
||||||
|
|
||||||
INodeDefManager *nodedef = client->getNodeDefManager();
|
INodeDefManager *nodedef = client->getNodeDefManager();
|
||||||
@ -316,9 +319,9 @@ PointedThing getPointedThing(Client *client, v3f player_position,
|
|||||||
assert(selection_box);
|
assert(selection_box);
|
||||||
|
|
||||||
v3f pos = selected_object->getPosition();
|
v3f pos = selected_object->getPosition();
|
||||||
hilightboxes.push_back(aabb3f(
|
selectionboxes->push_back(aabb3f(
|
||||||
selection_box->MinEdge + pos - intToFloat(camera_offset, BS),
|
selection_box->MinEdge, selection_box->MaxEdge));
|
||||||
selection_box->MaxEdge + pos - intToFloat(camera_offset, BS)));
|
hud->setSelectionPos(pos, camera_offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
mindistance = (selected_object->getPosition() - camera_position).getLength();
|
mindistance = (selected_object->getPosition() - camera_position).getLength();
|
||||||
@ -414,22 +417,56 @@ PointedThing getPointedThing(Client *client, v3f player_position,
|
|||||||
result.node_abovesurface = np_above;
|
result.node_abovesurface = np_above;
|
||||||
mindistance = distance;
|
mindistance = distance;
|
||||||
|
|
||||||
hilightboxes.clear();
|
selectionboxes->clear();
|
||||||
|
for (std::vector<aabb3f>::const_iterator
|
||||||
if (!g_settings->getBool("enable_node_highlighting")) {
|
i2 = boxes.begin();
|
||||||
for (std::vector<aabb3f>::const_iterator
|
i2 != boxes.end(); ++i2) {
|
||||||
i2 = boxes.begin();
|
aabb3f box = *i2;
|
||||||
i2 != boxes.end(); ++i2) {
|
box.MinEdge += v3f(-d, -d, -d);
|
||||||
aabb3f box = *i2;
|
box.MaxEdge += v3f(d, d, d);
|
||||||
box.MinEdge += npf + v3f(-d, -d, -d) - intToFloat(camera_offset, BS);
|
selectionboxes->push_back(box);
|
||||||
box.MaxEdge += npf + v3f(d, d, d) - intToFloat(camera_offset, BS);
|
|
||||||
hilightboxes.push_back(box);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
hud->setSelectionPos(npf, camera_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // for coords
|
} // for coords
|
||||||
|
|
||||||
|
// Update selection mesh light level and vertex colors
|
||||||
|
if (selectionboxes->size() > 0) {
|
||||||
|
v3f pf = hud->getSelectionPos();
|
||||||
|
v3s16 p = floatToInt(pf, BS);
|
||||||
|
|
||||||
|
// Get selection mesh light level
|
||||||
|
MapNode n = map.getNodeNoEx(p);
|
||||||
|
u16 node_light = getInteriorLight(n, -1, nodedef);
|
||||||
|
u16 light_level = node_light;
|
||||||
|
|
||||||
|
for (u8 i = 0; i < 6; i++) {
|
||||||
|
n = map.getNodeNoEx(p + g_6dirs[i]);
|
||||||
|
node_light = getInteriorLight(n, -1, nodedef);
|
||||||
|
if (node_light > light_level)
|
||||||
|
light_level = node_light;
|
||||||
|
}
|
||||||
|
|
||||||
|
video::SColor c = MapBlock_LightColor(255, light_level, 0);
|
||||||
|
u8 day = c.getRed();
|
||||||
|
u8 night = c.getGreen();
|
||||||
|
u32 daynight_ratio = client->getEnv().getDayNightRatio();
|
||||||
|
finalColorBlend(c, day, night, daynight_ratio);
|
||||||
|
|
||||||
|
// Modify final color a bit with time
|
||||||
|
u32 timer = porting::getTimeMs() % 5000;
|
||||||
|
float timerf = (float)(irr::core::PI * ((timer / 2500.0) - 0.5));
|
||||||
|
float sin_r = 0.08 * sin(timerf);
|
||||||
|
float sin_g = 0.08 * sin(timerf + irr::core::PI * 0.5);
|
||||||
|
float sin_b = 0.08 * sin(timerf + irr::core::PI);
|
||||||
|
c.setRed(core::clamp(core::round32(c.getRed() * (0.8 + sin_r)), 0, 255));
|
||||||
|
c.setGreen(core::clamp(core::round32(c.getGreen() * (0.8 + sin_g)), 0, 255));
|
||||||
|
c.setBlue(core::clamp(core::round32(c.getBlue() * (0.8 + sin_b)), 0, 255));
|
||||||
|
|
||||||
|
// Set mesh final color
|
||||||
|
hud->setSelectionMeshColor(c);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1522,8 +1559,7 @@ protected:
|
|||||||
void updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime,
|
void updateCamera(VolatileRunFlags *flags, u32 busy_time, f32 dtime,
|
||||||
float time_from_last_punch);
|
float time_from_last_punch);
|
||||||
void updateSound(f32 dtime);
|
void updateSound(f32 dtime);
|
||||||
void processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
|
void processPlayerInteraction(GameRunData *runData, f32 dtime, bool show_hud,
|
||||||
GameRunData *runData, f32 dtime, bool show_hud,
|
|
||||||
bool show_debug);
|
bool show_debug);
|
||||||
void handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem);
|
void handlePointingAtNothing(GameRunData *runData, const ItemStack &playerItem);
|
||||||
void handlePointingAtNode(GameRunData *runData,
|
void handlePointingAtNode(GameRunData *runData,
|
||||||
@ -1535,8 +1571,7 @@ protected:
|
|||||||
void handleDigging(GameRunData *runData, const PointedThing &pointed,
|
void handleDigging(GameRunData *runData, const PointedThing &pointed,
|
||||||
const v3s16 &nodepos, const ToolCapabilities &playeritem_toolcap,
|
const v3s16 &nodepos, const ToolCapabilities &playeritem_toolcap,
|
||||||
f32 dtime);
|
f32 dtime);
|
||||||
void updateFrame(std::vector<aabb3f> &highlight_boxes, ProfilerGraph *graph,
|
void updateFrame(ProfilerGraph *graph, RunStats *stats, GameRunData *runData,
|
||||||
RunStats *stats, GameRunData *runData,
|
|
||||||
f32 dtime, const VolatileRunFlags &flags, const CameraOrientation &cam);
|
f32 dtime, const VolatileRunFlags &flags, const CameraOrientation &cam);
|
||||||
void updateGui(float *statustext_time, const RunStats &stats,
|
void updateGui(float *statustext_time, const RunStats &stats,
|
||||||
const GameRunData& runData, f32 dtime, const VolatileRunFlags &flags,
|
const GameRunData& runData, f32 dtime, const VolatileRunFlags &flags,
|
||||||
@ -1630,7 +1665,6 @@ private:
|
|||||||
* a later release.
|
* a later release.
|
||||||
*/
|
*/
|
||||||
bool m_cache_doubletap_jump;
|
bool m_cache_doubletap_jump;
|
||||||
bool m_cache_enable_node_highlighting;
|
|
||||||
bool m_cache_enable_clouds;
|
bool m_cache_enable_clouds;
|
||||||
bool m_cache_enable_particles;
|
bool m_cache_enable_particles;
|
||||||
bool m_cache_enable_fog;
|
bool m_cache_enable_fog;
|
||||||
@ -1668,8 +1702,6 @@ Game::Game() :
|
|||||||
{
|
{
|
||||||
g_settings->registerChangedCallback("doubletap_jump",
|
g_settings->registerChangedCallback("doubletap_jump",
|
||||||
&settingChangedCallback, this);
|
&settingChangedCallback, this);
|
||||||
g_settings->registerChangedCallback("enable_node_highlighting",
|
|
||||||
&settingChangedCallback, this);
|
|
||||||
g_settings->registerChangedCallback("enable_clouds",
|
g_settings->registerChangedCallback("enable_clouds",
|
||||||
&settingChangedCallback, this);
|
&settingChangedCallback, this);
|
||||||
g_settings->registerChangedCallback("enable_particles",
|
g_settings->registerChangedCallback("enable_particles",
|
||||||
@ -1719,8 +1751,6 @@ Game::~Game()
|
|||||||
|
|
||||||
g_settings->deregisterChangedCallback("doubletap_jump",
|
g_settings->deregisterChangedCallback("doubletap_jump",
|
||||||
&settingChangedCallback, this);
|
&settingChangedCallback, this);
|
||||||
g_settings->deregisterChangedCallback("enable_node_highlighting",
|
|
||||||
&settingChangedCallback, this);
|
|
||||||
g_settings->deregisterChangedCallback("enable_clouds",
|
g_settings->deregisterChangedCallback("enable_clouds",
|
||||||
&settingChangedCallback, this);
|
&settingChangedCallback, this);
|
||||||
g_settings->deregisterChangedCallback("enable_particles",
|
g_settings->deregisterChangedCallback("enable_particles",
|
||||||
@ -1807,8 +1837,6 @@ void Game::run()
|
|||||||
&runData.fog_range,
|
&runData.fog_range,
|
||||||
client));
|
client));
|
||||||
|
|
||||||
std::vector<aabb3f> highlight_boxes;
|
|
||||||
|
|
||||||
set_light_table(g_settings->getFloat("display_gamma"));
|
set_light_table(g_settings->getFloat("display_gamma"));
|
||||||
|
|
||||||
#ifdef __ANDROID__
|
#ifdef __ANDROID__
|
||||||
@ -1858,10 +1886,9 @@ void Game::run()
|
|||||||
updateCamera(&flags, draw_times.busy_time, dtime,
|
updateCamera(&flags, draw_times.busy_time, dtime,
|
||||||
runData.time_from_last_punch);
|
runData.time_from_last_punch);
|
||||||
updateSound(dtime);
|
updateSound(dtime);
|
||||||
processPlayerInteraction(highlight_boxes, &runData, dtime,
|
processPlayerInteraction(&runData, dtime, flags.show_hud,
|
||||||
flags.show_hud, flags.show_debug);
|
flags.show_debug);
|
||||||
updateFrame(highlight_boxes, &graph, &stats, &runData, dtime,
|
updateFrame(&graph, &stats, &runData, dtime, flags, cam_view);
|
||||||
flags, cam_view);
|
|
||||||
updateProfilerGraphs(&graph);
|
updateProfilerGraphs(&graph);
|
||||||
|
|
||||||
// Update if minimap has been disabled by the server
|
// Update if minimap has been disabled by the server
|
||||||
@ -2888,8 +2915,6 @@ void Game::toggleHud(float *statustext_time, bool *flag)
|
|||||||
*flag = !*flag;
|
*flag = !*flag;
|
||||||
*statustext_time = 0;
|
*statustext_time = 0;
|
||||||
statustext = msg[*flag];
|
statustext = msg[*flag];
|
||||||
if (g_settings->getBool("enable_node_highlighting"))
|
|
||||||
client->setHighlighted(client->getHighlighted(), *flag);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::toggleMinimap(float *statustext_time, bool *flag,
|
void Game::toggleMinimap(float *statustext_time, bool *flag,
|
||||||
@ -3475,8 +3500,8 @@ void Game::updateSound(f32 dtime)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Game::processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
|
void Game::processPlayerInteraction(GameRunData *runData,
|
||||||
GameRunData *runData, f32 dtime, bool show_hud, bool show_debug)
|
f32 dtime, bool show_hud, bool show_debug)
|
||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
|
||||||
@ -3534,25 +3559,17 @@ void Game::processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
|
|||||||
|
|
||||||
PointedThing pointed = getPointedThing(
|
PointedThing pointed = getPointedThing(
|
||||||
// input
|
// input
|
||||||
client, player_position, camera_direction,
|
client, hud, player_position, camera_direction,
|
||||||
camera_position, shootline, d,
|
camera_position, shootline, d,
|
||||||
playeritem_def.liquids_pointable,
|
playeritem_def.liquids_pointable,
|
||||||
!runData->ldown_for_dig,
|
!runData->ldown_for_dig,
|
||||||
camera_offset,
|
camera_offset,
|
||||||
// output
|
// output
|
||||||
highlight_boxes,
|
|
||||||
runData->selected_object);
|
runData->selected_object);
|
||||||
|
|
||||||
if (pointed != runData->pointed_old) {
|
if (pointed != runData->pointed_old) {
|
||||||
infostream << "Pointing at " << pointed.dump() << std::endl;
|
infostream << "Pointing at " << pointed.dump() << std::endl;
|
||||||
|
hud->updateSelectionMesh(camera_offset);
|
||||||
if (m_cache_enable_node_highlighting) {
|
|
||||||
if (pointed.type == POINTEDTHING_NODE) {
|
|
||||||
client->setHighlighted(pointed.node_undersurface, show_hud);
|
|
||||||
} else {
|
|
||||||
client->setHighlighted(pointed.node_undersurface, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -3576,6 +3593,7 @@ void Game::processPlayerInteraction(std::vector<aabb3f> &highlight_boxes,
|
|||||||
infostream << "Pointing away from node"
|
infostream << "Pointing away from node"
|
||||||
<< " (stopped digging)" << std::endl;
|
<< " (stopped digging)" << std::endl;
|
||||||
runData->digging = false;
|
runData->digging = false;
|
||||||
|
hud->updateSelectionMesh(camera_offset);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3900,9 +3918,9 @@ void Game::handleDigging(GameRunData *runData,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
|
void Game::updateFrame(ProfilerGraph *graph, RunStats *stats,
|
||||||
ProfilerGraph *graph, RunStats *stats, GameRunData *runData,
|
GameRunData *runData, f32 dtime, const VolatileRunFlags &flags,
|
||||||
f32 dtime, const VolatileRunFlags &flags, const CameraOrientation &cam)
|
const CameraOrientation &cam)
|
||||||
{
|
{
|
||||||
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
LocalPlayer *player = client->getEnv().getLocalPlayer();
|
||||||
|
|
||||||
@ -4094,7 +4112,7 @@ void Game::updateFrame(std::vector<aabb3f> &highlight_boxes,
|
|||||||
}
|
}
|
||||||
|
|
||||||
draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper,
|
draw_scene(driver, smgr, *camera, *client, player, *hud, *mapper,
|
||||||
guienv, highlight_boxes, screensize, skycolor, flags.show_hud,
|
guienv, screensize, skycolor, flags.show_hud,
|
||||||
flags.show_minimap);
|
flags.show_minimap);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -4374,7 +4392,6 @@ void Game::settingChangedCallback(const std::string &setting_name, void *data)
|
|||||||
void Game::readSettings()
|
void Game::readSettings()
|
||||||
{
|
{
|
||||||
m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
|
m_cache_doubletap_jump = g_settings->getBool("doubletap_jump");
|
||||||
m_cache_enable_node_highlighting = g_settings->getBool("enable_node_highlighting");
|
|
||||||
m_cache_enable_clouds = g_settings->getBool("enable_clouds");
|
m_cache_enable_clouds = g_settings->getBool("enable_clouds");
|
||||||
m_cache_enable_particles = g_settings->getBool("enable_particles");
|
m_cache_enable_particles = g_settings->getBool("enable_particles");
|
||||||
m_cache_enable_fog = g_settings->getBool("enable_fog");
|
m_cache_enable_fog = g_settings->getBool("enable_fog");
|
||||||
|
116
src/hud.cpp
116
src/hud.cpp
@ -32,6 +32,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||||||
#include "porting.h"
|
#include "porting.h"
|
||||||
#include "fontengine.h"
|
#include "fontengine.h"
|
||||||
#include "guiscalingfilter.h"
|
#include "guiscalingfilter.h"
|
||||||
|
#include "mesh.h"
|
||||||
#include <IGUIStaticText.h>
|
#include <IGUIStaticText.h>
|
||||||
|
|
||||||
#ifdef HAVE_TOUCHSCREENGUI
|
#ifdef HAVE_TOUCHSCREENGUI
|
||||||
@ -80,6 +81,39 @@ Hud::Hud(video::IVideoDriver *driver, scene::ISceneManager* smgr,
|
|||||||
use_hotbar_image = false;
|
use_hotbar_image = false;
|
||||||
hotbar_selected_image = "";
|
hotbar_selected_image = "";
|
||||||
use_hotbar_selected_image = false;
|
use_hotbar_selected_image = false;
|
||||||
|
|
||||||
|
m_selection_mesh = NULL;
|
||||||
|
m_selection_boxes.clear();
|
||||||
|
m_selection_pos = v3f(0.0, 0.0, 0.0);
|
||||||
|
std::string mode = g_settings->get("node_highlighting");
|
||||||
|
m_selection_material.Lighting = false;
|
||||||
|
|
||||||
|
if (g_settings->getBool("enable_shaders")) {
|
||||||
|
IShaderSource *shdrsrc = gamedef->getShaderSource();
|
||||||
|
u16 shader_id = shdrsrc->getShader(
|
||||||
|
mode == "halo" ? "selection_shader" : "default_shader", 1, 1);
|
||||||
|
m_selection_material.MaterialType = shdrsrc->getShaderInfo(shader_id).material;
|
||||||
|
} else {
|
||||||
|
m_selection_material.MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mode == "box") {
|
||||||
|
m_use_selection_mesh = false;
|
||||||
|
m_selection_material.Thickness =
|
||||||
|
rangelim(g_settings->getS16("selectionbox_width"), 1, 5);
|
||||||
|
} else if (mode == "halo") {
|
||||||
|
m_use_selection_mesh = true;
|
||||||
|
m_selection_material.setTexture(0, tsrc->getTextureForMesh("halo.png"));
|
||||||
|
m_selection_material.setFlag(video::EMF_BACK_FACE_CULLING, true);
|
||||||
|
} else {
|
||||||
|
m_selection_material.MaterialType = video::EMT_SOLID;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Hud::~Hud()
|
||||||
|
{
|
||||||
|
if (m_selection_mesh)
|
||||||
|
m_selection_mesh->drop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
void Hud::drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
||||||
@ -239,7 +273,7 @@ void Hud::drawItems(v2s32 upperleftpos, s32 itemcount, s32 offset,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void Hud::drawLuaElements(v3s16 camera_offset) {
|
void Hud::drawLuaElements(const v3s16 &camera_offset) {
|
||||||
u32 text_height = g_fontengine->getTextHeight();
|
u32 text_height = g_fontengine->getTextHeight();
|
||||||
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
irr::gui::IGUIFont* font = g_fontengine->getFont();
|
||||||
for (size_t i = 0; i != player->maxHudId(); i++) {
|
for (size_t i = 0; i != player->maxHudId(); i++) {
|
||||||
@ -466,15 +500,85 @@ void Hud::drawCrosshair() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hud::setSelectionPos(const v3f &pos, const v3s16 &camera_offset)
|
||||||
|
{
|
||||||
|
m_camera_offset = camera_offset;
|
||||||
|
m_selection_pos = pos;
|
||||||
|
m_selection_pos_with_offset = pos - intToFloat(camera_offset, BS);
|
||||||
|
}
|
||||||
|
|
||||||
void Hud::drawSelectionBoxes(std::vector<aabb3f> &hilightboxes) {
|
void Hud::drawSelectionMesh()
|
||||||
for (std::vector<aabb3f>::const_iterator
|
{
|
||||||
i = hilightboxes.begin();
|
if (!m_use_selection_mesh) {
|
||||||
i != hilightboxes.end(); ++i) {
|
// Draw 3D selection boxes
|
||||||
driver->draw3DBox(*i, selectionbox_argb);
|
video::SMaterial oldmaterial = driver->getMaterial2D();
|
||||||
|
driver->setMaterial(m_selection_material);
|
||||||
|
for (std::vector<aabb3f>::const_iterator
|
||||||
|
i = m_selection_boxes.begin();
|
||||||
|
i != m_selection_boxes.end(); ++i) {
|
||||||
|
aabb3f box = aabb3f(
|
||||||
|
i->MinEdge + m_selection_pos_with_offset,
|
||||||
|
i->MaxEdge + m_selection_pos_with_offset);
|
||||||
|
|
||||||
|
u32 r = (selectionbox_argb.getRed() *
|
||||||
|
m_selection_mesh_color.getRed() / 255);
|
||||||
|
u32 g = (selectionbox_argb.getGreen() *
|
||||||
|
m_selection_mesh_color.getGreen() / 255);
|
||||||
|
u32 b = (selectionbox_argb.getBlue() *
|
||||||
|
m_selection_mesh_color.getBlue() / 255);
|
||||||
|
driver->draw3DBox(box, video::SColor(255, r, g, b));
|
||||||
|
}
|
||||||
|
driver->setMaterial(oldmaterial);
|
||||||
|
} else if (m_selection_mesh) {
|
||||||
|
// Draw selection mesh
|
||||||
|
video::SMaterial oldmaterial = driver->getMaterial2D();
|
||||||
|
driver->setMaterial(m_selection_material);
|
||||||
|
setMeshColor(m_selection_mesh, m_selection_mesh_color);
|
||||||
|
scene::IMesh* mesh = cloneMesh(m_selection_mesh);
|
||||||
|
translateMesh(mesh, m_selection_pos_with_offset);
|
||||||
|
u32 mc = m_selection_mesh->getMeshBufferCount();
|
||||||
|
for (u32 i = 0; i < mc; i++) {
|
||||||
|
scene::IMeshBuffer *buf = mesh->getMeshBuffer(i);
|
||||||
|
driver->drawMeshBuffer(buf);
|
||||||
|
}
|
||||||
|
mesh->drop();
|
||||||
|
driver->setMaterial(oldmaterial);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Hud::updateSelectionMesh(const v3s16 &camera_offset)
|
||||||
|
{
|
||||||
|
m_camera_offset = camera_offset;
|
||||||
|
if (!m_use_selection_mesh)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (m_selection_mesh) {
|
||||||
|
m_selection_mesh->drop();
|
||||||
|
m_selection_mesh = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!m_selection_boxes.size()) {
|
||||||
|
// No pointed object
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// New pointed object, create new mesh.
|
||||||
|
|
||||||
|
// Texture UV coordinates for selection boxes
|
||||||
|
static f32 texture_uv[24] = {
|
||||||
|
0,0,1,1,
|
||||||
|
0,0,1,1,
|
||||||
|
0,0,1,1,
|
||||||
|
0,0,1,1,
|
||||||
|
0,0,1,1,
|
||||||
|
0,0,1,1
|
||||||
|
};
|
||||||
|
|
||||||
|
m_selection_mesh = convertNodeboxesToMesh(m_selection_boxes, texture_uv);
|
||||||
|
|
||||||
|
// scale final halo mesh
|
||||||
|
scaleMesh(m_selection_mesh, v3f(1.08, 1.08, 1.08));
|
||||||
|
}
|
||||||
|
|
||||||
void Hud::resizeHotbar() {
|
void Hud::resizeHotbar() {
|
||||||
if (m_screensize != porting::getWindowSize()) {
|
if (m_screensize != porting::getWindowSize()) {
|
||||||
|
30
src/hud.h
30
src/hud.h
@ -119,17 +119,31 @@ public:
|
|||||||
bool use_hotbar_image;
|
bool use_hotbar_image;
|
||||||
std::string hotbar_selected_image;
|
std::string hotbar_selected_image;
|
||||||
bool use_hotbar_selected_image;
|
bool use_hotbar_selected_image;
|
||||||
v3s16 camera_offset;
|
|
||||||
|
|
||||||
Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
|
Hud(video::IVideoDriver *driver,scene::ISceneManager* smgr,
|
||||||
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
|
gui::IGUIEnvironment* guienv, IGameDef *gamedef, LocalPlayer *player,
|
||||||
Inventory *inventory);
|
Inventory *inventory);
|
||||||
|
~Hud();
|
||||||
|
|
||||||
void drawHotbar(u16 playeritem);
|
void drawHotbar(u16 playeritem);
|
||||||
void resizeHotbar();
|
void resizeHotbar();
|
||||||
void drawCrosshair();
|
void drawCrosshair();
|
||||||
void drawSelectionBoxes(std::vector<aabb3f> &hilightboxes);
|
void drawSelectionMesh();
|
||||||
void drawLuaElements(v3s16 camera_offset);
|
void updateSelectionMesh(const v3s16 &camera_offset);
|
||||||
|
|
||||||
|
std::vector<aabb3f> *getSelectionBoxes()
|
||||||
|
{ return &m_selection_boxes; }
|
||||||
|
|
||||||
|
void setSelectionPos(const v3f &pos, const v3s16 &camera_offset);
|
||||||
|
|
||||||
|
v3f getSelectionPos() const
|
||||||
|
{ return m_selection_pos; }
|
||||||
|
|
||||||
|
void setSelectionMeshColor(const video::SColor &c)
|
||||||
|
{ m_selection_mesh_color = c; }
|
||||||
|
|
||||||
|
void drawLuaElements(const v3s16 &camera_offset);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
void drawStatbar(v2s32 pos, u16 corner, u16 drawdir, std::string texture,
|
||||||
s32 count, v2s32 offset, v2s32 size=v2s32());
|
s32 count, v2s32 offset, v2s32 size=v2s32());
|
||||||
@ -140,11 +154,21 @@ private:
|
|||||||
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
void drawItem(const ItemStack &item, const core::rect<s32>& rect,
|
||||||
bool selected);
|
bool selected);
|
||||||
|
|
||||||
|
v3s16 m_camera_offset;
|
||||||
v2u32 m_screensize;
|
v2u32 m_screensize;
|
||||||
v2s32 m_displaycenter;
|
v2s32 m_displaycenter;
|
||||||
s32 m_hotbar_imagesize;
|
s32 m_hotbar_imagesize;
|
||||||
s32 m_padding;
|
s32 m_padding;
|
||||||
video::SColor hbar_colors[4];
|
video::SColor hbar_colors[4];
|
||||||
|
|
||||||
|
std::vector<aabb3f> m_selection_boxes;
|
||||||
|
v3f m_selection_pos;
|
||||||
|
v3f m_selection_pos_with_offset;
|
||||||
|
|
||||||
|
scene::IMesh* m_selection_mesh;
|
||||||
|
video::SColor m_selection_mesh_color;
|
||||||
|
video::SMaterial m_selection_material;
|
||||||
|
bool m_use_selection_mesh;
|
||||||
};
|
};
|
||||||
|
|
||||||
enum ItemRotationKind {
|
enum ItemRotationKind {
|
||||||
|
@ -47,10 +47,8 @@ MeshMakeData::MeshMakeData(IGameDef *gamedef, bool use_shaders):
|
|||||||
m_vmanip(),
|
m_vmanip(),
|
||||||
m_blockpos(-1337,-1337,-1337),
|
m_blockpos(-1337,-1337,-1337),
|
||||||
m_crack_pos_relative(-1337, -1337, -1337),
|
m_crack_pos_relative(-1337, -1337, -1337),
|
||||||
m_highlighted_pos_relative(-1337, -1337, -1337),
|
|
||||||
m_smooth_lighting(false),
|
m_smooth_lighting(false),
|
||||||
m_show_hud(false),
|
m_show_hud(false),
|
||||||
m_highlight_mesh_color(255, 255, 255, 255),
|
|
||||||
m_gamedef(gamedef),
|
m_gamedef(gamedef),
|
||||||
m_use_shaders(use_shaders)
|
m_use_shaders(use_shaders)
|
||||||
{}
|
{}
|
||||||
@ -138,12 +136,6 @@ void MeshMakeData::setCrack(int crack_level, v3s16 crack_pos)
|
|||||||
m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE;
|
m_crack_pos_relative = crack_pos - m_blockpos*MAP_BLOCKSIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MeshMakeData::setHighlighted(v3s16 highlighted_pos, bool show_hud)
|
|
||||||
{
|
|
||||||
m_show_hud = show_hud;
|
|
||||||
m_highlighted_pos_relative = highlighted_pos - m_blockpos*MAP_BLOCKSIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
void MeshMakeData::setSmoothLighting(bool smooth_lighting)
|
void MeshMakeData::setSmoothLighting(bool smooth_lighting)
|
||||||
{
|
{
|
||||||
m_smooth_lighting = smooth_lighting;
|
m_smooth_lighting = smooth_lighting;
|
||||||
@ -1036,12 +1028,10 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
m_animation_force_timer(0), // force initial animation
|
m_animation_force_timer(0), // force initial animation
|
||||||
m_last_crack(-1),
|
m_last_crack(-1),
|
||||||
m_crack_materials(),
|
m_crack_materials(),
|
||||||
m_highlighted_materials(),
|
|
||||||
m_last_daynight_ratio((u32) -1),
|
m_last_daynight_ratio((u32) -1),
|
||||||
m_daynight_diffs()
|
m_daynight_diffs()
|
||||||
{
|
{
|
||||||
m_enable_shaders = data->m_use_shaders;
|
m_enable_shaders = data->m_use_shaders;
|
||||||
m_enable_highlighting = g_settings->getBool("enable_node_highlighting");
|
|
||||||
|
|
||||||
if (g_settings->getBool("enable_minimap")) {
|
if (g_settings->getBool("enable_minimap")) {
|
||||||
m_minimap_mapblock = new MinimapMapblock;
|
m_minimap_mapblock = new MinimapMapblock;
|
||||||
@ -1116,8 +1106,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
|
|
||||||
mapblock_mesh_generate_special(data, collector);
|
mapblock_mesh_generate_special(data, collector);
|
||||||
|
|
||||||
m_highlight_mesh_color = data->m_highlight_mesh_color;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert MeshCollector to SMesh
|
Convert MeshCollector to SMesh
|
||||||
*/
|
*/
|
||||||
@ -1162,9 +1150,6 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
p.tile.texture = animation_frame.texture;
|
p.tile.texture = animation_frame.texture;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_enable_highlighting && p.tile.material_flags & MATERIAL_FLAG_HIGHLIGHTED)
|
|
||||||
m_highlighted_materials.push_back(i);
|
|
||||||
|
|
||||||
for(u32 j = 0; j < p.vertices.size(); j++)
|
for(u32 j = 0; j < p.vertices.size(); j++)
|
||||||
{
|
{
|
||||||
video::S3DVertex *vertex = &p.vertices[j];
|
video::S3DVertex *vertex = &p.vertices[j];
|
||||||
@ -1205,19 +1190,15 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
material.setFlag(video::EMF_FOG_ENABLE, true);
|
material.setFlag(video::EMF_FOG_ENABLE, true);
|
||||||
material.setTexture(0, p.tile.texture);
|
material.setTexture(0, p.tile.texture);
|
||||||
|
|
||||||
if (p.tile.material_flags & MATERIAL_FLAG_HIGHLIGHTED) {
|
if (m_enable_shaders) {
|
||||||
material.MaterialType = video::EMT_TRANSPARENT_ADD_COLOR;
|
material.MaterialType = m_shdrsrc->getShaderInfo(p.tile.shader_id).material;
|
||||||
} else {
|
p.tile.applyMaterialOptionsWithShaders(material);
|
||||||
if (m_enable_shaders) {
|
if (p.tile.normal_texture) {
|
||||||
material.MaterialType = m_shdrsrc->getShaderInfo(p.tile.shader_id).material;
|
material.setTexture(1, p.tile.normal_texture);
|
||||||
p.tile.applyMaterialOptionsWithShaders(material);
|
|
||||||
if (p.tile.normal_texture) {
|
|
||||||
material.setTexture(1, p.tile.normal_texture);
|
|
||||||
}
|
|
||||||
material.setTexture(2, p.tile.flags_texture);
|
|
||||||
} else {
|
|
||||||
p.tile.applyMaterialOptions(material);
|
|
||||||
}
|
}
|
||||||
|
material.setTexture(2, p.tile.flags_texture);
|
||||||
|
} else {
|
||||||
|
p.tile.applyMaterialOptions(material);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create meshbuffer
|
// Create meshbuffer
|
||||||
@ -1273,8 +1254,7 @@ MapBlockMesh::MapBlockMesh(MeshMakeData *data, v3s16 camera_offset):
|
|||||||
m_has_animation =
|
m_has_animation =
|
||||||
!m_crack_materials.empty() ||
|
!m_crack_materials.empty() ||
|
||||||
!m_daynight_diffs.empty() ||
|
!m_daynight_diffs.empty() ||
|
||||||
!m_animation_tiles.empty() ||
|
!m_animation_tiles.empty();
|
||||||
!m_highlighted_materials.empty();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
MapBlockMesh::~MapBlockMesh()
|
MapBlockMesh::~MapBlockMesh()
|
||||||
@ -1377,30 +1357,6 @@ bool MapBlockMesh::animate(bool faraway, float time, int crack, u32 daynight_rat
|
|||||||
m_last_daynight_ratio = daynight_ratio;
|
m_last_daynight_ratio = daynight_ratio;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Node highlighting
|
|
||||||
if (m_enable_highlighting) {
|
|
||||||
u8 day = m_highlight_mesh_color.getRed();
|
|
||||||
u8 night = m_highlight_mesh_color.getGreen();
|
|
||||||
video::SColor hc;
|
|
||||||
finalColorBlend(hc, day, night, daynight_ratio);
|
|
||||||
float sin_r = 0.07 * sin(1.5 * time);
|
|
||||||
float sin_g = 0.07 * sin(1.5 * time + irr::core::PI * 0.5);
|
|
||||||
float sin_b = 0.07 * sin(1.5 * time + irr::core::PI);
|
|
||||||
hc.setRed(core::clamp(core::round32(hc.getRed() * (0.8 + sin_r)), 0, 255));
|
|
||||||
hc.setGreen(core::clamp(core::round32(hc.getGreen() * (0.8 + sin_g)), 0, 255));
|
|
||||||
hc.setBlue(core::clamp(core::round32(hc.getBlue() * (0.8 + sin_b)), 0, 255));
|
|
||||||
|
|
||||||
for(std::list<u32>::iterator
|
|
||||||
i = m_highlighted_materials.begin();
|
|
||||||
i != m_highlighted_materials.end(); ++i)
|
|
||||||
{
|
|
||||||
scene::IMeshBuffer *buf = m_mesh->getMeshBuffer(*i);
|
|
||||||
video::S3DVertex *vertices = (video::S3DVertex *)buf->getVertices();
|
|
||||||
for (u32 j = 0; j < buf->getVertexCount() ;j++)
|
|
||||||
vertices[j].Color = hc;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,10 +41,8 @@ struct MeshMakeData
|
|||||||
VoxelManipulator m_vmanip;
|
VoxelManipulator m_vmanip;
|
||||||
v3s16 m_blockpos;
|
v3s16 m_blockpos;
|
||||||
v3s16 m_crack_pos_relative;
|
v3s16 m_crack_pos_relative;
|
||||||
v3s16 m_highlighted_pos_relative;
|
|
||||||
bool m_smooth_lighting;
|
bool m_smooth_lighting;
|
||||||
bool m_show_hud;
|
bool m_show_hud;
|
||||||
video::SColor m_highlight_mesh_color;
|
|
||||||
|
|
||||||
IGameDef *m_gamedef;
|
IGameDef *m_gamedef;
|
||||||
bool m_use_shaders;
|
bool m_use_shaders;
|
||||||
@ -67,11 +65,6 @@ struct MeshMakeData
|
|||||||
*/
|
*/
|
||||||
void setCrack(int crack_level, v3s16 crack_pos);
|
void setCrack(int crack_level, v3s16 crack_pos);
|
||||||
|
|
||||||
/*
|
|
||||||
Set the highlighted node position
|
|
||||||
*/
|
|
||||||
|
|
||||||
void setHighlighted(v3s16 highlighted_pos, bool show_hud);
|
|
||||||
/*
|
/*
|
||||||
Enable or disable smooth lighting
|
Enable or disable smooth lighting
|
||||||
*/
|
*/
|
||||||
@ -137,9 +130,6 @@ private:
|
|||||||
IShaderSource *m_shdrsrc;
|
IShaderSource *m_shdrsrc;
|
||||||
|
|
||||||
bool m_enable_shaders;
|
bool m_enable_shaders;
|
||||||
bool m_enable_highlighting;
|
|
||||||
|
|
||||||
video::SColor m_highlight_mesh_color;
|
|
||||||
|
|
||||||
// Must animate() be called before rendering?
|
// Must animate() be called before rendering?
|
||||||
bool m_has_animation;
|
bool m_has_animation;
|
||||||
@ -150,7 +140,6 @@ private:
|
|||||||
int m_last_crack;
|
int m_last_crack;
|
||||||
// Maps mesh buffer (i.e. material) indices to base texture names
|
// Maps mesh buffer (i.e. material) indices to base texture names
|
||||||
std::map<u32, std::string> m_crack_materials;
|
std::map<u32, std::string> m_crack_materials;
|
||||||
std::list<u32> m_highlighted_materials;
|
|
||||||
|
|
||||||
// Animation info: texture animationi
|
// Animation info: texture animationi
|
||||||
// Maps meshbuffers to TileSpecs
|
// Maps meshbuffers to TileSpecs
|
||||||
|
40
src/mesh.cpp
40
src/mesh.cpp
@ -405,9 +405,11 @@ scene::IMesh* cloneMesh(scene::IMesh *src_mesh)
|
|||||||
return dst_mesh;
|
return dst_mesh;
|
||||||
}
|
}
|
||||||
|
|
||||||
scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
|
scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
|
||||||
|
const f32 *uv_coords)
|
||||||
{
|
{
|
||||||
scene::SMesh* dst_mesh = new scene::SMesh();
|
scene::SMesh* dst_mesh = new scene::SMesh();
|
||||||
|
|
||||||
for (u16 j = 0; j < 6; j++)
|
for (u16 j = 0; j < 6; j++)
|
||||||
{
|
{
|
||||||
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
scene::IMeshBuffer *buf = new scene::SMeshBuffer();
|
||||||
@ -419,9 +421,7 @@ scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
|
|||||||
|
|
||||||
video::SColor c(255,255,255,255);
|
video::SColor c(255,255,255,255);
|
||||||
|
|
||||||
std::vector<aabb3f> boxes = f->node_box.fixed;
|
for(std::vector<aabb3f>::const_iterator
|
||||||
|
|
||||||
for(std::vector<aabb3f>::iterator
|
|
||||||
i = boxes.begin();
|
i = boxes.begin();
|
||||||
i != boxes.end(); ++i)
|
i != boxes.end(); ++i)
|
||||||
{
|
{
|
||||||
@ -446,27 +446,33 @@ scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f)
|
|||||||
box.MinEdge.Z=box.MaxEdge.Z;
|
box.MinEdge.Z=box.MaxEdge.Z;
|
||||||
box.MaxEdge.Z=temp;
|
box.MaxEdge.Z=temp;
|
||||||
}
|
}
|
||||||
// Compute texture coords
|
|
||||||
f32 tx1 = (box.MinEdge.X/BS)+0.5;
|
// Compute texture UV coords
|
||||||
f32 ty1 = (box.MinEdge.Y/BS)+0.5;
|
f32 tx1 = (box.MinEdge.X / BS) + 0.5;
|
||||||
f32 tz1 = (box.MinEdge.Z/BS)+0.5;
|
f32 ty1 = (box.MinEdge.Y / BS) + 0.5;
|
||||||
f32 tx2 = (box.MaxEdge.X/BS)+0.5;
|
f32 tz1 = (box.MinEdge.Z / BS) + 0.5;
|
||||||
f32 ty2 = (box.MaxEdge.Y/BS)+0.5;
|
f32 tx2 = (box.MaxEdge.X / BS) + 0.5;
|
||||||
f32 tz2 = (box.MaxEdge.Z/BS)+0.5;
|
f32 ty2 = (box.MaxEdge.Y / BS) + 0.5;
|
||||||
f32 txc[24] = {
|
f32 tz2 = (box.MaxEdge.Z / BS) + 0.5;
|
||||||
|
|
||||||
|
f32 txc_default[24] = {
|
||||||
// up
|
// up
|
||||||
tx1, 1-tz2, tx2, 1-tz1,
|
tx1, 1 - tz2, tx2, 1 - tz1,
|
||||||
// down
|
// down
|
||||||
tx1, tz1, tx2, tz2,
|
tx1, tz1, tx2, tz2,
|
||||||
// right
|
// right
|
||||||
tz1, 1-ty2, tz2, 1-ty1,
|
tz1, 1 - ty2, tz2, 1 - ty1,
|
||||||
// left
|
// left
|
||||||
1-tz2, 1-ty2, 1-tz1, 1-ty1,
|
1 - tz2, 1 - ty2, 1 - tz1, 1 - ty1,
|
||||||
// back
|
// back
|
||||||
1-tx2, 1-ty2, 1-tx1, 1-ty1,
|
1 - tx2, 1 - ty2, 1 - tx1, 1 - ty1,
|
||||||
// front
|
// front
|
||||||
tx1, 1-ty2, tx2, 1-ty1,
|
tx1, 1 - ty2, tx2, 1 - ty1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// use default texture UV mapping if not provided
|
||||||
|
const f32 *txc = uv_coords ? uv_coords : txc_default;
|
||||||
|
|
||||||
v3f min = box.MinEdge;
|
v3f min = box.MinEdge;
|
||||||
v3f max = box.MaxEdge;
|
v3f max = box.MaxEdge;
|
||||||
|
|
||||||
|
@ -83,9 +83,12 @@ void rotateMeshYZby (scene::IMesh *mesh, f64 degrees);
|
|||||||
scene::IMesh* cloneMesh(scene::IMesh *src_mesh);
|
scene::IMesh* cloneMesh(scene::IMesh *src_mesh);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Convert nodebox drawtype node to mesh.
|
Convert nodeboxes to mesh.
|
||||||
|
boxes - set of nodeboxes to be converted into cuboids
|
||||||
|
uv_coords[24] - table of texture uv coords for each cuboid face
|
||||||
*/
|
*/
|
||||||
scene::IMesh* convertNodeboxNodeToMesh(ContentFeatures *f);
|
scene::IMesh* convertNodeboxesToMesh(const std::vector<aabb3f> &boxes,
|
||||||
|
const f32 *uv_coords = NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Update bounding box for a mesh.
|
Update bounding box for a mesh.
|
||||||
|
@ -972,7 +972,7 @@ void CNodeDefManager::updateTextures(IGameDef *gamedef,
|
|||||||
//Convert regular nodebox nodes to meshnodes
|
//Convert regular nodebox nodes to meshnodes
|
||||||
//Change the drawtype and apply scale
|
//Change the drawtype and apply scale
|
||||||
f->drawtype = NDT_MESH;
|
f->drawtype = NDT_MESH;
|
||||||
f->mesh_ptr[0] = convertNodeboxNodeToMesh(f);
|
f->mesh_ptr[0] = convertNodeboxesToMesh(f->node_box.fixed);
|
||||||
v3f scale = v3f(1.0, 1.0, 1.0) * f->visual_scale;
|
v3f scale = v3f(1.0, 1.0, 1.0) * f->visual_scale;
|
||||||
scaleMesh(f->mesh_ptr[0], scale);
|
scaleMesh(f->mesh_ptr[0], scale);
|
||||||
recalculateBoundingBox(f->mesh_ptr[0]);
|
recalculateBoundingBox(f->mesh_ptr[0]);
|
||||||
|
Binary file not shown.
Before Width: | Height: | Size: 83 B After Width: | Height: | Size: 144 B |
Loading…
Reference in New Issue
Block a user