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
|
|
|
|
Copyright (C) 2013-2014 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
|
|
|
/**
|
|
|
|
* @addtogroup effects
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
2012-04-18 18:43:45 +08:00
|
|
|
/** Base class for other
|
|
|
|
*/
|
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
|
|
|
/**
|
|
|
|
* @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 */
|
2014-05-15 01:07:09 +08:00
|
|
|
inline const Vec2& getStep(void) const { return _step; }
|
|
|
|
inline void setStep(const Vec2& 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;
|
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;
|
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:
|
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
|
|
|
|
*/
|
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
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Vec3 vertex(const Vec2& 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
|
|
|
|
*/
|
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
|
|
|
|
* @js NA
|
|
|
|
* @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
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** sets a new vertex at a given position
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
void setVertex(const Vec2& pos, const Vec3& 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
|
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
|
|
|
|
*/
|
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
|
|
|
|
* @js NA
|
|
|
|
* @lua NA
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
CC_DEPRECATED_ATTRIBUTE Quad3 tile(const Vec2& 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
|
|
|
|
*/
|
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
|
|
|
|
* @js NA
|
|
|
|
* @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
|
|
|
|
2013-09-13 11:41:20 +08:00
|
|
|
/** sets a new tile
|
|
|
|
* @js NA
|
|
|
|
* @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
|
|
|
|
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__
|