axmol/cocos/2d/CCActionCamera.h

154 lines
4.1 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2008-2010 Ricardo Quesada
Copyright (c) 2010-2012 cocos2d-x.org
Copyright (c) 2011 Zynga Inc.
Copyright (c) 2013-2014 Chukong Technologies Inc.
http://www.cocos2d-x.org
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.
****************************************************************************/
#ifndef __CCCAMERA_ACTION_H__
#define __CCCAMERA_ACTION_H__
#include "CCActionInterval.h"
2013-12-21 08:33:31 +08:00
#include "kazmath/kazmath.h"
2012-04-18 18:43:45 +08:00
NS_CC_BEGIN
2010-08-09 10:58:48 +08:00
class Camera;
2010-08-09 11:03:06 +08:00
2012-06-20 18:09:11 +08:00
/**
* @addtogroup actions
* @{
*/
2012-04-18 18:43:45 +08:00
/**
@brief Base class for Camera actions
2012-06-20 18:09:11 +08:00
@ingroup Actions
2012-04-18 18:43:45 +08:00
*/
class CC_DLL ActionCamera : public ActionInterval //<NSCopying>
2012-04-18 18:43:45 +08:00
{
public:
/**
* @js ctor
*/
ActionCamera()
2013-12-21 08:33:31 +08:00
:_centerX(0)
,_centerY(0)
,_centerZ(0)
,_eyeX(0)
,_eyeY(0)
,_eyeZ(FLT_EPSILON)
,_upX(0)
,_upY(1)
,_upZ(0)
{}
/**
* @js NA
* @lua NA
*/
virtual ~ActionCamera(){}
// Overrides
virtual void startWithTarget(Node *target) override;
virtual ActionCamera * reverse() const override;
virtual ActionCamera *clone() const override;
2012-04-18 18:43:45 +08:00
protected:
2010-08-09 11:03:06 +08:00
2013-12-21 08:33:31 +08:00
void restore();
void setEye(float x, float y, float z);
void setCenter(float x, float y, float z);
void setUp(float x, float y, float z);
void updateTransform();
float _centerX;
float _centerY;
float _centerZ;
float _eyeX;
float _eyeY;
float _eyeZ;
float _upX;
float _upY;
float _upZ;
2012-04-18 18:43:45 +08:00
};
2010-08-09 10:58:48 +08:00
2012-04-18 18:43:45 +08:00
/**
@brief OrbitCamera action
2012-04-18 18:43:45 +08:00
Orbits the camera around the center of the screen using spherical coordinates
2012-06-20 18:09:11 +08:00
@ingroup Actions
2012-04-18 18:43:45 +08:00
*/
class CC_DLL OrbitCamera : public ActionCamera //<NSCopying>
2012-04-18 18:43:45 +08:00
{
public:
/** creates a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */
static OrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
/**
* @js ctor
*/
OrbitCamera()
: _radius(0.0)
, _deltaRadius(0.0)
, _angleZ(0.0)
, _deltaAngleZ(0.0)
, _angleX(0.0)
, _deltaAngleX(0.0)
, _radZ(0.0)
, _radDeltaZ(0.0)
, _radX(0.0)
, _radDeltaX(0.0)
{}
/**
* @js NA
* @lua NA
*/
2013-12-21 08:33:31 +08:00
virtual ~OrbitCamera(){}
/** initializes a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX */
bool initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
/** positions the camera according to spherical coordinates */
void sphericalRadius(float *r, float *zenith, float *azimuth);
// Overrides
OrbitCamera *clone() const override;
virtual void startWithTarget(Node *target) override;
virtual void update(float time) override;
2010-08-09 10:58:48 +08:00
2012-04-18 18:43:45 +08:00
protected:
float _radius;
float _deltaRadius;
float _angleZ;
float _deltaAngleZ;
float _angleX;
float _deltaAngleX;
float _radZ;
float _radDeltaZ;
float _radX;
float _radDeltaX;
2012-04-18 18:43:45 +08:00
};
2012-06-20 18:09:11 +08:00
// end of actions group
/// @}
2012-04-18 18:43:45 +08:00
NS_CC_END
2010-08-09 10:58:48 +08:00
#endif //__CCCAMERA_ACTION_H__