2011-03-19 10:59:01 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
2016-04-08 13:40:36 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2014-01-07 11:25:07 +08:00
|
|
|
|
2011-03-19 10:59:01 +08:00
|
|
|
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__
|
2012-04-25 16:18:04 +08:00
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "2d/CCActionInterval.h"
|
2014-04-26 13:03:25 +08:00
|
|
|
#include "math/CCMath.h"
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
2010-08-09 10:58:48 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Camera;
|
2010-08-09 11:03:06 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/**
|
|
|
|
*@brief Base class for Camera actions.
|
|
|
|
*@ingroup Actions
|
|
|
|
*/
|
2016-10-08 02:47:48 +08:00
|
|
|
class CC_DLL ActionCamera : public ActionInterval
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
2015-03-30 15:47:47 +08:00
|
|
|
* @lua new
|
2013-09-13 16:46:31 +08:00
|
|
|
*/
|
2014-01-14 04:52:07 +08:00
|
|
|
ActionCamera();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-03-28 18:00:25 +08:00
|
|
|
virtual ~ActionCamera(){};
|
2013-07-18 07:56:19 +08:00
|
|
|
|
|
|
|
// Overrides
|
|
|
|
virtual void startWithTarget(Node *target) override;
|
|
|
|
virtual ActionCamera * reverse() const override;
|
2016-04-08 13:40:36 +08:00
|
|
|
virtual ActionCamera *clone() const override;
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Sets the Eye value of the Camera.
|
|
|
|
*
|
|
|
|
* @param eye The Eye value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setEye(const Vec3 &eye);
|
2014-01-14 04:52:07 +08:00
|
|
|
void setEye(float x, float y, float z);
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Returns the Eye value of the Camera.
|
|
|
|
*
|
|
|
|
* @return The Eye value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec3& getEye() const { return _eye; }
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Sets the Center value of the Camera.
|
|
|
|
*
|
|
|
|
* @param center The Center value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setCenter(const Vec3 ¢er);
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Returns the Center value of the Camera.
|
|
|
|
*
|
|
|
|
* @return The Center value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec3& getCenter() const { return _center; }
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Sets the Up value of the Camera.
|
|
|
|
*
|
|
|
|
* @param up The Up value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setUp(const Vec3 &up);
|
2015-03-18 20:05:59 +08:00
|
|
|
/* Returns the Up value of the Camera.
|
|
|
|
*
|
|
|
|
* @return The Up value of the Camera.
|
2015-03-19 18:41:11 +08:00
|
|
|
* @js NA
|
2015-03-18 20:05:59 +08:00
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
const Vec3& getUp() const { return _up; }
|
2014-01-14 04:52:07 +08:00
|
|
|
|
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 updateTransform();
|
|
|
|
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 _center;
|
|
|
|
Vec3 _eye;
|
|
|
|
Vec3 _up;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
2010-08-09 10:58:48 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** @class OrbitCamera
|
|
|
|
*
|
|
|
|
* @brief OrbitCamera action.
|
|
|
|
* Orbits the camera around the center of the screen using spherical coordinates.
|
|
|
|
* @ingroup Actions
|
|
|
|
*/
|
2016-10-08 02:47:48 +08:00
|
|
|
class CC_DLL OrbitCamera : public ActionCamera
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Creates a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX.
|
|
|
|
*
|
|
|
|
* @param t Duration in seconds.
|
|
|
|
* @param radius The start radius.
|
|
|
|
* @param deltaRadius The delta radius.
|
2015-05-21 08:22:59 +08:00
|
|
|
* @param angleZ The start angle in Z.
|
2015-03-18 20:05:59 +08:00
|
|
|
* @param deltaAngleZ The delta angle in Z.
|
2015-05-21 08:22:59 +08:00
|
|
|
* @param angleX The start angle in X.
|
2015-03-18 20:05:59 +08:00
|
|
|
* @param deltaAngleX The delta angle in X.
|
|
|
|
* @return An OrbitCamera.
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
static OrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
|
2014-03-28 17:45:06 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Positions the camera according to spherical coordinates.
|
|
|
|
*
|
|
|
|
* @param r The spherical radius.
|
|
|
|
* @param zenith The spherical zenith.
|
|
|
|
* @param azimuth The spherical azimuth.
|
|
|
|
*/
|
2014-03-28 17:45:06 +08:00
|
|
|
void sphericalRadius(float *r, float *zenith, float *azimuth);
|
|
|
|
|
|
|
|
// Overrides
|
2016-04-08 13:40:36 +08:00
|
|
|
OrbitCamera *clone() const override;
|
2014-03-28 17:45:06 +08:00
|
|
|
virtual void startWithTarget(Node *target) override;
|
|
|
|
virtual void update(float time) override;
|
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
2014-03-28 18:00:25 +08:00
|
|
|
OrbitCamera();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-03-28 18:00:25 +08:00
|
|
|
virtual ~OrbitCamera();
|
2012-06-14 15:13:16 +08:00
|
|
|
|
2015-03-18 20:05:59 +08:00
|
|
|
/** Initializes a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX. */
|
2012-04-19 14:35:52 +08:00
|
|
|
bool initWithDuration(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
|
2010-08-09 10:58:48 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
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
|
2011-03-19 10:59:01 +08:00
|
|
|
|
2014-06-19 19:45:49 +08:00
|
|
|
#endif //__CCCAMERA_ACTION_H__
|