2010-08-16 16:46:45 +08:00
|
|
|
/****************************************************************************
|
2011-03-19 10:34:26 +08:00
|
|
|
Copyright (c) 2009 On-Core
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2016-08-05 09:42:15 +08:00
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
2011-03-19 10:34:26 +08:00
|
|
|
|
2010-08-16 16:46:45 +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 __EFFECTS_CCGRID_H__
|
|
|
|
#define __EFFECTS_CCGRID_H__
|
|
|
|
|
2014-04-27 01:11:22 +08:00
|
|
|
#include "base/CCRef.h"
|
2014-04-30 08:37:36 +08:00
|
|
|
#include "base/ccTypes.h"
|
|
|
|
#include "base/CCDirector.h"
|
2010-08-16 16:46:45 +08:00
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
class Texture2D;
|
|
|
|
class Grabber;
|
|
|
|
class GLProgram;
|
2014-08-27 13:39:50 +08:00
|
|
|
class Node;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
2015-03-27 15:25:44 +08:00
|
|
|
* @addtogroup _2d
|
2012-06-20 18:09:11 +08:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Base class for Other grid.
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2014-02-20 10:53:49 +08:00
|
|
|
class CC_DLL GridBase : public Ref
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 07:56:19 +08:00
|
|
|
/** create one Grid */
|
|
|
|
static GridBase* create(const Size& gridSize, Texture2D *texture, bool flipped);
|
|
|
|
/** create one Grid */
|
|
|
|
static GridBase* create(const Size& gridSize);
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
2015-03-24 21:34:20 +08:00
|
|
|
Destructor.
|
2013-09-13 13:52:42 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~GridBase(void);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@{
|
|
|
|
Init the Grid base.
|
|
|
|
@param gridSize the size of the grid.
|
|
|
|
@param texture The texture used for grab.
|
|
|
|
@param flipped whether or not the grab texture should be flip by Y or not.
|
2015-09-09 11:37:41 +08:00
|
|
|
@param rect The effective grid rect.
|
2015-03-24 21:34:20 +08:00
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
bool initWithSize(const Size& gridSize);
|
2015-07-08 17:26:29 +08:00
|
|
|
bool initWithSize(const Size& gridSize, const Rect& rect);
|
|
|
|
bool initWithSize(const Size& gridSize, Texture2D *texture, bool flipped);
|
|
|
|
bool initWithSize(const Size& gridSize, Texture2D *texture, bool flipped, const Rect& rect);
|
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
|
|
|
/** @{
|
|
|
|
Getter and setter of the active state of the grid.
|
|
|
|
*/
|
2013-11-07 09:05:13 +08:00
|
|
|
inline bool isActive(void) const { return _active; }
|
2013-12-18 17:47:20 +08:00
|
|
|
void setActive(bool active);
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Get number of times that the grid will be reused. */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline int getReuseGrid(void) const { return _reuseGrid; }
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Set number of times that the grid will be reused. */
|
2013-12-18 17:47:20 +08:00
|
|
|
inline void setReuseGrid(int reuseGrid) { _reuseGrid = reuseGrid; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Size of the grid. */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline const Size& getGridSize(void) const { return _gridSize; }
|
2015-03-24 21:34:20 +08:00
|
|
|
/**Set the size of the grid.*/
|
2013-06-20 14:13:12 +08:00
|
|
|
inline void setGridSize(const Size& gridSize) { _gridSize = gridSize; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Pixels between the grids. */
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Vec2& getStep(void) const { return _step; }
|
2015-03-24 21:34:20 +08:00
|
|
|
/**Get the pixels between the grids.*/
|
2014-05-15 01:07:09 +08:00
|
|
|
inline void setStep(const Vec2& step) { _step = step; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** is texture flipped. */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline bool isTextureFlipped(void) const { return _isTextureFlipped; }
|
2015-03-24 21:34:20 +08:00
|
|
|
/**Set the texture flipped or not.*/
|
2013-12-18 17:47:20 +08:00
|
|
|
void setTextureFlipped(bool flipped);
|
2015-03-24 21:34:20 +08:00
|
|
|
|
|
|
|
/**@{
|
|
|
|
Init and reset the status when render effects by using the grid.
|
|
|
|
*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void beforeDraw(void);
|
2013-07-18 07:56:19 +08:00
|
|
|
void afterDraw(Node *target);
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**@{
|
|
|
|
Interface for custom action when before or after draw.
|
2015-03-28 14:28:16 +08:00
|
|
|
@js NA
|
2015-03-24 21:34:20 +08:00
|
|
|
*/
|
2014-09-17 18:33:18 +08:00
|
|
|
virtual void beforeBlit() {}
|
|
|
|
virtual void afterBlit() {}
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
|
|
|
|
|
|
|
/**Interface used to blit the texture with grid to screen.*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void blit(void);
|
2015-03-24 21:34:20 +08:00
|
|
|
/**Interface, Reuse the grid vertices.*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void reuse(void);
|
2015-03-24 21:34:20 +08:00
|
|
|
/**Interface, Calculate the vertices used for the blit.*/
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void calculateVertexPoints(void);
|
2015-03-24 21:34:20 +08:00
|
|
|
|
|
|
|
/**Change projection to 2D for grabbing.*/
|
2012-04-19 14:35:52 +08:00
|
|
|
void set2DProjection(void);
|
2015-07-08 15:57:27 +08:00
|
|
|
|
2015-07-08 22:34:33 +08:00
|
|
|
/**
|
|
|
|
* @brief Set the effect grid rect.
|
|
|
|
* @param rect The effect grid rect.
|
|
|
|
*/
|
2015-07-08 15:57:27 +08:00
|
|
|
void setGridRect(const Rect& rect);
|
2015-07-08 22:34:33 +08:00
|
|
|
/**
|
|
|
|
* @brief Get the effect grid rect.
|
|
|
|
* @return Return the effect grid rect.
|
|
|
|
*/
|
2015-07-08 15:57:27 +08:00
|
|
|
inline const Rect& getGridRect() const {return _gridRect;}
|
2012-04-18 18:43:45 +08:00
|
|
|
|
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _active;
|
2013-12-05 17:19:01 +08:00
|
|
|
int _reuseGrid;
|
2013-06-20 14:13:12 +08:00
|
|
|
Size _gridSize;
|
|
|
|
Texture2D *_texture;
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec2 _step;
|
2013-06-20 14:13:12 +08:00
|
|
|
Grabber *_grabber;
|
2013-06-15 14:03:30 +08:00
|
|
|
bool _isTextureFlipped;
|
2013-06-20 14:13:12 +08:00
|
|
|
GLProgram* _shaderProgram;
|
2013-07-25 14:39:32 +08:00
|
|
|
Director::Projection _directorProjection;
|
2015-07-08 15:57:27 +08:00
|
|
|
Rect _gridRect;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
Grid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z
|
2012-04-18 18:43:45 +08:00
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL Grid3D : public GridBase
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2015-07-08 17:26:29 +08:00
|
|
|
/** create one Grid. */
|
|
|
|
static Grid3D* create(const Size& gridSize);
|
2015-09-09 11:37:41 +08:00
|
|
|
/** create one Grid. */
|
2015-07-08 17:26:29 +08:00
|
|
|
static Grid3D* create(const Size& gridSize, const Rect& rect);
|
2015-03-24 21:34:20 +08:00
|
|
|
/** create one Grid. */
|
2013-12-18 17:47:20 +08:00
|
|
|
static Grid3D* create(const Size& gridSize, Texture2D *texture, bool flipped);
|
2015-03-24 21:34:20 +08:00
|
|
|
/** create one Grid. */
|
2015-07-08 17:26:29 +08:00
|
|
|
static Grid3D* create(const Size& gridSize, Texture2D *texture, bool flipped, const Rect& rect);
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
2015-03-24 21:34:20 +08:00
|
|
|
Constructor.
|
2013-09-13 16:46:31 +08:00
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
Grid3D();
|
2013-09-13 11:41:20 +08:00
|
|
|
/**
|
2015-03-24 21:34:20 +08:00
|
|
|
Destructor.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
~Grid3D(void);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Returns the vertex at a given position.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 getVertex(const Vec2& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** @deprecated Use getVertex() instead
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Vec3 vertex(const Vec2& pos) const { return getVertex(pos); }
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Returns the original (non-transformed) vertex at a given position.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Vec3 getOriginalVertex(const Vec2& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** @deprecated Use getOriginalVertex() instead
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Vec3 originalVertex(const Vec2& pos) const { return getOriginalVertex(pos); }
|
2013-07-07 21:08:14 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Sets a new vertex at a given position.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setVertex(const Vec2& pos, const Vec3& vertex);
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@{
|
2015-09-09 11:37:41 +08:00
|
|
|
Implementations for interfaces in base class.
|
2015-03-24 21:34:20 +08:00
|
|
|
*/
|
2014-09-17 18:33:18 +08:00
|
|
|
virtual void beforeBlit() override;
|
|
|
|
virtual void afterBlit() override;
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void blit() override;
|
|
|
|
virtual void reuse() override;
|
|
|
|
virtual void calculateVertexPoints() override;
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
2014-09-17 18:33:18 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@{
|
|
|
|
Getter and Setter for depth test state when blit.
|
2015-03-28 14:28:16 +08:00
|
|
|
@js NA
|
2015-03-24 21:34:20 +08:00
|
|
|
*/
|
2014-09-17 18:33:18 +08:00
|
|
|
void setNeedDepthTestForBlit( bool neededDepthTest) { _needDepthTestForBlit = neededDepthTest; }
|
|
|
|
bool getNeedDepthTestForBlit() const { return _needDepthTestForBlit; }
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
2012-04-18 18:43:45 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
GLvoid *_texCoordinates;
|
|
|
|
GLvoid *_vertices;
|
|
|
|
GLvoid *_originalVertices;
|
|
|
|
GLushort *_indices;
|
2014-09-17 18:33:18 +08:00
|
|
|
bool _needDepthTestForBlit;
|
|
|
|
bool _oldDepthTestValue;
|
2015-01-16 08:41:07 +08:00
|
|
|
bool _oldDepthWriteValue;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2013-06-20 14:13:12 +08:00
|
|
|
TiledGrid3D is a 3D grid implementation. It differs from Grid3D in that
|
2012-04-18 18:43:45 +08:00
|
|
|
the tiles can be separated from the grid.
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL TiledGrid3D : public GridBase
|
2010-08-16 16:46:45 +08:00
|
|
|
{
|
2012-04-18 18:43:45 +08:00
|
|
|
public:
|
2015-07-08 17:47:04 +08:00
|
|
|
/** Create one Grid. */
|
|
|
|
static TiledGrid3D* create(const Size& gridSize);
|
|
|
|
/** Create one Grid. */
|
|
|
|
static TiledGrid3D* create(const Size& gridSize, const Rect& rect);
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Create one Grid. */
|
2013-12-18 17:47:20 +08:00
|
|
|
static TiledGrid3D* create(const Size& gridSize, Texture2D *texture, bool flipped);
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Create one Grid. */
|
2015-07-08 17:47:04 +08:00
|
|
|
static TiledGrid3D* create(const Size& gridSize, Texture2D *texture, bool flipped, const Rect& rect);
|
2013-09-13 16:46:31 +08:00
|
|
|
/**
|
2015-03-24 21:34:20 +08:00
|
|
|
Constructor.
|
2013-09-13 16:46:31 +08:00
|
|
|
* @js ctor
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
TiledGrid3D();
|
2013-09-13 13:52:42 +08:00
|
|
|
/**
|
2015-03-24 21:34:20 +08:00
|
|
|
Destructor.
|
2013-09-13 13:52:42 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
~TiledGrid3D();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Returns the tile at the given position.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 getTile(const Vec2& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the tile at the given position
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Quad3 tile(const Vec2& pos) const { return getTile(pos); }
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Returns the original tile (untransformed) at the given position.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
Quad3 getOriginalTile(const Vec2& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the original tile (untransformed) at the given position
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Quad3 originalTile(const Vec2& pos) const { return getOriginalTile(pos); }
|
2013-07-18 07:56:19 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/** Sets a new tile.
|
2013-09-13 11:41:20 +08:00
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setTile(const Vec2& pos, const Quad3& coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@{
|
2015-09-09 11:37:41 +08:00
|
|
|
Implementations for interfaces in base class.
|
2015-03-24 21:34:20 +08:00
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
virtual void blit() override;
|
|
|
|
virtual void reuse() override;
|
|
|
|
virtual void calculateVertexPoints() override;
|
2015-03-24 21:34:20 +08:00
|
|
|
/**@}*/
|
2012-04-18 18:43:45 +08:00
|
|
|
protected:
|
2013-06-15 14:03:30 +08:00
|
|
|
GLvoid *_texCoordinates;
|
|
|
|
GLvoid *_vertices;
|
|
|
|
GLvoid *_originalVertices;
|
|
|
|
GLushort *_indices;
|
2012-04-18 18:43:45 +08:00
|
|
|
};
|
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
// end of effects group
|
|
|
|
/// @}
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
NS_CC_END
|
2010-08-16 16:46:45 +08:00
|
|
|
|
|
|
|
#endif // __EFFECTS_CCGRID_H__
|