Skip to content

Commit 09970b7

Browse files
sapiersapier
sapier
authored and
sapier
committedMay 17, 2014
Add support for interlaced polarized 3d screens
Add (experimental) support for topbottom as well as sidebyside 3d mode
1 parent d9f6f9e commit 09970b7

17 files changed

+909
-423
lines changed
 

‎minetest.conf.example

+9-3
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,15 @@
127127
#view_bobbing_amount = 1.0
128128
# Amount of fall bobbing (0 = no fall bobbing, 1.0 = normal, 2.0 = double)
129129
#fall_bobbing_amount = 0.0
130-
# Anaglyph stereo
131-
#anaglyph = false
132-
#anaglyph_strength = 0.1
130+
# 3d support,
131+
# right now:
132+
# "none" = no 3d output,
133+
# "anaglyph" = cyan/magenta color 3d,
134+
# "interlaced" = odd/even line based polarisation screen support,
135+
# "topbottom" = split screen top boton,
136+
# "sidebyside" = split screen side by side
137+
#3d_mode = none
138+
#3d_paralax_strength = 0.025
133139
# In-game chat console background color (R,G,B)
134140
#console_color = (0,0,0)
135141
# In-game chat console background alpha (opaqueness, between 0 and 255)

‎src/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,7 @@ set(minetest_SRCS
460460
guiEngine.cpp
461461
guiFileSelectMenu.cpp
462462
convert_json.cpp
463+
drawscene.cpp
463464
${minetest_SCRIPT_SRCS}
464465
)
465466

‎src/camera.cpp

