ActionCamera,OrbitCamera源码解析

本文深入解析了Unity中CCActionCamera和OrbitCamera两个类的源码,详细探讨了它们在游戏场景中的应用和实现原理,帮助读者理解如何在项目中使用这些相机动作。
摘要由CSDN通过智能技术生成

CCActionCamera中的两个类:

首先看ActionCamera


代码:

/**
 *@brief Base class for Camera actions.
 *@ingroup Actions
 */
 /// 摄像机动作的基类
class CC_DLL ActionCamera : public ActionInterval //<NSCopying> 
{
public:
    /**
     * @js ctor
     * @lua new
     */
    ActionCamera();
    /**
     * @js NA
     * @lua NA
     */
    virtual ~ActionCamera(){};

    // Overrides
	/// 这些是从Action中继承过来的
    virtual void startWithTarget(Node *target) override;
    virtual ActionCamera * reverse() const override;
	virtual ActionCamera *clone() const override;

    /* Sets the Eye value of the Camera. 
     * 
     * @param eye The Eye value of the Camera.
     * @js NA
     */
	 /// 设置摄像机的观察点
    void setEye(const Vec3 &eye);
    void setEye(float x, float y, float z);
    /* Returns the Eye value of the Camera. 
     *
     * @return The Eye value of the Camera.
     * @js NA
     */
	 /// 返回摄像机的观察点
    const Vec3& getEye() const { return _eye; }
    /* Sets the Center value of the Camera. 
     *
     * @param center The Center value of the Camera.
     * @js NA
     */
	 /// 设置摄像机的中心点
    void setCenter(const Vec3 ¢er);
    /* Returns the Center value of the Camera. 
     *
     * @return The Center value of the Camera.
     * @js NA
     */
	 /// 返回摄像机的中心点
    const Vec3& getCenter() const { return _center; }
    /* Sets the Up value of the Camera. 
     *
     * @param up The Up value of the Camera.
     * @js NA
     */
	 /// 设置摄像机的上升值
    void setUp(const Vec3 &up);
    /* Returns the Up value of the Camera. 
     *
     * @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;
};

OrbitCamera:


代码:

/** @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 //<NSCopying> 
{
public:
    /** 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.
     * @param angleZ The start Angel in Z.
     * @param deltaAngleZ The delta angle in Z.
     * @param angleX The start Angel in X.
     * @param deltaAngleX The delta angle in X.
     * @return An OrbitCamera.
     */
	 /// 创建一个轨道摄像机动作
	 /// t:动作的执行时间
	 /// radius:起始半径
	 /// deltaRadius:半径增量
	 /// angleZ:起始Z轴角度
	 /// detaAngleZ: Z轴角度的增量
	 /// angleX:起始X轴角度
	 /// deltaAngleX:X轴角度的增量
    static OrbitCamera* create(float t, float radius, float deltaRadius, float angleZ, float deltaAngleZ, float angleX, float deltaAngleX);
    
    /** Positions the camera according to spherical coordinates. 
     *
     * @param r The spherical radius.
     * @param zenith The spherical zenith.
     * @param azimuth The spherical azimuth.
     */
	 /// 根据球面坐标,给摄像机定位
    void sphericalRadius(float *r, float *zenith, float *azimuth);

    // Overrides
	/// 继承自Action的方法
	OrbitCamera *clone() const override;
    virtual void startWithTarget(Node *target) override;
    virtual void update(float time) override;
    
CC_CONSTRUCTOR_ACCESS:
    /**
     * @js ctor
     */
    OrbitCamera();
    /**
     * @js NA
     * @lua NA
     */
    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);

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
/// @}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值