CCCamera,CCAtlasNode源码解析
来源:互联网 发布:山脉户外 知乎 编辑:程序博客网 时间:2024/06/06 00:36
源码:
/** * Note: * Scene creates a default camera. And the default camera mask of Node is 1, therefore it can be seen by the default camera. * During rendering the scene, it draws the objects seen by each camera in the added order except default camera. The default camera is the last one being drawn with. * It's usually a good idea to render 3D objects in a separate camera. * And set the 3d camera flag to CameraFlag::USER1 or anything else except DEFAULT. Dedicate The DEFAULT camera for UI, because it is rendered at last. * You can change the camera order to get different result when depth test is not enabled. * For each camera, transparent 3d sprite is rendered after opaque 3d sprite and other 2d objects. */ /// 场景创建了一个默认的摄像机,默认的摄像机遮挡的节点是1个。因此,它可以被默认的摄像机看到。在场景的渲染期间,按加入的顺序,通过每个摄像机绘制每个对象。 /// 默认的摄像机是最后被沪指的。 /// 在绘制3D对象的时候,是用分离摄像机是一个不错的方法 /// enum class CameraFlag/// 摄像机的标识{ DEFAULT = 1, USER1 = 1 << 1, USER2 = 1 << 2, USER3 = 1 << 3, USER4 = 1 << 4, USER5 = 1 << 5, USER6 = 1 << 6, USER7 = 1 << 7, USER8 = 1 << 8,};/*** Defines a camera .*//// 声明一个摄像机class CC_DLL Camera :public Node{ friend class Scene;public: /** * The type of camera. */ enum class Type { PERSPECTIVE = 1, ORTHOGRAPHIC = 2 };public: /** * Creates a perspective camera. * * @param fieldOfView The field of view for the perspective camera (normally in the range of 40-60 degrees). * @param aspectRatio The aspect ratio of the camera (normally the width of the viewport divided by the height of the viewport). * @param nearPlane The near plane distance. * @param farPlane The far plane distance. *//// 创建一个透视摄像机 static Camera* createPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane); /** * Creates an orthographic camera. * * @param zoomX The zoom factor along the X-axis of the orthographic projection (the width of the ortho projection). * @param zoomY The zoom factor along the Y-axis of the orthographic projection (the height of the ortho projection). * @param nearPlane The near plane distance. * @param farPlane The far plane distance. *//// 创建一个正视摄像机 static Camera* createOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane); /** create default camera, the camera type depends on Director::getProjection, the depth of the default camera is 0 *//// 创建一个摄像机 static Camera* create(); /** * Gets the type of camera. * * @return The camera type. *//// 得到摄像机的类型 Camera::Type getType() const { return _type; } /**get & set Camera flag*//// 得到摄像机的标识 CameraFlag getCameraFlag() const { return (CameraFlag)_cameraFlag; }/// 设置摄像机的标识 void setCameraFlag(CameraFlag flag) { _cameraFlag = (unsigned short)flag; } /** * Make Camera looks at target * * @param target The target camera is point at * @param up The up vector, usually it's Y axis *//// 是摄像机观看某个目标 virtual void lookAt(const Vec3& target, const Vec3& up = Vec3::UNIT_Y); /** * Gets the camera's projection matrix. * * @return The camera projection matrix. *//// 得到透视摄像机的矩阵 const Mat4& getProjectionMatrix() const; /** * Gets the camera's view matrix. * * @return The camera view matrix. *//// 得到摄像机视窗的矩阵 const Mat4& getViewMatrix() const; /**get view projection matrix*//// 得到透视摄像机视窗的矩阵 const Mat4& getViewProjectionMatrix() const; /* convert the specified point of viewport from world-space coordinates into the screen-space coordinates. * * @param src The world-space position. * @return The screen-space position. */ /// 将视窗坐标,转换为屏幕坐标 Vec2 project(const Vec3& src) const; /** * Convert the specified point of viewport from screen-space coordinate into the world-space coordinate. * * @param src The screen-space position. * @return The world-space position. */ /// 将屏幕坐标转换为世界坐标 Vec3 unproject(const Vec3& src) const; /** * Convert the specified point of viewport from screen-space coordinate into the world-space coordinate. * * @param viewport The viewport size to use. * @param src The screen-space position. * @param dst The world-space position. */ /// 将屏幕坐标转换为世界坐标 void unproject(const Size& viewport, const Vec3* src, Vec3* dst) const; /** * Is this aabb visible in frustum */ /// aabb在锥形区间中是否可见 bool isVisibleInFrustum(const AABB* aabb) const; /** * Get object depth towards camera */ /// 得到实例在摄像机中的深度 float getDepthInView(const Mat4& transform) const; /** * set depth, camera with larger depth is drawn on top of camera with smaller depth, the depth of camera with CameraFlag::DEFAULT is 0, user defined camera is -1 by default */ /// 设置深度 void setDepth(int depth); /** * get depth, camera with larger depth is drawn on top of camera with smaller depth, the depth of camera with CameraFlag::DEFAULT is 0, user defined camera is -1 by default */ /// 得到深度 int getDepth() const { return _depth; } //override virtual void onEnter() override; virtual void onExit() override; /** * Get the visiting camera , the visiting camera shall be set on Scene::render */ /// 得到当前访问的摄像机 static const Camera* getVisitingCamera() { return _visitingCamera; } /** * Get the default camera of the current running scene. */ /// 得到默认的摄像机 static Camera* getDefaultCamera();CC_CONSTRUCTOR_ACCESS: Camera(); ~Camera(); /** * Set the scene,this method shall not be invoke manually */ /// 设置场景 void setScene(Scene* scene); /**set additional matrix for the projection matrix, it multiplys mat to projection matrix when called, used by WP8*//// 设置额外的投影 void setAdditionalProjection(const Mat4& mat); /** init camera */ /// 初始化摄像机bool initDefault(); bool initPerspective(float fieldOfView, float aspectRatio, float nearPlane, float farPlane); bool initOrthographic(float zoomX, float zoomY, float nearPlane, float farPlane);protected: Scene* _scene; //Scene camera belongs to Mat4 _projection; mutable Mat4 _view; mutable Mat4 _viewInv; mutable Mat4 _viewProjection; Vec3 _up; Camera::Type _type; float _fieldOfView; float _zoom[2]; float _aspectRatio; float _nearPlane; float _farPlane; mutable bool _viewProjectionDirty; unsigned short _cameraFlag; // camera flag mutable Frustum _frustum; // camera frustum mutable bool _frustumDirty; int _depth; //camera depth, the depth of camera with CameraFlag::DEFAULT flag is 0 by default, a camera with larger depth is drawn on top of camera with smaller detph static Camera* _visitingCamera; friend class Director;};
源码:
/** @brief AtlasNode is a subclass of Node that implements the RGBAProtocol and TextureProtocol protocol. * It knows how to render a TextureAtlas object. * If you are going to render a TextureAtlas consider subclassing AtlasNode (or a subclass of AtlasNode). * All features from Node are valid, plus the following features: * - opacity and RGB colors. */ /// AtlasNode是一个实现了RGBAProtocol和TextureProtocol的子类 /// 图集节点class CC_DLL AtlasNode : public Node, public TextureProtocol{ public:/** creates a AtlasNode with an Atlas file the width and height of each item and the quantity of items to render. * * @param filename The path of Atlas file. * @param tileWidth The width of the item. * @param tileHeight The height of the item. * @param itemsToRender The quantity of items to render. */ /// 创建一个图集节点static AtlasNode * create(const std::string& filename, int tileWidth, int tileHeight, int itemsToRender); /** updates the Atlas (indexed vertex array). * Shall be overridden in subclasses. *//// 更新图集节点的值 virtual void updateAtlasValues(); /** Set an buffer manager of the texture vertex. *//// 设置图集节点的纹理 void setTextureAtlas(TextureAtlas* textureAtlas); /** Return the buffer manager of the texture vertex. * * @return Return A TextureAtlas. */ /// 得到图集节点的纹理 TextureAtlas* getTextureAtlas() const; void setQuadsToDraw(ssize_t quadsToDraw); ssize_t getQuadsToDraw() const; // Overrides virtual void draw(Renderer *renderer, const Mat4 &transform, uint32_t flags) override; virtual Texture2D* getTexture() const override; virtual void setTexture(Texture2D *texture) override; virtual bool isOpacityModifyRGB() const override; virtual void setOpacityModifyRGB(bool isOpacityModifyRGB) override; virtual const Color3B& getColor(void) const override; virtual void setColor(const Color3B& color) override; virtual void setOpacity(GLubyte opacity) override; /** * @code * When this function bound into js or lua,the parameter will be changed * In js: var setBlendFunc(var src, var dst) * @endcode * @lua NA *//// 设置混合函数 virtual void setBlendFunc(const BlendFunc& blendFunc) override; /** * @lua NA *//// 得到混合函数 virtual const BlendFunc& getBlendFunc() const override;CC_CONSTRUCTOR_ACCESS: AtlasNode(); virtual ~AtlasNode();/// 初始化 /** Initializes an AtlasNode with an Atlas file the width and height of each item and the quantity of items to render*/ bool initWithTileFile(const std::string& tile, int tileWidth, int tileHeight, int itemsToRender); /** Initializes an AtlasNode with a texture the width and height of each item measured in points and the quantity of items to render*/ bool initWithTexture(Texture2D* texture, int tileWidth, int tileHeight, int itemsToRender);protected: void calculateMaxItems(); void updateBlendFunc(); void updateOpacityModifyRGB(); friend class Director; void setIgnoreContentScaleFactor(bool bIgnoreContentScaleFactor); /** Chars per row. */ int _itemsPerRow; /** Chars per column. */ int _itemsPerColumn; /** Width of each char. */ int _itemWidth; /** Height of each char. */ int _itemHeight; Color3B _colorUnmodified; TextureAtlas* _textureAtlas; /** Protocol variables. */ bool _isOpacityModifyRGB; BlendFunc _blendFunc; /** Quads to draw. */ ssize_t _quadsToDraw; /** Color uniform. */ GLint _uniformColor; /** This varible is only used for LabelAtlas FPS display. So plz don't modify its value. */ bool _ignoreContentScaleFactor; /** Quad command. */ QuadCommand _quadCommand;private: CC_DISALLOW_COPY_AND_ASSIGN(AtlasNode);};
0 0
- CCCamera,CCAtlasNode源码解析
- CCCamera
- Cocos2dx-3.x 中CCCamera相机类详解及源码分析
- CCCamera 摄像机 详解
- cocos2dx之CCCamera
- cocos2dx的CCCamera
- 整体架构CCCamera 摄像机
- COCos2d-X 节点(CCAtlasNode.h)API
- cocos2d-x学习之CCCamera
- cocos2-x 利用CCCamera缩放
- 源码解析
- 源码解析
- iphone-common-codes-ccteam源代码 CCCamera.h
- iphone-common-codes-ccteam源代码 CCCamera.m
- cocos2d-X 节点(CCCamera.h.)API
- Cocos2dx 学习笔记28 使用CCCamera注意事项
- 【JDk源码解析之一】ArrayList源码解析
- 【源码解析】-- ArrayList的源码解析
- Android应用开发之所有动画使用详解
- TTS零基础入门之拒绝界面卡顿--加入线程
- 云 虚主机探索之经验总结
- Java对象、Json、Xml转换工具Jackson使用
- 1.大数据基础(上)_2.大数据的商业应用
- CCCamera,CCAtlasNode源码解析
- HDU 4407 Sum (莫比乌斯反演)
- gdb调试多线程
- php微信开发 (获取用户地理位置)
- python_学习笔记0825
- group by cube 用法
- 泛型
- 【leetcode】Distinct Subsequences
- 在Linux、ubuntu 11下安装无线网卡 、杂牌无线网卡、ndiswrapper的使用