3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4 Copyright (C) 2017 numzero, Lobachevskiy Vitaliy <numzer0@yandex.ru>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as published by
8 the Free Software Foundation; either version 2.1 of the License, or
9 (at your option) any later version.
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. See the
14 GNU Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public License along
17 with this program; if not, write to the Free Software Foundation, Inc.,
18 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 #include "client/camera.h"
24 #include "client/client.h"
25 #include "client/clientmap.h"
26 #include "client/hud.h"
27 #include "client/minimap.h"
28 #include "client/content_cao.h"
30 RenderingCore::RenderingCore(IrrlichtDevice *_device, Client *_client, Hud *_hud)
31 : device(_device), driver(device->getVideoDriver()), smgr(device->getSceneManager()),
32 guienv(device->getGUIEnvironment()), client(_client), camera(client->getCamera()),
33 mapper(client->getMinimap()), hud(_hud)
35 screensize = driver->getScreenSize();
36 virtual_size = screensize;
39 RenderingCore::~RenderingCore()
44 void RenderingCore::initialize()
46 // have to be called late as the VMT is not ready in the constructor:
50 void RenderingCore::updateScreenSize()
52 virtual_size = screensize;
57 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
58 bool _draw_wield_tool, bool _draw_crosshair, bool _draw_tracers, bool _draw_esp)
60 v2u32 ss = driver->getScreenSize();
61 if (screensize != ss) {
67 show_minimap = _show_minimap;
68 draw_wield_tool = _draw_wield_tool;
69 draw_crosshair = _draw_crosshair;
70 draw_tracers = _draw_tracers;
77 void RenderingCore::drawTracersAndESP()
79 ClientEnvironment &env = client->getEnv();
80 Camera *camera = client->getCamera();
82 v3f camera_offset = intToFloat(camera->getOffset(), BS);
84 v3f eye_pos = (camera->getPosition() + camera->getDirection() - camera_offset);
86 video::SMaterial material, oldmaterial;
87 oldmaterial = driver->getMaterial2D();
88 material.setFlag(video::EMF_LIGHTING, false);
89 material.setFlag(video::EMF_BILINEAR_FILTER, false);
90 material.setFlag(video::EMF_ZBUFFER, false);
91 material.setFlag(video::EMF_ZWRITE_ENABLE, false);
92 driver->setMaterial(material);
94 auto allObjects = env.getAllActiveObjects();
95 for (auto &it : allObjects) {
96 ClientActiveObject *cao = it.second;
97 if (cao->isLocalPlayer() || cao->getParent())
99 GenericCAO *obj = dynamic_cast<GenericCAO *>(cao);
103 if (! obj->getSelectionBox(&box))
105 v3f pos = obj->getPosition();
106 pos -= camera_offset;
109 pos = box.getCenter();
111 driver->draw3DBox(box, video::SColor(255, 255, 255, 255));
113 driver->draw3DLine(eye_pos, pos, video::SColor(255, 255, 255, 255));
116 driver->setMaterial(oldmaterial);
119 void RenderingCore::draw3D()
122 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
125 hud->drawSelectionMesh();
126 if (draw_tracers || draw_esp)
129 camera->drawWieldedTool();
132 void RenderingCore::drawHUD()
136 hud->drawCrosshair();
138 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
139 hud->drawLuaElements(camera->getOffset());
140 camera->drawNametags();
141 if (mapper && show_minimap)
142 mapper->drawMinimap();
147 void RenderingCore::drawPostFx()
149 client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());