forked from Devsh-Graphics-Programming/Nabla
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCSceneManager.cpp
More file actions
145 lines (118 loc) · 4.5 KB
/
CSceneManager.cpp
File metadata and controls
145 lines (118 loc) · 4.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
// Copyright (C) 2019 - DevSH Graphics Programming Sp. z O.O.
// This file is part of the "Nabla Engine" and was originally part of the "Irrlicht Engine"
// For conditions of distribution and use, see copyright notice in nabla.h
// See the original file in irrlicht source for authors
#include "BuildConfigOptions.h"
#include "CSceneManager.h"
#include "nbl_os.h"
#include "CCameraSceneNode.h"
#include "CSceneNodeAnimatorCameraFPS.h"
#include "CSceneNodeAnimatorCameraMaya.h"
#include "CSceneNodeAnimatorCameraModifiedMaya.h"
namespace nbl
{
namespace scene
{
//! Adds a camera scene node to the tree and sets it as active camera.
//! \param position: Position of the space relative to its parent where the camera will be placed.
//! \param lookat: Position where the camera will look at. Also known as target.
//! \param parent: Parent scene node of the camera. Can be null. If the parent moves,
//! the camera will move too.
//! \return Returns pointer to interface to camera
ICameraSceneNode* CSceneManager::addCameraSceneNode(IDummyTransformationSceneNode* parent,
const core::vector3df& position, const core::vectorSIMDf& lookat, int32_t id,
bool makeActive)
{
if (!parent)
parent = this;
ICameraSceneNode* node = new CCameraSceneNode(parent, this, id, position, lookat);
if (makeActive)
setActiveCamera(node);
node->drop();
return node;
}
//! Adds a camera scene node which is able to be controlled with the mouse similar
//! to in the 3D Software Maya by Alias Wavefront.
//! The returned pointer must not be dropped.
ICameraSceneNode* CSceneManager::addCameraSceneNodeMaya(IDummyTransformationSceneNode* parent,
float rotateSpeed, float zoomSpeed, float translationSpeed, int32_t id, float distance,
bool makeActive)
{
ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
core::vectorSIMDf(0,0,100), id, makeActive);
if (node)
{
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraMaya(CursorControl,
rotateSpeed, zoomSpeed, translationSpeed, distance);
node->addAnimator(anm);
anm->drop();
}
return node;
}
ICameraSceneNode* CSceneManager::addCameraSceneNodeModifiedMaya(IDummyTransformationSceneNode* parent,
float rotateSpeed, float zoomSpeed,
float translationSpeed, int32_t id, float distance,
float scrlZoomSpeedMultiplier, bool zoomWithRMB,
bool makeActive)
{
ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
core::vectorSIMDf(0, 0, 100), id, makeActive);
if (node)
{
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraModifiedMaya(CursorControl,
rotateSpeed, zoomSpeed, translationSpeed, distance, scrlZoomSpeedMultiplier, zoomWithRMB);
node->addAnimator(anm);
anm->drop();
}
return node;
}
//! Adds a camera scene node which is able to be controlled with the mouse and keys
//! like in most first person shooters (FPS):
ICameraSceneNode* CSceneManager::addCameraSceneNodeFPS(IDummyTransformationSceneNode* parent,
float rotateSpeed, float moveSpeed, int32_t id, SKeyMap* keyMapArray,
int32_t keyMapSize, bool noVerticalMovement, float jumpSpeed,
bool invertMouseY, bool makeActive)
{
ICameraSceneNode* node = addCameraSceneNode(parent, core::vector3df(),
core::vectorSIMDf(0,0,100), id, makeActive);
if (node)
{
ISceneNodeAnimator* anm = new CSceneNodeAnimatorCameraFPS(CursorControl,
rotateSpeed, moveSpeed, jumpSpeed,
keyMapArray, keyMapSize, noVerticalMovement, invertMouseY);
// Bind the node's rotation to its target. This is consistent with 1.4.2 and below.
node->bindTargetAndRotation(true);
node->addAnimator(anm);
anm->drop();
}
return node;
}
//!
void CSceneManager::OnAnimate(uint32_t timeMs)
{
size_t prevSize = Children.size();
for (size_t i=0; i<prevSize;)
{
IDummyTransformationSceneNode* tmpChild = Children[i];
if (tmpChild->isISceneNode())
static_cast<ISceneNode*>(tmpChild)->OnAnimate(timeMs);
else
OnAnimate_static(tmpChild,timeMs);
if (Children[i]>tmpChild)
prevSize = Children.size();
else
i++;
}
}
//! Posts an input event to the environment. Usually you do not have to
//! use this method, it is used by the internal engine.
bool CSceneManager::receiveIfEventReceiverDidNotAbsorb(const SEvent& event)
{
bool ret = false;
ICameraSceneNode* cam = getActiveCamera();
if (cam)
ret = cam->OnEvent(event);
return ret;
}
} // end namespace scene
} // end namespace nbl