mirror of https://github.com/axmolengine/axmol.git
visiting camera
This commit is contained in:
parent
1e15131b2b
commit
4dce59582b
|
@ -1242,7 +1242,7 @@ void Node::visit(Renderer* renderer, const Mat4 &parentTransform, uint32_t paren
|
|||
director->pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW);
|
||||
director->loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_MODELVIEW, _modelViewTransform);
|
||||
|
||||
auto camera = director->getCurrentCamera();
|
||||
auto camera = Camera::getVisitingCamera();
|
||||
bool visibleByCamera = camera ? (unsigned short)camera->getCameraFlag() & _cameraMask : true;
|
||||
|
||||
int i = 0;
|
||||
|
|
|
@ -185,12 +185,6 @@ void Scene::addChildToPhysicsWorld(Node* child)
|
|||
}
|
||||
}
|
||||
|
||||
Camera* Scene::getCameraByIndex(int index) const
|
||||
{
|
||||
CCASSERT(index < _cameras.size(), "invalid index");
|
||||
return _cameras[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -65,10 +65,8 @@ public:
|
|||
using Node::addChild;
|
||||
virtual std::string getDescription() const override;
|
||||
|
||||
/** get camera count */
|
||||
ssize_t getCameraCount() const { return _cameras.size(); }
|
||||
/** get camera */
|
||||
Camera* getCameraByIndex(int index) const;
|
||||
/** get all cameras */
|
||||
const std::vector<Camera*>& getCameras() const { return _cameras; }
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Scene();
|
||||
|
@ -82,6 +80,7 @@ protected:
|
|||
friend class ProtectedNode;
|
||||
friend class SpriteBatchNode;
|
||||
friend class Camera;
|
||||
friend class Director;
|
||||
|
||||
std::vector<Camera*> _cameras; //weak ref to Camera
|
||||
|
||||
|
|
|
@ -29,6 +29,8 @@
|
|||
|
||||
NS_CC_BEGIN
|
||||
|
||||
Camera* Camera::_visitingCamera = nullptr;
|
||||
|
||||
Camera* Camera::create()
|
||||
{
|
||||
Camera* camera = nullptr;
|
||||
|
@ -224,17 +226,9 @@ void Camera::onEnter()
|
|||
{
|
||||
if (_scene == nullptr)
|
||||
{
|
||||
auto parent = getParent();
|
||||
while (parent)
|
||||
{
|
||||
auto scene = dynamic_cast<Scene*>(parent);
|
||||
if (scene)
|
||||
{
|
||||
setScene(scene);
|
||||
break;
|
||||
}
|
||||
parent = parent->getParent();
|
||||
}
|
||||
auto scene = getScene();
|
||||
if (scene)
|
||||
setScene(scene);
|
||||
}
|
||||
Node::onEnter();
|
||||
}
|
||||
|
|
|
@ -131,6 +131,8 @@ public:
|
|||
//override
|
||||
virtual void onEnter() override;
|
||||
virtual void onExit() override;
|
||||
|
||||
static const Camera* getVisitingCamera() { return _visitingCamera; }
|
||||
|
||||
CC_CONSTRUCTOR_ACCESS:
|
||||
Camera();
|
||||
|
@ -157,6 +159,10 @@ protected:
|
|||
float _farPlane;
|
||||
mutable bool _viewProjectionDirty;
|
||||
unsigned short _cameraFlag; // camera flag
|
||||
|
||||
static Camera* _visitingCamera;
|
||||
|
||||
friend class Director;
|
||||
};
|
||||
|
||||
NS_CC_END
|
||||
|
|
|
@ -158,7 +158,6 @@ bool Director::init(void)
|
|||
initMatrixStack();
|
||||
|
||||
_renderer = new Renderer;
|
||||
_currentCamera = nullptr;
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||
_console = new Console;
|
||||
|
@ -289,18 +288,19 @@ void Director::drawScene()
|
|||
if (_runningScene)
|
||||
{
|
||||
Camera* defaultCamera = nullptr;
|
||||
const auto& cameras = _runningScene->_cameras;
|
||||
//draw with camera
|
||||
for (ssize_t i = 0; i < _runningScene->getCameraCount(); i++)
|
||||
for (size_t i = 0; i < cameras.size(); i++)
|
||||
{
|
||||
_currentCamera = _runningScene->getCameraByIndex((int)i);
|
||||
if (_currentCamera->getCameraFlag() == CameraFlag::DEFAULT)
|
||||
Camera::_visitingCamera = cameras[i];
|
||||
if (Camera::_visitingCamera->getCameraFlag() == CameraFlag::DEFAULT)
|
||||
{
|
||||
defaultCamera = _currentCamera;
|
||||
defaultCamera = Camera::_visitingCamera;
|
||||
continue;
|
||||
}
|
||||
|
||||
pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _currentCamera->getViewProjectionMatrix());
|
||||
loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());
|
||||
|
||||
//visit the scene
|
||||
_runningScene->visit(_renderer, Mat4::IDENTITY, false);
|
||||
|
@ -311,9 +311,9 @@ void Director::drawScene()
|
|||
//draw with default camera
|
||||
if (defaultCamera)
|
||||
{
|
||||
_currentCamera = defaultCamera;
|
||||
Camera::_visitingCamera = defaultCamera;
|
||||
pushMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, _currentCamera->getViewProjectionMatrix());
|
||||
loadMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION, Camera::_visitingCamera->getViewProjectionMatrix());
|
||||
|
||||
//visit the scene
|
||||
_runningScene->visit(_renderer, Mat4::IDENTITY, false);
|
||||
|
@ -321,7 +321,7 @@ void Director::drawScene()
|
|||
|
||||
popMatrix(MATRIX_STACK_TYPE::MATRIX_STACK_PROJECTION);
|
||||
}
|
||||
_currentCamera = nullptr;
|
||||
Camera::_visitingCamera = nullptr;
|
||||
|
||||
_eventDispatcher->dispatchEvent(_eventAfterVisit);
|
||||
}
|
||||
|
|
|
@ -406,8 +406,6 @@ public:
|
|||
* get Frame Rate
|
||||
*/
|
||||
float getFrameRate() const { return _frameRate; }
|
||||
|
||||
Camera* getCurrentCamera() const { return _currentCamera; }
|
||||
|
||||
protected:
|
||||
void purgeDirector();
|
||||
|
@ -508,9 +506,6 @@ protected:
|
|||
|
||||
/* Renderer for the Director */
|
||||
Renderer *_renderer;
|
||||
|
||||
/* current camera, only vailid during drawScene */
|
||||
Camera* _currentCamera;
|
||||
|
||||
#if (CC_TARGET_PLATFORM != CC_PLATFORM_WINRT)
|
||||
/* Console for the director */
|
||||
|
|
Loading…
Reference in New Issue