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()),
32 smgr(device->getSceneManager()), guienv(device->getGUIEnvironment()),
33 client(_client), camera(client->getCamera()),
34 mapper(client->getMinimap()), hud(_hud)
36 screensize = driver->getScreenSize();
37 virtual_size = screensize;
40 RenderingCore::~RenderingCore()
45 void RenderingCore::initialize()
47 // have to be called late as the VMT is not ready in the constructor:
51 void RenderingCore::updateScreenSize()
53 virtual_size = screensize;
58 void RenderingCore::draw(video::SColor _skycolor, bool _show_hud, bool _show_minimap,
59 bool _draw_wield_tool, bool _draw_crosshair, bool _draw_tracers,
62 v2u32 ss = driver->getScreenSize();
63 if (screensize != ss) {
69 show_minimap = _show_minimap;
70 draw_wield_tool = _draw_wield_tool;
71 draw_crosshair = _draw_crosshair;
72 draw_tracers = _draw_tracers;
79 void RenderingCore::drawTracersAndESP()
81 ClientEnvironment &env = client->getEnv();
82 Camera *camera = client->getCamera();
84 v3f camera_offset = intToFloat(camera->getOffset(), BS);
86 v3f eye_pos = (camera->getPosition() + camera->getDirection() - camera_offset);
88 video::SMaterial material, oldmaterial;
89 oldmaterial = driver->getMaterial2D();
90 material.setFlag(video::EMF_LIGHTING, false);
91 material.setFlag(video::EMF_BILINEAR_FILTER, false);
92 material.setFlag(video::EMF_ZBUFFER, false);
93 material.setFlag(video::EMF_ZWRITE_ENABLE, false);
94 driver->setMaterial(material);
96 auto allObjects = env.getAllActiveObjects();
97 for (auto &it : allObjects) {
98 ClientActiveObject *cao = it.second;
99 if (cao->isLocalPlayer() || cao->getParent())
101 GenericCAO *obj = dynamic_cast<GenericCAO *>(cao);
105 if (!obj->getSelectionBox(&box))
107 v3f pos = obj->getPosition();
108 pos -= camera_offset;
111 pos = box.getCenter();
113 driver->draw3DBox(box, video::SColor(255, 255, 255, 255));
116 eye_pos, pos, video::SColor(255, 255, 255, 255));
119 driver->setMaterial(oldmaterial);
122 void RenderingCore::draw3D()
125 driver->setTransform(video::ETS_WORLD, core::IdentityMatrix);
128 hud->drawSelectionMesh();
129 if (draw_tracers || draw_esp)
132 camera->drawWieldedTool();
135 void RenderingCore::drawHUD()
139 hud->drawCrosshair();
141 hud->drawHotbar(client->getEnv().getLocalPlayer()->getWieldIndex());
142 hud->drawLuaElements(camera->getOffset());
143 camera->drawNametags();
144 if (mapper && show_minimap)
145 mapper->drawMinimap();
150 void RenderingCore::drawPostFx()
152 client->getEnv().getClientMap().renderPostFx(camera->getCameraMode());