2010-08-16 16:46:45 +08:00
|
|
|
/****************************************************************************
|
2012-09-24 21:22:20 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2011-03-19 10:34:26 +08:00
|
|
|
Copyright (c) 2009 On-Core
|
|
|
|
|
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__
|
|
|
|
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCObject.h"
|
|
|
|
#include "CCNode.h"
|
2010-08-16 16:46:45 +08:00
|
|
|
#include "ccTypes.h"
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCTexture2D.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
#include "CCDirector.h"
|
2012-03-14 14:55:17 +08:00
|
|
|
#include "kazmath/mat4.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-10-14 14:01:00 +08:00
|
|
|
#include "CCGLBufferedNode.h"
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
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;
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-06-20 18:09:11 +08:00
|
|
|
/**
|
|
|
|
* @addtogroup effects
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
/** Base class for other
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
class CC_DLL GridBase : public Object
|
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
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
virtual ~GridBase(void);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-12-18 17:47:20 +08:00
|
|
|
bool initWithSize(const Size& gridSize, Texture2D *texture, bool flipped);
|
2013-07-18 07:56:19 +08:00
|
|
|
bool initWithSize(const Size& gridSize);
|
|
|
|
|
2012-09-17 15:02:24 +08:00
|
|
|
/** whether or not the grid is active */
|
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);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** number of times that the grid will be reused */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline int getReuseGrid(void) const { return _reuseGrid; }
|
2013-12-18 17:47:20 +08:00
|
|
|
inline void setReuseGrid(int reuseGrid) { _reuseGrid = reuseGrid; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** size of the grid */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline const Size& getGridSize(void) const { return _gridSize; }
|
2013-06-20 14:13:12 +08:00
|
|
|
inline void setGridSize(const Size& gridSize) { _gridSize = gridSize; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** pixels between the grids */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline const Point& getStep(void) const { return _step; }
|
2013-06-20 14:13:12 +08:00
|
|
|
inline void setStep(const Point& step) { _step = step; }
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
/** is texture flipped */
|
2013-11-07 09:05:13 +08:00
|
|
|
inline bool isTextureFlipped(void) const { return _isTextureFlipped; }
|
2013-12-18 17:47:20 +08:00
|
|
|
void setTextureFlipped(bool flipped);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void beforeDraw(void);
|
2013-07-18 07:56:19 +08:00
|
|
|
void afterDraw(Node *target);
|
2012-04-19 14:35:52 +08:00
|
|
|
virtual void blit(void);
|
|
|
|
virtual void reuse(void);
|
|
|
|
virtual void calculateVertexPoints(void);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
void set2DProjection(void);
|
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;
|
|
|
|
Point _step;
|
|
|
|
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;
|
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
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-06-20 14:13:12 +08:00
|
|
|
, public GLBufferedNode
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2012-04-18 18:43:45 +08:00
|
|
|
{
|
|
|
|
public:
|
2013-07-18 07:56:19 +08:00
|
|
|
/** create one Grid */
|
2013-12-18 17:47:20 +08:00
|
|
|
static Grid3D* create(const Size& gridSize, Texture2D *texture, bool flipped);
|
2013-07-18 07:56:19 +08:00
|
|
|
/** create one Grid */
|
|
|
|
static Grid3D* create(const Size& gridSize);
|
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
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-06-20 14:13:12 +08:00
|
|
|
~Grid3D(void);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the vertex at a given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
Vertex3F getVertex(const Point& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** @deprecated Use getVertex() instead
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Vertex3F vertex(const Point& pos) const { return getVertex(pos); }
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the original (non-transformed) vertex at a given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
Vertex3F getOriginalVertex(const Point& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** @deprecated Use getOriginalVertex() instead
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Vertex3F originalVertex(const Point& pos) const { return getOriginalVertex(pos); }
|
2013-07-07 21:08:14 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** sets a new vertex at a given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
void setVertex(const Point& pos, const Vertex3F& vertex);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void blit() override;
|
|
|
|
virtual void reuse() override;
|
|
|
|
virtual void calculateVertexPoints() override;
|
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
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
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
|
2013-04-13 05:51:29 +08:00
|
|
|
#ifdef EMSCRIPTEN
|
2013-06-20 14:13:12 +08:00
|
|
|
, public GLBufferedNode
|
2013-04-13 05:51:29 +08:00
|
|
|
#endif // EMSCRIPTEN
|
2010-08-16 16:46:45 +08:00
|
|
|
{
|
2012-04-18 18:43:45 +08:00
|
|
|
public:
|
2013-07-18 07:56:19 +08:00
|
|
|
/** create one Grid */
|
2013-12-18 17:47:20 +08:00
|
|
|
static TiledGrid3D* create(const Size& gridSize, Texture2D *texture, bool flipped);
|
2013-07-18 07:56:19 +08:00
|
|
|
/** create one Grid */
|
|
|
|
static TiledGrid3D* create(const Size& gridSize);
|
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
|
|
|
/**
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
~TiledGrid3D();
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the tile at the given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
Quad3 getTile(const Point& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the tile at the given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Quad3 tile(const Point& pos) const { return getTile(pos); }
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the original tile (untransformed) at the given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
Quad3 getOriginalTile(const Point& pos) const;
|
2013-09-13 11:41:20 +08:00
|
|
|
/** returns the original tile (untransformed) at the given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-18 07:56:19 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Quad3 originalTile(const Point& pos) const { return getOriginalTile(pos); }
|
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** sets a new tile
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2013-07-05 16:49:22 +08:00
|
|
|
void setTile(const Point& pos, const Quad3& coords);
|
2012-04-18 18:43:45 +08:00
|
|
|
|
2013-07-18 07:56:19 +08:00
|
|
|
// Overrides
|
|
|
|
virtual void blit() override;
|
|
|
|
virtual void reuse() override;
|
|
|
|
virtual void calculateVertexPoints() override;
|
2012-12-06 18:51:33 +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__
|