summaryrefslogtreecommitdiff
path: root/src/drawscene.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/drawscene.cpp')
-rw-r--r--src/drawscene.cpp192
1 files changed, 126 insertions, 66 deletions
diff --git a/src/drawscene.cpp b/src/drawscene.cpp
index 509f341d5..c6abda4ac 100644
--- a/src/drawscene.cpp
+++ b/src/drawscene.cpp
@@ -31,27 +31,9 @@ typedef enum {
EYECOUNT = 2
} 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,
- std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
- scene::ISceneManager* smgr, bool draw_wield_tool, Client& client,
+ video::IVideoDriver* driver, scene::ISceneManager* smgr,
+ bool draw_wield_tool, Client& client,
gui::IGUIEnvironment* guienv )
{
@@ -85,10 +67,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&leftMove);
}
@@ -115,10 +95,8 @@ void draw_anaglyph_3d_mode(Camera& camera, bool show_hud, Hud& hud,
camera.getCameraNode()->setTarget(focusPoint);
smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&rightMove);
}
@@ -144,16 +122,15 @@ void init_texture(video::IVideoDriver* driver, const v2u32& screensize,
irr::video::ECF_A8R8G8B8);
}
-video::ITexture* draw_image(const v2u32& screensize,
- paralax_sign psign, const irr::core::matrix4& startMatrix,
- const irr::core::vector3df& focusPoint, bool show_hud,
- video::IVideoDriver* driver, Camera& camera, scene::ISceneManager* smgr,
- Hud& hud, std::vector<aabb3f>& hilightboxes,
- bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
- video::SColor skycolor )
+video::ITexture* draw_image(const v2u32 &screensize,
+ paralax_sign psign, const irr::core::matrix4 &startMatrix,
+ const irr::core::vector3df &focusPoint, bool show_hud,
+ video::IVideoDriver *driver, Camera &camera, scene::ISceneManager *smgr,
+ Hud &hud, bool draw_wield_tool, Client &client,
+ gui::IGUIEnvironment *guienv, const video::SColor &skycolor)
{
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;
@@ -187,10 +164,8 @@ video::ITexture* draw_image(const v2u32& screensize,
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if (draw_wield_tool)
camera.drawWieldedTool(&movement);
}
@@ -220,7 +195,7 @@ video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
hud.drawCrosshair();
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
-
+ camera.drawNametags();
guienv->drawAll();
}
@@ -232,7 +207,7 @@ video::ITexture* draw_hud(video::IVideoDriver* driver, const v2u32& screensize,
}
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,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
@@ -248,7 +223,7 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
/* create left view */
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);
//Right eye...
@@ -267,10 +242,8 @@ void draw_interlaced_3d_mode(Camera& camera, bool show_hud,
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if (show_hud)
- {
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
-
+ if (show_hud) {
+ hud.drawSelectionMesh();
if(draw_wield_tool)
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,
- Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+ Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
@@ -309,12 +282,12 @@ void draw_sidebyside_3d_mode(Camera& camera, bool show_hud,
/* create left view */
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);
/* create right view */
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);
/* 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,
- Hud& hud, std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
+ Hud& hud, video::IVideoDriver* driver,
scene::ISceneManager* smgr, const v2u32& screensize,
bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
video::SColor skycolor )
@@ -365,12 +338,12 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
/* create left view */
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);
/* create right view */
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);
/* create hud overlay */
@@ -404,23 +377,100 @@ void draw_top_bottom_3d_mode(Camera& camera, bool show_hud,
camera.getCameraNode()->setTarget(oldTarget);
}
-void draw_plain(Camera& camera, bool show_hud, Hud& hud,
- std::vector<aabb3f> hilightboxes, video::IVideoDriver* driver,
- bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv)
+void draw_pageflip_3d_mode(Camera& camera, bool show_hud,
+ Hud& hud, video::IVideoDriver* driver,
+ scene::ISceneManager* smgr, const v2u32& screensize,
+ bool draw_wield_tool, Client& client, gui::IGUIEnvironment* guienv,
+ video::SColor skycolor)
{
+ /* preserve old setup*/
+ irr::core::vector3df oldPosition = camera.getCameraNode()->getPosition();
+ irr::core::vector3df oldTarget = camera.getCameraNode()->getTarget();
+
+ irr::core::matrix4 startMatrix =
+ camera.getCameraNode()->getAbsoluteTransformation();
+ irr::core::vector3df focusPoint = (camera.getCameraNode()->getTarget()
+ - camera.getCameraNode()->getAbsolutePosition()).setLength(1)
+ + camera.getCameraNode()->getAbsolutePosition();
+
+ //Left eye...
+ driver->setRenderTarget(irr::video::ERT_STEREO_LEFT_BUFFER);
+
+ irr::core::vector3df leftEye;
+ irr::core::matrix4 leftMove;
+ leftMove.setTranslation(
+ irr::core::vector3df(-g_settings->getFloat("3d_paralax_strength"),
+ 0.0f, 0.0f));
+ leftEye = (startMatrix * leftMove).getTranslation();
+
+ //clear the depth buffer, and color
+ driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera.getCameraNode()->setPosition(leftEye);
+ camera.getCameraNode()->setTarget(focusPoint);
+ smgr->drawAll();
driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- draw_selectionbox(driver, hud, hilightboxes, show_hud);
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool)
+ camera.drawWieldedTool(&leftMove);
+ hud.drawHotbar(client.getPlayerItem());
+ hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+ }
+
+ guienv->drawAll();
+
+ //Right eye...
+ driver->setRenderTarget(irr::video::ERT_STEREO_RIGHT_BUFFER);
+
+ irr::core::vector3df rightEye;
+ irr::core::matrix4 rightMove;
+ rightMove.setTranslation(
+ irr::core::vector3df(g_settings->getFloat("3d_paralax_strength"),
+ 0.0f, 0.0f));
+ rightEye = (startMatrix * rightMove).getTranslation();
+
+ //clear the depth buffer, and color
+ driver->beginScene(true, true, irr::video::SColor(200, 200, 200, 255));
+ camera.getCameraNode()->setPosition(rightEye);
+ camera.getCameraNode()->setTarget(focusPoint);
+ smgr->drawAll();
+ driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
- if(draw_wield_tool)
- camera.drawWieldedTool();
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool)
+ camera.drawWieldedTool(&rightMove);
+ hud.drawHotbar(client.getPlayerItem());
+ hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+ }
+
+ guienv->drawAll();
+
+ camera.getCameraNode()->setPosition(oldPosition);
+ camera.getCameraNode()->setTarget(oldTarget);
+}
+
+void draw_plain(Camera &camera, bool show_hud, Hud &hud,
+ video::IVideoDriver *driver, bool draw_wield_tool,
+ Client &client, gui::IGUIEnvironment *guienv)
+{
+ driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
+ if (show_hud) {
+ hud.drawSelectionMesh();
+ if (draw_wield_tool) {
+ camera.drawWieldedTool();
+ }
+ }
}
void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
Camera &camera, Client& client, LocalPlayer *player, Hud &hud,
Mapper &mapper, gui::IGUIEnvironment *guienv,
- std::vector<aabb3f> hilightboxes, const v2u32 &screensize,
- video::SColor skycolor, bool show_hud, bool show_minimap)
+ const v2u32 &screensize, const video::SColor &skycolor,
+ bool show_hud, bool show_minimap)
{
TimeTaker timer("smgr");
@@ -444,30 +494,37 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
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);
draw_crosshair = false;
}
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);
draw_crosshair = false;
}
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);
show_hud = false;
}
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);
show_hud = false;
}
+ else if (draw_mode == "pageflip")
+ {
+ draw_pageflip_3d_mode(camera, show_hud, hud, driver,
+ smgr, screensize, draw_wield_tool, client, guienv, skycolor);
+ draw_crosshair = false;
+ show_hud = false;
+ }
else {
- draw_plain(camera, show_hud, hud, hilightboxes, driver,
+ draw_plain(camera, show_hud, hud, driver,
draw_wield_tool, client, guienv);
}
@@ -483,8 +540,11 @@ void draw_scene(video::IVideoDriver *driver, scene::ISceneManager *smgr,
{
if (draw_crosshair)
hud.drawCrosshair();
+
hud.drawHotbar(client.getPlayerItem());
hud.drawLuaElements(camera.getOffset());
+ camera.drawNametags();
+
if (show_minimap)
mapper.drawMinimap();
}