3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
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.
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.
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.
24 #include "clientmap.h" // MapDrawControl
27 #include "client/renderingengine.h"
29 #include "wieldmesh.h"
30 #include "noise.h" // easeCurve
34 #include "util/numeric.h"
35 #include "constants.h"
36 #include "fontengine.h"
37 #include "script/scripting_client.h"
39 #define CAMERA_OFFSET_STEP 200
43 Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
45 m_draw_control(draw_control),
48 //dstream<<FUNCTION_NAME<<std::endl;
50 m_driver = smgr->getVideoDriver();
51 // note: making the camera node a child of the player node
52 // would lead to unexpected behaviour, so we don't do that.
53 m_playernode = smgr->addEmptySceneNode(smgr->getRootSceneNode());
54 m_headnode = smgr->addEmptySceneNode(m_playernode);
55 m_cameranode = smgr->addCameraSceneNode(smgr->getRootSceneNode());
56 m_cameranode->bindTargetAndRotation(true);
58 // This needs to be in its own scene manager. It is drawn after
59 // all other 3D scene nodes and before the GUI.
60 m_wieldmgr = smgr->createNewSceneManager();
61 m_wieldmgr->addCameraSceneNode();
62 m_wieldnode = new WieldMeshSceneNode(m_wieldmgr->getRootSceneNode(), m_wieldmgr, -1, false);
63 m_wieldnode->setItem(ItemStack(), m_client);
64 m_wieldnode->drop(); // m_wieldmgr grabbed it
66 /* TODO: Add a callback function so these can be updated when a setting
67 * changes. At this point in time it doesn't matter (e.g. /set
68 * is documented to change server settings only)
70 * TODO: Local caching of settings is not optimal and should at some stage
71 * be updated to use a global settings object for getting thse values
72 * (as opposed to the this local caching). This can be addressed in
75 m_cache_fall_bobbing_amount = g_settings->getFloat("fall_bobbing_amount");
76 m_cache_view_bobbing_amount = g_settings->getFloat("view_bobbing_amount");
77 m_cache_fov = g_settings->getFloat("fov");
78 m_cache_zoom_fov = g_settings->getFloat("zoom_fov");
79 m_arm_inertia = g_settings->getBool("arm_inertia");
88 bool Camera::successfullyCreated(std::string &error_message)
91 error_message = "Failed to create the player scene node";
92 } else if (!m_headnode) {
93 error_message = "Failed to create the head scene node";
94 } else if (!m_cameranode) {
95 error_message = "Failed to create the camera scene node";
96 } else if (!m_wieldmgr) {
97 error_message = "Failed to create the wielded item scene manager";
98 } else if (!m_wieldnode) {
99 error_message = "Failed to create the wielded item scene node";
101 error_message.clear();
104 if (g_settings->getBool("enable_client_modding")) {
105 m_client->getScript()->on_camera_ready(this);
107 return error_message.empty();
110 // Returns the fractional part of x
111 inline f32 my_modf(f32 x)
114 return modf(x, &dummy);
117 void Camera::step(f32 dtime)
119 if(m_view_bobbing_fall > 0)
121 m_view_bobbing_fall -= 3 * dtime;
122 if(m_view_bobbing_fall <= 0)
123 m_view_bobbing_fall = -1; // Mark the effect as finished
126 bool was_under_zero = m_wield_change_timer < 0;
127 m_wield_change_timer = MYMIN(m_wield_change_timer + dtime, 0.125);
129 if (m_wield_change_timer >= 0 && was_under_zero)
130 m_wieldnode->setItem(m_wield_item_next, m_client);
132 if (m_view_bobbing_state != 0)
134 //f32 offset = dtime * m_view_bobbing_speed * 0.035;
135 f32 offset = dtime * m_view_bobbing_speed * 0.030;
136 if (m_view_bobbing_state == 2) {
137 // Animation is getting turned off
138 if (m_view_bobbing_anim < 0.25) {
139 m_view_bobbing_anim -= offset;
140 } else if (m_view_bobbing_anim > 0.75) {
141 m_view_bobbing_anim += offset;
144 if (m_view_bobbing_anim < 0.5) {
145 m_view_bobbing_anim += offset;
146 if (m_view_bobbing_anim > 0.5)
147 m_view_bobbing_anim = 0.5;
149 m_view_bobbing_anim -= offset;
150 if (m_view_bobbing_anim < 0.5)
151 m_view_bobbing_anim = 0.5;
154 if (m_view_bobbing_anim <= 0 || m_view_bobbing_anim >= 1 ||
155 fabs(m_view_bobbing_anim - 0.5) < 0.01) {
156 m_view_bobbing_anim = 0;
157 m_view_bobbing_state = 0;
161 float was = m_view_bobbing_anim;
162 m_view_bobbing_anim = my_modf(m_view_bobbing_anim + offset);
163 bool step = (was == 0 ||
164 (was < 0.5f && m_view_bobbing_anim >= 0.5f) ||
165 (was > 0.5f && m_view_bobbing_anim <= 0.5f));
167 MtEvent *e = new SimpleTriggerEvent("ViewBobbingStep");
168 m_client->event()->put(e);
173 if (m_digging_button != -1)
175 f32 offset = dtime * 3.5;
176 float m_digging_anim_was = m_digging_anim;
177 m_digging_anim += offset;
178 if (m_digging_anim >= 1)
181 m_digging_button = -1;
184 if(m_digging_anim_was < lim && m_digging_anim >= lim)
186 if(m_digging_button == 0)
188 MtEvent *e = new SimpleTriggerEvent("CameraPunchLeft");
189 m_client->event()->put(e);
190 } else if(m_digging_button == 1) {
191 MtEvent *e = new SimpleTriggerEvent("CameraPunchRight");
192 m_client->event()->put(e);
198 void Camera::addArmInertia(f32 player_yaw, f32 frametime)
200 if (m_timer.X == 0.0f) {
201 // In the limit case where timer is 0 set a static velocity (generic case divide by zero)
202 m_cam_vel.X = 1.0001f;
205 m_cam_vel.X = std::fabs((m_last_cam_pos.X - player_yaw) / m_timer.X) * 0.01f;
207 if (m_timer.Y == 0.0f) {
208 // In the limit case where timer is 0 set a static velocity (generic case divide by zero)
209 m_cam_vel.Y = 1.0001f;
212 m_cam_vel.Y = std::fabs((m_last_cam_pos.Y - m_camera_direction.Y) / m_timer.Y);
214 if (m_cam_vel.X > 1.0f || m_cam_vel.Y > 1.0f) {
216 the arm moves when the camera moves fast enough.
219 if (m_cam_vel.X > 1.0f) {
220 m_timer.X = frametime;
222 if (m_cam_vel.X > m_cam_vel_old.X)
223 m_cam_vel_old.X = m_cam_vel.X;
225 if (m_last_cam_pos.X > player_yaw)
227 m_wieldmesh_offset.X -= (0.1f + frametime) * m_cam_vel.X;
230 m_wieldmesh_offset.X += (0.1f + frametime) * m_cam_vel.X;
232 if (m_last_cam_pos.X != player_yaw)
233 m_last_cam_pos.X = player_yaw;
235 m_wieldmesh_offset.X = rangelim(m_wieldmesh_offset.X, 48.0f, 62.0f);
238 if (m_cam_vel.Y > 1.0f) {
239 m_timer.Y = frametime;
241 if (m_cam_vel.Y > m_cam_vel_old.Y)
242 m_cam_vel_old.Y = m_cam_vel.Y;
244 if (m_last_cam_pos.Y > m_camera_direction.Y)
246 m_wieldmesh_offset.Y += (0.1f + frametime) * m_cam_vel.Y;
249 m_wieldmesh_offset.Y -= (0.1f + frametime) * m_cam_vel.Y;
251 if (m_last_cam_pos.Y != m_camera_direction.Y)
252 m_last_cam_pos.Y = m_camera_direction.Y;
254 m_wieldmesh_offset.Y = rangelim(m_wieldmesh_offset.Y, -45.0f, -30.0f);
258 the arm now gets back to its default position when the camera stops.
261 if (floor(m_wieldmesh_offset.X) == 55.0f) {
262 m_cam_vel_old.X = 0.0f;
263 m_wieldmesh_offset.X = 55.0f;
266 if (m_wieldmesh_offset.X > 55.0f)
267 m_wieldmesh_offset.X -= (0.05f + frametime) * m_cam_vel_old.X;
268 if (m_wieldmesh_offset.X < 55.0f)
269 m_wieldmesh_offset.X += (0.05f + frametime) * m_cam_vel_old.X;
271 if (floor(m_wieldmesh_offset.Y) == -35.0f) {
272 m_cam_vel_old.Y = 0.0f;
273 m_wieldmesh_offset.Y = -35.0f;
276 if (m_wieldmesh_offset.Y > -35.0f)
277 m_wieldmesh_offset.Y -= (0.05f + frametime) * m_cam_vel_old.Y;
278 if (m_wieldmesh_offset.Y < -35.0f)
279 m_wieldmesh_offset.Y += (0.05f + frametime) * m_cam_vel_old.Y;
283 void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
284 f32 tool_reload_ratio, ClientEnvironment &c_env)
286 // Get player position
287 // Smooth the movement when walking up stairs
288 v3f old_player_position = m_playernode->getPosition();
289 v3f player_position = player->getPosition();
290 if (player->isAttached && player->parent)
291 player_position = player->parent->getPosition();
292 //if(player->touching_ground && player_position.Y > old_player_position.Y)
293 if(player->touching_ground &&
294 player_position.Y > old_player_position.Y)
296 f32 oldy = old_player_position.Y;
297 f32 newy = player_position.Y;
298 f32 t = exp(-23*frametime);
299 player_position.Y = oldy * t + newy * (1-t);
302 // Set player node transformation
303 m_playernode->setPosition(player_position);
304 m_playernode->setRotation(v3f(0, -1 * player->getYaw(), 0));
305 m_playernode->updateAbsolutePosition();
307 // Get camera tilt timer (hurt animation)
308 float cameratilt = fabs(fabs(player->hurt_tilt_timer-0.75)-0.75);
310 // Fall bobbing animation
311 float fall_bobbing = 0;
312 if(player->camera_impact >= 1 && m_camera_mode < CAMERA_MODE_THIRD)
314 if(m_view_bobbing_fall == -1) // Effect took place and has finished
315 player->camera_impact = m_view_bobbing_fall = 0;
316 else if(m_view_bobbing_fall == 0) // Initialize effect
317 m_view_bobbing_fall = 1;
319 // Convert 0 -> 1 to 0 -> 1 -> 0
320 fall_bobbing = m_view_bobbing_fall < 0.5 ? m_view_bobbing_fall * 2 : -(m_view_bobbing_fall - 0.5) * 2 + 1;
321 // Smoothen and invert the above
322 fall_bobbing = sin(fall_bobbing * 0.5 * M_PI) * -1;
323 // Amplify according to the intensity of the impact
324 fall_bobbing *= (1 - rangelim(50 / player->camera_impact, 0, 1)) * 5;
326 fall_bobbing *= m_cache_fall_bobbing_amount;
329 // Calculate players eye offset for different camera modes
330 v3f PlayerEyeOffset = player->getEyeOffset();
331 if (m_camera_mode == CAMERA_MODE_FIRST)
332 PlayerEyeOffset += player->eye_offset_first;
334 PlayerEyeOffset += player->eye_offset_third;
336 // Set head node transformation
337 m_headnode->setPosition(PlayerEyeOffset+v3f(0,cameratilt*-player->hurt_tilt_strength+fall_bobbing,0));
338 m_headnode->setRotation(v3f(player->getPitch(), 0, cameratilt*player->hurt_tilt_strength));
339 m_headnode->updateAbsolutePosition();
341 // Compute relative camera position and target
342 v3f rel_cam_pos = v3f(0,0,0);
343 v3f rel_cam_target = v3f(0,0,1);
344 v3f rel_cam_up = v3f(0,1,0);
346 if (m_cache_view_bobbing_amount != 0.0f && m_view_bobbing_anim != 0.0f &&
347 m_camera_mode < CAMERA_MODE_THIRD) {
348 f32 bobfrac = my_modf(m_view_bobbing_anim * 2);
349 f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0;
353 f32 bobtmp = sin(pow(bobfrac, bobknob) * M_PI);
354 //f32 bobtmp2 = cos(pow(bobfrac, bobknob) * M_PI);
357 0.3 * bobdir * sin(bobfrac * M_PI),
358 -0.28 * bobtmp * bobtmp,
361 //rel_cam_pos += 0.2 * bobvec;
362 //rel_cam_target += 0.03 * bobvec;
363 //rel_cam_up.rotateXYBy(0.02 * bobdir * bobtmp * M_PI);
365 f *= m_cache_view_bobbing_amount;
366 rel_cam_pos += bobvec * f;
367 //rel_cam_target += 0.995 * bobvec * f;
368 rel_cam_target += bobvec * f;
369 rel_cam_target.Z -= 0.005 * bobvec.Z * f;
370 //rel_cam_target.X -= 0.005 * bobvec.X * f;
371 //rel_cam_target.Y -= 0.005 * bobvec.Y * f;
372 rel_cam_up.rotateXYBy(-0.03 * bobdir * bobtmp * M_PI * f);
374 f32 angle_deg = 1 * bobdir * sin(bobfrac * M_PI);
375 f32 angle_rad = angle_deg * M_PI / 180;
379 r * (cos(angle_rad) - 1),
382 //rel_cam_target += off;
383 rel_cam_up.rotateXYBy(angle_deg);
388 // Compute absolute camera position and target
389 m_headnode->getAbsoluteTransformation().transformVect(m_camera_position, rel_cam_pos);
390 m_headnode->getAbsoluteTransformation().rotateVect(m_camera_direction, rel_cam_target - rel_cam_pos);
393 m_headnode->getAbsoluteTransformation().rotateVect(abs_cam_up, rel_cam_up);
395 // Seperate camera position for calculation
396 v3f my_cp = m_camera_position;
398 // Reposition the camera for third person view
399 if (m_camera_mode > CAMERA_MODE_FIRST)
401 if (m_camera_mode == CAMERA_MODE_THIRD_FRONT)
402 m_camera_direction *= -1;
406 // Calculate new position
408 for (int i = BS; i <= BS*2.75; i++)
410 my_cp.X = m_camera_position.X + m_camera_direction.X*-i;
411 my_cp.Z = m_camera_position.Z + m_camera_direction.Z*-i;
413 my_cp.Y = m_camera_position.Y + (m_camera_direction.Y*-i);
415 // Prevent camera positioned inside nodes
416 INodeDefManager *nodemgr = m_client->ndef();
417 MapNode n = c_env.getClientMap().getNodeNoEx(floatToInt(my_cp, BS));
418 const ContentFeatures& features = nodemgr->get(n);
419 if(features.walkable)
421 my_cp.X += m_camera_direction.X*-1*-BS/2;
422 my_cp.Z += m_camera_direction.Z*-1*-BS/2;
423 my_cp.Y += m_camera_direction.Y*-1*-BS/2;
429 // If node blocks camera position don't move y to heigh
430 if (abort && my_cp.Y > player_position.Y+BS*2)
431 my_cp.Y = player_position.Y+BS*2;
434 // Update offset if too far away from the center of the map
435 m_camera_offset.X += CAMERA_OFFSET_STEP*
436 (((s16)(my_cp.X/BS) - m_camera_offset.X)/CAMERA_OFFSET_STEP);
437 m_camera_offset.Y += CAMERA_OFFSET_STEP*
438 (((s16)(my_cp.Y/BS) - m_camera_offset.Y)/CAMERA_OFFSET_STEP);
439 m_camera_offset.Z += CAMERA_OFFSET_STEP*
440 (((s16)(my_cp.Z/BS) - m_camera_offset.Z)/CAMERA_OFFSET_STEP);
442 // Set camera node transformation
443 m_cameranode->setPosition(my_cp-intToFloat(m_camera_offset, BS));
444 m_cameranode->setUpVector(abs_cam_up);
445 // *100.0 helps in large map coordinates
446 m_cameranode->setTarget(my_cp-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction);
448 // update the camera position in front-view mode to render blocks behind player
449 if (m_camera_mode == CAMERA_MODE_THIRD_FRONT)
450 m_camera_position = my_cp;
454 if (player->getPlayerControl().zoom && m_client->checkLocalPrivilege("zoom")) {
455 fov_degrees = m_cache_zoom_fov;
457 fov_degrees = m_cache_fov;
459 fov_degrees = rangelim(fov_degrees, 7.0, 160.0);
461 // FOV and aspect ratio
462 const v2u32 &window_size = RenderingEngine::get_instance()->getWindowSize();
463 m_aspect = (f32) window_size.X / (f32) window_size.Y;
464 m_fov_y = fov_degrees * M_PI / 180.0;
465 // Increase vertical FOV on lower aspect ratios (<16:10)
466 m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
467 m_fov_x = 2 * atan(m_aspect * tan(0.5 * m_fov_y));
468 m_cameranode->setAspectRatio(m_aspect);
469 m_cameranode->setFOV(m_fov_y);
472 addArmInertia(player->getYaw(), frametime);
474 // Position the wielded item
475 //v3f wield_position = v3f(45, -35, 65);
476 v3f wield_position = v3f(m_wieldmesh_offset.X, m_wieldmesh_offset.Y, 65);
477 //v3f wield_rotation = v3f(-100, 120, -100);
478 v3f wield_rotation = v3f(-100, 120, -100);
479 wield_position.Y += fabs(m_wield_change_timer)*320 - 40;
480 if(m_digging_anim < 0.05 || m_digging_anim > 0.5)
483 if(m_digging_anim > 0.5)
484 frac = 2.0 * (m_digging_anim - 0.5);
485 // This value starts from 1 and settles to 0
486 f32 ratiothing = pow((1.0f - tool_reload_ratio), 0.5f);
487 //f32 ratiothing2 = pow(ratiothing, 0.5f);
488 f32 ratiothing2 = (easeCurve(ratiothing*0.5))*2.0;
489 wield_position.Y -= frac * 25.0 * pow(ratiothing2, 1.7f);
490 //wield_position.Z += frac * 5.0 * ratiothing2;
491 wield_position.X -= frac * 35.0 * pow(ratiothing2, 1.1f);
492 wield_rotation.Y += frac * 70.0 * pow(ratiothing2, 1.4f);
493 //wield_rotation.X -= frac * 15.0 * pow(ratiothing2, 1.4f);
494 //wield_rotation.Z += frac * 15.0 * pow(ratiothing2, 1.0f);
496 if (m_digging_button != -1)
498 f32 digfrac = m_digging_anim;
499 wield_position.X -= 50 * sin(pow(digfrac, 0.8f) * M_PI);
500 wield_position.Y += 24 * sin(digfrac * 1.8 * M_PI);
501 wield_position.Z += 25 * 0.5;
503 // Euler angles are PURE EVIL, so why not use quaternions?
504 core::quaternion quat_begin(wield_rotation * core::DEGTORAD);
505 core::quaternion quat_end(v3f(80, 30, 100) * core::DEGTORAD);
506 core::quaternion quat_slerp;
507 quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI));
508 quat_slerp.toEuler(wield_rotation);
509 wield_rotation *= core::RADTODEG;
511 f32 bobfrac = my_modf(m_view_bobbing_anim);
512 wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0;
513 wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
515 m_wieldnode->setPosition(wield_position);
516 m_wieldnode->setRotation(wield_rotation);
518 m_wieldnode->setColor(player->light_color);
520 // Set render distance
521 updateViewingRange();
523 // If the player is walking, swimming, or climbing,
524 // view bobbing is enabled and free_move is off,
525 // start (or continue) the view bobbing animation.
526 v3f speed = player->getSpeed();
527 const bool movement_XZ = hypot(speed.X, speed.Z) > BS;
528 const bool movement_Y = fabs(speed.Y) > BS;
530 const bool walking = movement_XZ && player->touching_ground;
531 const bool swimming = (movement_XZ || player->swimming_vertical) && player->in_liquid;
532 const bool climbing = movement_Y && player->is_climbing;
533 if ((walking || swimming || climbing) &&
534 (!g_settings->getBool("free_move") || !m_client->checkLocalPrivilege("fly"))) {
536 m_view_bobbing_state = 1;
537 m_view_bobbing_speed = MYMIN(speed.getLength(), 70);
539 else if (m_view_bobbing_state == 1)
542 m_view_bobbing_state = 2;
543 m_view_bobbing_speed = 60;
547 void Camera::updateViewingRange()
549 f32 viewing_range = g_settings->getFloat("viewing_range");
550 m_draw_control.wanted_range = viewing_range;
551 if (m_draw_control.range_all) {
552 m_cameranode->setFarValue(100000.0);
555 m_cameranode->setFarValue((viewing_range < 2000) ? 2000 * BS : viewing_range * BS);
558 void Camera::setDigging(s32 button)
560 if (m_digging_button == -1)
561 m_digging_button = button;
564 void Camera::wield(const ItemStack &item)
566 if (item.name != m_wield_item_next.name ||
567 item.metadata != m_wield_item_next.metadata) {
568 m_wield_item_next = item;
569 if (m_wield_change_timer > 0)
570 m_wield_change_timer = -m_wield_change_timer;
571 else if (m_wield_change_timer == 0)
572 m_wield_change_timer = -0.001;
576 void Camera::drawWieldedTool(irr::core::matrix4* translation)
578 // Clear Z buffer so that the wielded tool stay in front of world geometry
579 m_wieldmgr->getVideoDriver()->clearZBuffer();
581 // Draw the wielded node (in a separate scene manager)
582 scene::ICameraSceneNode* cam = m_wieldmgr->getActiveCamera();
583 cam->setAspectRatio(m_cameranode->getAspectRatio());
584 cam->setFOV(72.0*M_PI/180.0);
585 cam->setNearValue(10);
586 cam->setFarValue(1000);
587 if (translation != NULL)
589 irr::core::matrix4 startMatrix = cam->getAbsoluteTransformation();
590 irr::core::vector3df focusPoint = (cam->getTarget()
591 - cam->getAbsolutePosition()).setLength(1)
592 + cam->getAbsolutePosition();
594 irr::core::vector3df camera_pos =
595 (startMatrix * *translation).getTranslation();
596 cam->setPosition(camera_pos);
597 cam->setTarget(focusPoint);
599 m_wieldmgr->drawAll();
602 void Camera::drawNametags()
604 core::matrix4 trans = m_cameranode->getProjectionMatrix();
605 trans *= m_cameranode->getViewMatrix();
607 for (std::list<Nametag *>::const_iterator
608 i = m_nametags.begin();
609 i != m_nametags.end(); ++i) {
610 Nametag *nametag = *i;
611 if (nametag->nametag_color.getAlpha() == 0) {
612 // Enforce hiding nametag,
613 // because if freetype is enabled, a grey
614 // shadow can remain.
617 v3f pos = nametag->parent_node->getAbsolutePosition() + v3f(0.0, 1.1 * BS, 0.0);
618 f32 transformed_pos[4] = { pos.X, pos.Y, pos.Z, 1.0f };
619 trans.multiplyWith1x4Matrix(transformed_pos);
620 if (transformed_pos[3] > 0) {
621 std::string nametag_colorless = unescape_enriched(nametag->nametag_text);
622 core::dimension2d<u32> textsize =
623 g_fontengine->getFont()->getDimension(
624 utf8_to_wide(nametag_colorless).c_str());
625 f32 zDiv = transformed_pos[3] == 0.0f ? 1.0f :
626 core::reciprocal(transformed_pos[3]);
627 v2u32 screensize = m_driver->getScreenSize();
629 screen_pos.X = screensize.X *
630 (0.5 * transformed_pos[0] * zDiv + 0.5) - textsize.Width / 2;
631 screen_pos.Y = screensize.Y *
632 (0.5 - transformed_pos[1] * zDiv * 0.5) - textsize.Height / 2;
633 core::rect<s32> size(0, 0, textsize.Width, textsize.Height);
634 g_fontengine->getFont()->draw(utf8_to_wide(nametag->nametag_text).c_str(),
635 size + screen_pos, nametag->nametag_color);
640 Nametag *Camera::addNametag(scene::ISceneNode *parent_node,
641 std::string nametag_text, video::SColor nametag_color)
643 Nametag *nametag = new Nametag(parent_node, nametag_text, nametag_color);
644 m_nametags.push_back(nametag);
648 void Camera::removeNametag(Nametag *nametag)
650 m_nametags.remove(nametag);