2010-07-06 15:46:45 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:59:01 +08:00
|
|
|
Copyright (c) 2010-2011 cocos2d-x.org
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2011-07-01 15:08:23 +08:00
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2010-07-06 15:46:45 +08:00
|
|
|
|
2010-07-06 20:55:05 +08:00
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
2010-07-06 15:46:45 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-07-06 10:19:51 +08:00
|
|
|
#ifndef __CCCAMERA_H__
|
|
|
|
#define __CCCAMERA_H__
|
|
|
|
|
2011-03-07 17:11:57 +08:00
|
|
|
#include "CCObject.h"
|
2010-07-06 11:56:22 +08:00
|
|
|
#include "ccMacros.h"
|
2010-07-06 10:19:51 +08:00
|
|
|
#include <string>
|
2012-03-14 14:55:17 +08:00
|
|
|
#include "kazmath/mat4.h"
|
2012-04-07 12:02:40 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
A CCCamera is used in every CCNode.
|
|
|
|
Useful to look at the object from different views.
|
|
|
|
The OpenGL gluLookAt() function is used to locate the
|
|
|
|
camera.
|
|
|
|
|
|
|
|
If the object is transformed by any of the scale, rotation or
|
|
|
|
position attributes, then they will override the camera.
|
|
|
|
|
|
|
|
IMPORTANT: Either your use the camera or the rotation/scale/position properties. You can't use both.
|
|
|
|
World coordinates won't work if you use the camera.
|
|
|
|
|
|
|
|
Limitations:
|
|
|
|
|
|
|
|
- Some nodes, like CCParallaxNode, CCParticle uses world node coordinates, and they won't work properly if you move them (or any of their ancestors)
|
|
|
|
using the camera.
|
|
|
|
|
|
|
|
- It doesn't work on batched nodes like CCSprite objects when they are parented to a CCSpriteBatchNode object.
|
|
|
|
|
|
|
|
- It is recommended to use it ONLY if you are going to create 3D effects. For 2D effecs, use the action CCFollow or position/scale/rotate.
|
|
|
|
|
|
|
|
*/
|
|
|
|
class CC_DLL CCCamera : public CCObject
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
float m_fEyeX;
|
|
|
|
float m_fEyeY;
|
|
|
|
float m_fEyeZ;
|
|
|
|
|
|
|
|
float m_fCenterX;
|
|
|
|
float m_fCenterY;
|
|
|
|
float m_fCenterZ;
|
|
|
|
|
|
|
|
float m_fUpX;
|
|
|
|
float m_fUpY;
|
|
|
|
float m_fUpZ;
|
|
|
|
|
|
|
|
bool m_bDirty;
|
|
|
|
kmMat4 m_lookupMatrix;
|
|
|
|
public:
|
|
|
|
CCCamera(void);
|
|
|
|
~CCCamera(void);
|
|
|
|
|
|
|
|
void init(void);
|
|
|
|
|
2012-04-14 19:11:57 +08:00
|
|
|
const char* description(void);
|
2012-04-07 12:02:40 +08:00
|
|
|
|
|
|
|
/** sets the dirty value */
|
|
|
|
inline void setDirty(bool bValue) { m_bDirty = bValue; }
|
|
|
|
/** get the dirty value */
|
|
|
|
inline bool getDirty(void) { return m_bDirty; }
|
|
|
|
|
|
|
|
/** sets the camera in the default position */
|
|
|
|
void restore(void);
|
|
|
|
/** Sets the camera using gluLookAt using its eye, center and up_vector */
|
|
|
|
void locate(void);
|
|
|
|
/** sets the eye values in points */
|
|
|
|
void setEyeXYZ(float fEyeX, float fEyeY, float fEyeZ);
|
|
|
|
/** sets the center values in points */
|
|
|
|
void setCenterXYZ(float fCenterX, float fCenterY, float fCenterZ);
|
|
|
|
/** sets the up values */
|
|
|
|
void setUpXYZ(float fUpX, float fUpY, float fUpZ);
|
|
|
|
|
|
|
|
/** get the eye vector values in points */
|
|
|
|
void getEyeXYZ(float *pEyeX, float *pEyeY, float *pEyeZ);
|
|
|
|
/** get the center vector values int points */
|
|
|
|
void getCenterXYZ(float *pCenterX, float *pCenterY, float *pCenterZ);
|
|
|
|
/** get the up vector values */
|
|
|
|
void getUpXYZ(float *pUpX, float *pUpY, float *pUpZ);
|
|
|
|
public:
|
|
|
|
/** returns the Z eye */
|
|
|
|
static float getZEye();
|
|
|
|
|
|
|
|
private:
|
|
|
|
DISALLOW_COPY_AND_ASSIGN(CCCamera);
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
2010-07-06 10:19:51 +08:00
|
|
|
|
|
|
|
#endif // __CCCAMERA_H__
|