+52-27
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,9 @@ Camera::Camera(scene::ISceneManager* smgr, MapDrawControl& draw_control,
8282
m_wield_change_timer(0.125),
8383
m_wield_mesh_next(NULL),
8484
m_previous_playeritem(-1),
85-
m_previous_itemname("")
85+
m_previous_itemname(""),
86+
87+
m_camera_mode(CAMERA_MODE_FIRST)
8688
{
8789
//dstream<<__FUNCTION_NAME<<std::endl;
8890

@@ -159,8 +161,10 @@ void Camera::step(f32 dtime)
159161
if(m_wield_change_timer > 0.125)
160162
m_wield_change_timer = 0.125;
161163

162-
if(m_wield_change_timer >= 0 && was_under_zero) {
163-
if(m_wield_mesh_next) {
164+
if(m_wield_change_timer >= 0 && was_under_zero)
165+
{
166+
if(m_wield_mesh_next)
167+
{
164168
m_wieldnode->setMesh(m_wield_mesh_next);
165169
m_wieldnode->setVisible(true);
166170
} else {
@@ -189,11 +193,14 @@ void Camera::step(f32 dtime)
189193
#endif
190194
#if 1
191195
// Animation is getting turned off
192-
if(m_view_bobbing_anim < 0.25){
196+
if(m_view_bobbing_anim < 0.25)
197+
{
193198
m_view_bobbing_anim -= offset;
194-
} else if(m_view_bobbing_anim > 0.75){
199+
} else if(m_view_bobbing_anim > 0.75) {
195200
m_view_bobbing_anim += offset;
196-
} if(m_view_bobbing_anim < 0.5){
201+
}
202+
if(m_view_bobbing_anim < 0.5)
203+
{
197204
m_view_bobbing_anim += offset;
198205
if(m_view_bobbing_anim > 0.5)
199206
m_view_bobbing_anim = 0.5;
@@ -217,7 +224,8 @@ void Camera::step(f32 dtime)
217224
bool step = (was == 0 ||
218225
(was < 0.5f && m_view_bobbing_anim >= 0.5f) ||
219226
(was > 0.5f && m_view_bobbing_anim <= 0.5f));
220-
if(step){
227+
if(step)
228+
{
221229
MtEvent *e = new SimpleTriggerEvent("ViewBobbingStep");
222230
m_gamedef->event()->put(e);
223231
}
@@ -237,10 +245,11 @@ void Camera::step(f32 dtime)
237245
float lim = 0.15;
238246
if(m_digging_anim_was < lim && m_digging_anim >= lim)
239247
{
240-
if(m_digging_button == 0){
248+
if(m_digging_button == 0)
249+
{
241250
MtEvent *e = new SimpleTriggerEvent("CameraPunchLeft");
242251
m_gamedef->event()->put(e);
243-
} else if(m_digging_button == 1){
252+
} else if(m_digging_button == 1) {
244253
MtEvent *e = new SimpleTriggerEvent("CameraPunchRight");
245254
m_gamedef->event()->put(e);
246255
}
@@ -249,8 +258,7 @@ void Camera::step(f32 dtime)
249258
}
250259

251260
void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
252-
f32 tool_reload_ratio,
253-
int current_camera_mode, ClientEnvironment &c_env)
261+
f32 tool_reload_ratio, ClientEnvironment &c_env)
254262
{
255263
// Get player position
256264
// Smooth the movement when walking up stairs
@@ -278,7 +286,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
278286

279287
// Fall bobbing animation
280288
float fall_bobbing = 0;
281-
if(player->camera_impact >= 1 && current_camera_mode < CAMERA_MODE_THIRD)
289+
if(player->camera_impact >= 1 && m_camera_mode < CAMERA_MODE_THIRD)
282290
{
283291
if(m_view_bobbing_fall == -1) // Effect took place and has finished
284292
player->camera_impact = m_view_bobbing_fall = 0;
@@ -297,7 +305,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
297305

298306
// Calculate players eye offset for different camera modes
299307
v3f PlayerEyeOffset = player->getEyeOffset();
300-
if (current_camera_mode == CAMERA_MODE_FIRST)
308+
if (m_camera_mode == CAMERA_MODE_FIRST)
301309
PlayerEyeOffset += player->eye_offset_first;
302310
else
303311
PlayerEyeOffset += player->eye_offset_third;
@@ -312,7 +320,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
312320
v3f rel_cam_target = v3f(0,0,1);
313321
v3f rel_cam_up = v3f(0,1,0);
314322

315-
if (m_view_bobbing_anim != 0 && current_camera_mode < CAMERA_MODE_THIRD)
323+
if (m_view_bobbing_anim != 0 && m_camera_mode < CAMERA_MODE_THIRD)
316324
{
317325
f32 bobfrac = my_modf(m_view_bobbing_anim * 2);
318326
f32 bobdir = (m_view_bobbing_anim < 0.5) ? 1.0 : -1.0;
@@ -365,16 +373,17 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
365373
v3f my_cp = m_camera_position;
366374

367375
// Reposition the camera for third person view
368-
if (current_camera_mode > CAMERA_MODE_FIRST) {
369-
370-
if (current_camera_mode == CAMERA_MODE_THIRD_FRONT)
376+
if (m_camera_mode > CAMERA_MODE_FIRST)
377+
{
378+
if (m_camera_mode == CAMERA_MODE_THIRD_FRONT)
371379
m_camera_direction *= -1;
372380

373381
my_cp.Y += 2;
374382

375383
// Calculate new position
376384
bool abort = false;
377-
for (int i = BS; i <= BS*2; i++) {
385+
for (int i = BS; i <= BS*2; i++)
386+
{
378387
my_cp.X = m_camera_position.X + m_camera_direction.X*-i;
379388
my_cp.Z = m_camera_position.Z + m_camera_direction.Z*-i;
380389
if (i > 12)
@@ -384,7 +393,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
384393
INodeDefManager *nodemgr = m_gamedef->ndef();
385394
MapNode n = c_env.getClientMap().getNodeNoEx(floatToInt(my_cp, BS));
386395
const ContentFeatures& features = nodemgr->get(n);
387-
if(features.walkable) {
396+
if(features.walkable)
397+
{
388398
my_cp.X += m_camera_direction.X*-1*-BS/2;
389399
my_cp.Z += m_camera_direction.Z*-1*-BS/2;
390400
my_cp.Y += m_camera_direction.Y*-1*-BS/2;
@@ -413,7 +423,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
413423
m_cameranode->setTarget(my_cp-intToFloat(m_camera_offset, BS) + 100 * m_camera_direction);
414424

415425
// update the camera position in front-view mode to render blocks behind player
416-
if (current_camera_mode == CAMERA_MODE_THIRD_FRONT)
426+
if (m_camera_mode == CAMERA_MODE_THIRD_FRONT)
417427
m_camera_position = my_cp;
418428

419429
// Get FOV setting
@@ -439,7 +449,8 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
439449
wield_position.Y -= 40 + m_wield_change_timer*320;
440450
else
441451
wield_position.Y -= 40 - m_wield_change_timer*320;
442-
if(m_digging_anim < 0.05 || m_digging_anim > 0.5){
452+
if(m_digging_anim < 0.05 || m_digging_anim > 0.5)
453+
{
443454
f32 frac = 1.0;
444455
if(m_digging_anim > 0.5)
445456
frac = 2.0 * (m_digging_anim - 0.5);
@@ -468,8 +479,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
468479
quat_slerp.slerp(quat_begin, quat_end, sin(digfrac * M_PI));
469480
quat_slerp.toEuler(wield_rotation);
470481
wield_rotation *= core::RADTODEG;
471-
}
472-
else {
482+
} else {
473483
f32 bobfrac = my_modf(m_view_bobbing_anim);
474484
wield_position.X -= sin(bobfrac*M_PI*2.0) * 3.0;
475485
wield_position.Y += sin(my_modf(bobfrac*2.0)*M_PI) * 3.0;
@@ -654,12 +664,14 @@ void Camera::wield(const ItemStack &item, u16 playeritem)
654664
std::string itemname = item.getDefinition(idef).name;
655665
m_wield_mesh_next = idef->getWieldMesh(itemname, m_gamedef);
656666
if(playeritem != m_previous_playeritem &&
657-
!(m_previous_itemname == "" && itemname == "")) {
667+
!(m_previous_itemname == "" && itemname == ""))
668+
{
658669
m_previous_playeritem = playeritem;
659670
m_previous_itemname = itemname;
660671
if(m_wield_change_timer >= 0.125)
661672
m_wield_change_timer = -0.125;
662-
else if(m_wield_change_timer > 0) {
673+
else if(m_wield_change_timer > 0)
674+
{
663675
m_wield_change_timer = -m_wield_change_timer;
664676
}
665677
} else {
@@ -670,7 +682,8 @@ void Camera::wield(const ItemStack &item, u16 playeritem)
670682
m_wieldnode->setVisible(false);
671683
}
672684
m_wield_mesh_next = NULL;
673-
if(m_previous_itemname != itemname) {
685+
if(m_previous_itemname != itemname)
686+
{
674687
m_previous_itemname = itemname;
675688
m_wield_change_timer = 0;
676689
}
@@ -679,7 +692,7 @@ void Camera::wield(const ItemStack &item, u16 playeritem)
679692
}
680693
}
681694

682-
void Camera::drawWieldedTool()
695+
void Camera::drawWieldedTool(irr::core::matrix4* translation)
683696
{
684697
// Set vertex colors of wield mesh according to light level
685698
u8 li = m_wieldlight;
@@ -695,5 +708,17 @@ void Camera::drawWieldedTool()
695708
cam->setFOV(72.0*M_PI/180.0);
696709
cam->setNearValue(0.1);
697710
cam->setFarValue(100);
711+
if (translation != NULL)
712+
{
713+
irr::core::matrix4 startMatrix = cam->getAbsoluteTransformation();
714+
irr::core::vector3df focusPoint = (cam->getTarget()
715+
- cam->getAbsolutePosition()).setLength(1)
716+
+ cam->getAbsolutePosition();
717+
718+
irr::core::vector3df camera_pos =
719+
(startMatrix * *translation).getTranslation();
720+
cam->setPosition(camera_pos);
721+
cam->setTarget(focusPoint);
722+
}
698723
m_wieldmgr->drawAll();
699724
}

‎src/camera.h

+21-4
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class LocalPlayer;
3333
struct MapDrawControl;
3434
class IGameDef;
3535

36-
enum CameraModes {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
36+
enum CameraMode {CAMERA_MODE_FIRST, CAMERA_MODE_THIRD, CAMERA_MODE_THIRD_FRONT};
3737

3838
/*
3939
Client camera class, manages the player and camera scene nodes, the viewing distance
@@ -117,8 +117,7 @@ class Camera
117117
// Update the camera from the local player's position.
118118
// busytime is used to adjust the viewing range.
119119
void update(LocalPlayer* player, f32 frametime, f32 busytime,
120-
f32 tool_reload_ratio,
121-
int current_camera_mode, ClientEnvironment &c_env);
120+
f32 tool_reload_ratio, ClientEnvironment &c_env);
122121

123122
// Render distance feedback loop
124123
void updateViewingRange(f32 frametime_in, f32 busytime_in);
@@ -133,7 +132,23 @@ class Camera
133132
// Draw the wielded tool.
134133
// This has to happen *after* the main scene is drawn.
135134
// Warning: This clears the Z buffer.
136-
void drawWieldedTool();
135+
void drawWieldedTool(irr::core::matrix4* translation=NULL);
136+
137+
// Toggle the current camera mode
138+
void toggleCameraMode() {
139+
if (m_camera_mode == CAMERA_MODE_FIRST)
140+
m_camera_mode = CAMERA_MODE_THIRD;
141+
else if (m_camera_mode == CAMERA_MODE_THIRD)
142+
m_camera_mode = CAMERA_MODE_THIRD_FRONT;
143+
else
144+
m_camera_mode = CAMERA_MODE_FIRST;
145+
}
146+
147+
//read the current camera mode
148+
inline CameraMode getCameraMode()
149+
{
150+
return m_camera_mode;
151+
}
137152

138153
private:
139154
// Nodes
@@ -196,6 +211,8 @@ class Camera
196211
scene::IMesh *m_wield_mesh_next;
197212
u16 m_previous_playeritem;
198213
std::string m_previous_itemname;
214+
215+
CameraMode m_camera_mode;
199216
};
200217

201218
#endif

‎src/client.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
5151
#include "util/directiontables.h"
5252
#include "util/pointedthing.h"
5353
#include "version.h"
54+
#include "drawscene.h"
55+
56+
extern gui::IGUIEnvironment* guienv;
5457

5558
/*
5659
QueuedMeshUpdate
@@ -2648,10 +2651,6 @@ float Client::mediaReceiveProgress()
26482651
return 1.0; // downloader only exists when not yet done
26492652
}
26502653

2651-
void draw_load_screen(const std::wstring &text,
2652-
IrrlichtDevice* device, gui::IGUIFont* font,
2653-
float dtime=0 ,int percent=0, bool clouds=true);
2654-
26552654
void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
26562655
{
26572656
infostream<<"Client::afterContentReceived() started"<<std::endl;
@@ -2680,7 +2679,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
26802679
{
26812680
verbosestream<<"Updating item textures and meshes"<<std::endl;
26822681
wchar_t* text = wgettext("Item textures...");
2683-
draw_load_screen(text,device,font,0,0);
2682+
draw_load_screen(text, device, guienv, font, 0, 0);
26842683
std::set<std::string> names = m_itemdef->getAll();
26852684
size_t size = names.size();
26862685
size_t count = 0;
@@ -2693,7 +2692,7 @@ void Client::afterContentReceived(IrrlichtDevice *device, gui::IGUIFont* font)
26932692
count++;
26942693
percent = count*100/size;
26952694
if (count%50 == 0) // only update every 50 item
2696-
draw_load_screen(text,device,font,0,percent);
2695+
draw_load_screen(text, device, guienv, font, 0, percent);
26972696
}
26982697
delete[] text;
26992698
}

‎src/clientmap.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -856,7 +856,7 @@ int ClientMap::getBackgroundBrightness(float max_d, u32 daylight_factor,
856856
return ret;
857857
}
858858

859-
void ClientMap::renderPostFx()
859+
void ClientMap::renderPostFx(CameraMode cam_mode)
860860
{
861861
INodeDefManager *nodemgr = m_gamedef->ndef();
862862

@@ -867,16 +867,16 @@ void ClientMap::renderPostFx()
867867
v3f camera_position = m_camera_position;
868868
m_camera_mutex.Unlock();
869869

870-
LocalPlayer *player = m_client->getEnv().getLocalPlayer();
871-
872870
MapNode n = getNodeNoEx(floatToInt(camera_position, BS));
873871

874872
// - If the player is in a solid node, make everything black.
875873
// - If the player is in liquid, draw a semi-transparent overlay.
876874
// - Do not if player is in third person mode
877875
const ContentFeatures& features = nodemgr->get(n);
878876
video::SColor post_effect_color = features.post_effect_color;
879-
if(features.solidness == 2 && !(g_settings->getBool("noclip") && m_gamedef->checkLocalPrivilege("noclip")) && player->camera_mode == CAMERA_MODE_FIRST)
877+
if(features.solidness == 2 && !(g_settings->getBool("noclip") &&
878+
m_gamedef->checkLocalPrivilege("noclip")) &&
879+
cam_mode == CAMERA_MODE_FIRST)
880880
{
881881
post_effect_color = video::SColor(255, 0, 0, 0);
882882
}

‎src/clientmap.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2222

2323
#include "irrlichttypes_extrabloated.h"
2424
#include "map.h"
25+
#include "camera.h"
2526
#include <set>
2627
#include <map>
2728

@@ -126,7 +127,7 @@ class ClientMap : public Map, public scene::ISceneNode
126127
int getBackgroundBrightness(float max_d, u32 daylight_factor,
127128
int oldvalue, bool *sunlight_seen_result);
128129

129-
void renderPostFx();
130+
void renderPostFx(CameraMode cam_mode);
130131

131132
// For debug printing
132133
virtual void PrintInfo(std::ostream &out);

‎src/content_cao.cpp

+183-114
Large diffs are not rendered by default.

‎src/defaultsettings.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ void set_default_settings(Settings *settings)
5656
settings->setDefault("keymap_camera_mode", "KEY_F7");
5757
settings->setDefault("keymap_increase_viewing_range_min", "+");
5858
settings->setDefault("keymap_decrease_viewing_range_min", "-");
59-
settings->setDefault("anaglyph", "false");
60-
settings->setDefault("anaglyph_strength", "0.1");
59+
settings->setDefault("3d_mode", "none");
60+
settings->setDefault("3d_paralax_strength", "0.025");
6161
settings->setDefault("aux1_descends", "false");
6262
settings->setDefault("doubletap_jump", "false");
6363
settings->setDefault("always_fly_fast", "true");

‎src/drawscene.cpp

+529
Large diffs are not rendered by default.

‎src/drawscene.h

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
Minetest
3+
Copyright (C) 2010-2014 celeron55, Perttu Ahola <celeron55@gmail.com>
4+
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.
9+
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.
14+
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.
18+
*/
19+
20+
#ifndef DRAWSCENE_H_
21+
#define DRAWSCENE_H_
22+
23+
#include "camera.h"
24+
#include "hud.h"
25+
#include "irrlichttypes_extrabloated.h"
26+
27+
28+
void draw_load_screen(const std::wstring &text, IrrlichtDevice* device,
29+
gui::IGUIEnvironment* guienv, gui::IGUIFont* font, float dtime=0,
30+
int percent=0, bool clouds=true);
31+
32+
void draw_scene(video::IVideoDriver* driver, scene::ISceneManager* smgr,
33+
Camera& camera, Client& client, LocalPlayer* player, Hud& hud,
34+
gui::IGUIEnvironment* guienv, std::vector<aabb3f> hilightboxes,
35+
const v2u32& screensize, video::SColor skycolor, bool show_hud);
36+
37+
#endif /* DRAWSCENE_H_ */

‎src/game.cpp

+30-234
Large diffs are not rendered by default.

‎src/hud.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,6 @@ void Hud::drawHotbar(u16 playeritem) {
435435

436436

437437
void Hud::drawCrosshair() {
438-
if (!(player->hud_flags & HUD_FLAG_CROSSHAIR_VISIBLE) ||
439-
(player->camera_mode == CAMERA_MODE_THIRD_FRONT)) {
440-
return;
441-
}
442438

443439
if (use_crosshair_image) {
444440
video::ITexture *crosshair = tsrc->getTexture("crosshair.png");

‎src/localplayer.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef):
4343
last_pitch(0),
4444
last_yaw(0),
4545
last_keyPressed(0),
46-
camera_mode(0),
4746
eye_offset_first(v3f(0,0,0)),
4847
eye_offset_third(v3f(0,0,0)),
4948
last_animation(NO_ANIM),
@@ -54,7 +53,8 @@ LocalPlayer::LocalPlayer(IGameDef *gamedef):
5453
m_old_node_below(32767,32767,32767),
5554
m_old_node_below_type("air"),
5655
m_need_to_get_new_sneak_node(true),
57-
m_can_jump(false)
56+
m_can_jump(false),
57+
m_cao(NULL)
5858
{
5959
// Initialize hp to 0, so that no hearts will be shown if server
6060
// doesn't support health points
@@ -505,7 +505,7 @@ void LocalPlayer::applyControl(float dtime)
505505
if(control.jump)
506506
{
507507
if(free_move)
508-
{
508+
{
509509
if(g_settings->getBool("aux1_descends") || g_settings->getBool("always_fly_fast"))
510510
{
511511
if(fast_move)

‎src/localplayer.h

+12-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
2424
#include <list>
2525

2626
class Environment;
27-
27+
class GenericCAO;
2828
class ClientActiveObject;
2929

3030
enum LocalPlayerAnimations {NO_ANIM, WALK_ANIM, DIG_ANIM, WD_ANIM}; // no local animation, walking, digging, both
@@ -62,7 +62,6 @@ class LocalPlayer : public Player
6262
unsigned int last_keyPressed;
6363

6464
float camera_impact;
65-
int camera_mode;
6665
v3f eye_offset_first;
6766
v3f eye_offset_third;
6867

@@ -72,6 +71,15 @@ class LocalPlayer : public Player
7271
std::string hotbar_image;
7372
std::string hotbar_selected_image;
7473

74+
GenericCAO* getCAO() const {
75+
return m_cao;
76+
}
77+
78+
void setCAO(GenericCAO* toset) {
79+
assert( m_cao == NULL );
80+
m_cao = toset;
81+
}
82+
7583
private:
7684
// This is used for determining the sneaking range
7785
v3s16 m_sneak_node;
@@ -84,6 +92,8 @@ class LocalPlayer : public Player
8492
// Whether recalculation of the sneak node is needed
8593
bool m_need_to_get_new_sneak_node;
8694
bool m_can_jump;
95+
96+
GenericCAO* m_cao;
8797
};
8898

8999
#endif

‎src/sky.cpp

+15-15
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "camera.h" // CameraModes
1414

1515
//! constructor
16-
Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlayer* player):
16+
Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id):
1717
scene::ISceneNode(parent, mgr, id),
1818
m_visible(true),
1919
m_fallback_bg_color(255,255,255,255),
@@ -22,8 +22,7 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlay
2222
m_cloud_brightness(0.5),
2323
m_bgcolor_bright_f(1,1,1,1),
2424
m_skycolor_bright_f(1,1,1,1),
25-
m_cloudcolor_bright_f(1,1,1,1),
26-
m_player(player)
25+
m_cloudcolor_bright_f(1,1,1,1)
2726
{
2827
setAutomaticCulling(scene::EAC_OFF);
2928
Box.MaxEdge.set(0,0,0);
@@ -66,14 +65,14 @@ Sky::Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlay
6665
m_materials[3].setTexture(0, m_sun_texture);
6766
m_materials[3].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
6867
if (m_sun_tonemap)
69-
m_materials[3].Lighting = true;
68+
m_materials[3].Lighting = true;
7069
}
7170
if (m_moon_texture){
7271
m_materials[4] = mat;
7372
m_materials[4].setTexture(0, m_moon_texture);
7473
m_materials[4].MaterialType = video::EMT_TRANSPARENT_ALPHA_CHANNEL;
7574
if (m_moon_tonemap)
76-
m_materials[4].Lighting = true;
75+
m_materials[4].Lighting = true;
7776
}
7877

7978
for(u32 i=0; i<SKY_STAR_COUNT; i++){
@@ -161,20 +160,20 @@ void Sky::render()
161160
video::SColor mooncolor2 = mooncolor2_f.toSColor();
162161

163162
// Calculate offset normalized to the X dimension of a 512x1 px tonemap
164-
float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
163+
float offset=(1.0-fabs(sin((m_time_of_day - 0.5)*irr::core::PI)))*511;
165164

166165
if (m_sun_tonemap){
167166
u8 * texels = (u8 *)m_sun_tonemap->lock();
168167
video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
169168
video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
170-
m_sun_tonemap->unlock();
169+
m_sun_tonemap->unlock();
171170
m_materials[3].EmissiveColor = texel_color;
172171
}
173172
if (m_moon_tonemap){
174173
u8 * texels = (u8 *)m_moon_tonemap->lock();
175174
video::SColor* texel = (video::SColor *)(texels + (u32)offset * 4);
176175
video::SColor texel_color (255,texel->getRed(),texel->getGreen(), texel->getBlue());
177-
m_moon_tonemap->unlock();
176+
m_moon_tonemap->unlock();
178177
m_materials[4].EmissiveColor = texel_color;
179178
}
180179

@@ -263,7 +262,7 @@ void Sky::render()
263262
}
264263

265264
// Draw sun
266-
if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85){
265+
if(wicked_time_of_day > 0.15 && wicked_time_of_day < 0.85){
267266
if (!m_sun_texture){
268267
driver->setMaterial(m_materials[1]);
269268
float d = sunsize * 1.7;
@@ -411,7 +410,7 @@ void Sky::render()
411410
vertices[i].Pos.rotateXZBy(-90);
412411
vertices[i].Pos.rotateXYBy(wicked_time_of_day * 360 - 90);
413412
}
414-
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
413+
driver->drawIndexedTriangleFan(&vertices[0], 4, indices, 2);
415414
}
416415
}
417416

@@ -485,7 +484,8 @@ void Sky::render()
485484
}
486485

487486
void Sky::update(float time_of_day, float time_brightness,
488-
float direct_brightness, bool sunlight_seen)
487+
float direct_brightness, bool sunlight_seen,
488+
CameraMode cam_mode, float yaw, float pitch)
489489
{
490490
// Stabilize initial brightness and color values by flooding updates
491491
if(m_first_update){
@@ -496,7 +496,7 @@ void Sky::update(float time_of_day, float time_brightness,
496496
m_first_update = false;
497497
for(u32 i=0; i<100; i++){
498498
update(time_of_day, time_brightness, direct_brightness,
499-
sunlight_seen);
499+
sunlight_seen, cam_mode, yaw, pitch);
500500
}
501501
return;
502502
}
@@ -580,16 +580,16 @@ void Sky::update(float time_of_day, float time_brightness,
580580
{
581581
// calculate hemisphere value from yaw, (inverted in third person front view)
582582
s8 dir_factor = 1;
583-
if (m_player->camera_mode > CAMERA_MODE_THIRD)
583+
if (cam_mode > CAMERA_MODE_THIRD)
584584
dir_factor = -1;
585-
f32 pointcolor_blend = wrapDegrees_0_360(m_player->getYaw()*dir_factor + 90);
585+
f32 pointcolor_blend = wrapDegrees_0_360( yaw*dir_factor + 90);
586586
if (pointcolor_blend > 180)
587587
pointcolor_blend = 360 - pointcolor_blend;
588588
pointcolor_blend /= 180;
589589
// bound view angle to determine where transition starts and ends
590590
pointcolor_blend = rangelim(1 - pointcolor_blend * 1.375, 0, 1 / 1.375) * 1.375;
591591
// combine the colors when looking up or down, otherwise turning looks weird
592-
pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(m_player->getPitch())) / 90 * 1.5, 1));
592+
pointcolor_blend += (0.5 - pointcolor_blend) * (1 - MYMIN((90 - std::abs(pitch)) / 90 * 1.5, 1));
593593
// invert direction to match where the sun and moon are rising
594594
if (m_time_of_day > 0.5)
595595
pointcolor_blend = 1 - pointcolor_blend;

‎src/sky.h

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
1919

2020
#include "irrlichttypes_extrabloated.h"
2121
#include <ISceneNode.h>
22-
#include "localplayer.h"
22+
#include "camera.h"
2323

2424
#ifndef SKY_HEADER
2525
#define SKY_HEADER
@@ -32,7 +32,7 @@ class Sky : public scene::ISceneNode
3232
{
3333
public:
3434
//! constructor
35-
Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id, LocalPlayer* player);
35+
Sky(scene::ISceneNode* parent, scene::ISceneManager* mgr, s32 id);
3636

3737
virtual void OnRegisterSceneNode();
3838

@@ -50,7 +50,8 @@ class Sky : public scene::ISceneNode
5050
{ return SKY_MATERIAL_COUNT; }
5151

5252
void update(float m_time_of_day, float time_brightness,
53-
float direct_brightness, bool sunlight_seen);
53+
float direct_brightness, bool sunlight_seen, CameraMode cam_mode,
54+
float yaw, float pitch);
5455

5556
float getBrightness(){ return m_brightness; }
5657

@@ -126,7 +127,6 @@ class Sky : public scene::ISceneNode
126127
video::SColorf m_cloudcolor_f;
127128
v3f m_stars[SKY_STAR_COUNT];
128129
video::S3DVertex m_star_vertices[SKY_STAR_COUNT*4];
129-
LocalPlayer* m_player;
130130
video::ITexture* m_sun_texture;
131131
video::ITexture* m_moon_texture;
132132
video::ITexture* m_sun_tonemap;

0 commit comments

Comments
 (0)
Please sign in to comment.