init code for viewport

This commit is contained in:
Huabing.Xu 2015-05-29 13:47:29 +08:00
parent 22ddf53539
commit 1fb0ba112b
2 changed files with 32 additions and 4 deletions

View File

@ -35,6 +35,19 @@ NS_CC_BEGIN
Camera* Camera::_visitingCamera = nullptr;
Viewport::Viewport(float left, float bottom, float width, float height)
: _left(left)
, _bottom(bottom)
, _width(width)
, _height(height)
{
}
Viewport::Viewport()
{
_left = _bottom = 0.f;
_width = _height = 1.0f;
}
Camera* Camera::getDefaultCamera()
{

View File

@ -33,6 +33,20 @@ NS_CC_BEGIN
class Scene;
class FrameBufferObject;
/**
Viewport is a normalized to renderTarget
*/
struct CC_DLL Viewport
{
Viewport(float left, float bottom, float width, float height);
Viewport();
float _left;
float _bottom;
float _width;
float _height;
};
/**
* Note:
* Scene creates a default camera. And the default camera mask of Node is 1, therefore it can be seen by the default camera.
@ -54,10 +68,9 @@ enum class CameraFlag
USER7 = 1 << 7,
USER8 = 1 << 8,
};
/**
* Defines a camera .
*/
* Defines a camera .
*/
class CC_DLL Camera :public Node
{
friend class Scene;
@ -204,7 +217,7 @@ public:
void clearBackground(float depth);
void setFrameBufferObject(FrameBufferObject* fbo);
void setViewport(const Viewport& vp) { _viewport = vp; }
CC_CONSTRUCTOR_ACCESS:
Camera();
~Camera();
@ -222,6 +235,7 @@ CC_CONSTRUCTOR_ACCESS:
bool initPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane);
bool initOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane);
void applyFrameBufferObject();
protected:
Scene* _scene; //Scene camera belongs to
@ -244,6 +258,7 @@ protected:
static Camera* _visitingCamera;
friend class Director;
Viewport _viewport;
FrameBufferObject* _fbo;
};