2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2008-2010 Ricardo Quesada
|
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2011 Zynga Inc.
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-01-04 12:36:20 +08:00
|
|
|
https://adxeproject.github.io/
|
2019-11-23 20:27:39 +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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCCAMERA_ACTION_H__
|
|
|
|
#define __CCCAMERA_ACTION_H__
|
|
|
|
|
|
|
|
#include "2d/CCActionInterval.h"
|
|
|
|
#include "math/CCMath.h"
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
class Camera;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup actions
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*@brief Base class for Camera actions.
|
|
|
|
*@ingroup Actions
|
|
|
|
*/
|
|
|
|
class CC_DLL ActionCamera : public ActionInterval
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
* @lua new
|
|
|
|
*/
|
|
|
|
ActionCamera();
|
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~ActionCamera(){};
|
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void startWithTarget(Node* target) override;
|
|
|
|
virtual ActionCamera* reverse() const override;
|
|
|
|
virtual ActionCamera* clone() const override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/* Sets the Eye value of the Camera.
|
|
|
|
*
|
2019-11-23 20:27:39 +08:00
|
|
|
* @param eye The Eye value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setEye(const Vec3& eye);
|
2019-11-23 20:27:39 +08:00
|
|
|
void setEye(float x, float y, float z);
|
2021-12-25 10:04:45 +08:00
|
|
|
/* Returns the Eye value of the Camera.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @return The Eye value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
const Vec3& getEye() const { return _eye; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/* Sets the Center value of the Camera.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param center The Center value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setCenter(const Vec3& center);
|
|
|
|
/* Returns the Center value of the Camera.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @return The Center value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
const Vec3& getCenter() const { return _center; }
|
2021-12-25 10:04:45 +08:00
|
|
|
/* Sets the Up value of the Camera.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param up The Up value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void setUp(const Vec3& up);
|
|
|
|
/* Returns the Up value of the Camera.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @return The Up value of the Camera.
|
|
|
|
* @js NA
|
|
|
|
*/
|
|
|
|
const Vec3& getUp() const { return _up; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void restore();
|
|
|
|
void updateTransform();
|
|
|
|
|
|
|
|
Vec3 _center;
|
|
|
|
Vec3 _eye;
|
|
|
|
Vec3 _up;
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @class OrbitCamera
|
|
|
|
*
|
|
|
|
* @brief OrbitCamera action.
|
|
|
|
* Orbits the camera around the center of the screen using spherical coordinates.
|
|
|
|
* @ingroup Actions
|
|
|
|
*/
|
|
|
|
class CC_DLL OrbitCamera : public ActionCamera
|
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Creates a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param t Duration in seconds.
|
|
|
|
* @param radius The start radius.
|
|
|
|
* @param deltaRadius The delta radius.
|
|
|
|
* @param angleZ The start angle in Z.
|
|
|
|
* @param deltaAngleZ The delta angle in Z.
|
|
|
|
* @param angleX The start angle in X.
|
|
|
|
* @param deltaAngleX The delta angle in X.
|
|
|
|
* @return An OrbitCamera.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
static OrbitCamera*
|
|
|
|
create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
|
|
|
|
|
|
|
|
/** Positions the camera according to spherical coordinates.
|
2019-11-23 20:27:39 +08:00
|
|
|
*
|
|
|
|
* @param r The spherical radius.
|
|
|
|
* @param zenith The spherical zenith.
|
|
|
|
* @param azimuth The spherical azimuth.
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
void sphericalRadius(float* r, float* zenith, float* azimuth);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// Overrides
|
2021-12-25 10:04:45 +08:00
|
|
|
OrbitCamera* clone() const override;
|
|
|
|
virtual void startWithTarget(Node* target) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual void update(float time) override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS :
|
|
|
|
/**
|
|
|
|
* @js ctor
|
|
|
|
*/
|
|
|
|
OrbitCamera();
|
2019-11-23 20:27:39 +08:00
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
|
|
|
virtual ~OrbitCamera();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
/** Initializes a OrbitCamera action with radius, delta-radius, z, deltaZ, x, deltaX. */
|
2021-12-25 10:04:45 +08:00
|
|
|
bool initWithDuration(float t,
|
|
|
|
float radius,
|
|
|
|
float deltaRadius,
|
|
|
|
float angleZ,
|
|
|
|
float deltaAngleZ,
|
|
|
|
float angleX,
|
|
|
|
float deltaAngleX);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
float _radius;
|
|
|
|
float _deltaRadius;
|
|
|
|
float _angleZ;
|
|
|
|
float _deltaAngleZ;
|
|
|
|
float _angleX;
|
|
|
|
float _deltaAngleX;
|
|
|
|
|
|
|
|
float _radZ;
|
|
|
|
float _radDeltaZ;
|
|
|
|
float _radX;
|
|
|
|
float _radDeltaX;
|
|
|
|
};
|
|
|
|
|
|
|
|
// end of actions group
|
|
|
|
/// @}
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif //__CCCAMERA_ACTION_H__
|