axmol/cocos2dx/effects/CCGrid.h

187 lines
5.3 KiB
C
Raw Normal View History

2010-08-16 16:46:45 +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__
#include "cocoa/CCObject.h"
#include "base_nodes/CCNode.h"
2010-08-16 16:46:45 +08:00
#include "CCCamera.h"
#include "ccTypes.h"
#include "textures/CCTexture2D.h"
#include "CCDirector.h"
#include "kazmath/mat4.h"
#ifdef EMSCRIPTEN
#include "base_nodes/CCGLBufferedNode.h"
#endif // EMSCRIPTEN
2010-08-16 16:46:45 +08:00
2012-04-18 18:43:45 +08:00
NS_CC_BEGIN
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
*/
class CC_DLL GridBase : public Object
2012-04-18 18:43:45 +08:00
{
public:
virtual ~GridBase(void);
2012-04-18 18:43:45 +08:00
/** whether or not the grid is active */
inline bool isActive(void) { return _active; }
void setActive(bool bActive);
2012-04-18 18:43:45 +08:00
/** number of times that the grid will be reused */
inline int getReuseGrid(void) { return _reuseGrid; }
inline void setReuseGrid(int nReuseGrid) { _reuseGrid = nReuseGrid; }
2012-04-18 18:43:45 +08:00
/** size of the grid */
inline const Size& getGridSize(void) { return _gridSize; }
inline void setGridSize(const Size& gridSize) { _gridSize = gridSize; }
2012-04-18 18:43:45 +08:00
/** pixels between the grids */
inline const Point& getStep(void) { return _step; }
inline void setStep(const Point& step) { _step = step; }
2012-04-18 18:43:45 +08:00
/** is texture flipped */
inline bool isTextureFlipped(void) { return _isTextureFlipped; }
void setTextureFlipped(bool bFlipped);
2012-04-18 18:43:45 +08:00
bool initWithSize(const Size& gridSize, Texture2D *pTexture, bool bFlipped);
bool initWithSize(const Size& gridSize);
2012-04-18 18:43:45 +08:00
void beforeDraw(void);
void afterDraw(Node *pTarget);
virtual void blit(void);
virtual void reuse(void);
virtual void calculateVertexPoints(void);
2012-04-18 18:43:45 +08:00
public:
/** create one Grid */
static GridBase* create(const Size& gridSize, Texture2D *texture, bool flipped);
/** create one Grid */
static GridBase* create(const Size& gridSize);
void set2DProjection(void);
2012-04-18 18:43:45 +08:00
protected:
bool _active;
int _reuseGrid;
Size _gridSize;
Texture2D *_texture;
Point _step;
Grabber *_grabber;
bool _isTextureFlipped;
GLProgram* _shaderProgram;
ccDirectorProjection _directorProjection;
2012-04-18 18:43:45 +08:00
};
/**
Grid3D is a 3D grid implementation. Each vertex has 3 dimensions: x,y,z
2012-04-18 18:43:45 +08:00
*/
class CC_DLL Grid3D : public GridBase
#ifdef EMSCRIPTEN
, public GLBufferedNode
#endif // EMSCRIPTEN
2012-04-18 18:43:45 +08:00
{
public:
Grid3D();
~Grid3D(void);
2012-04-18 18:43:45 +08:00
/** returns the vertex at a given position */
ccVertex3F vertex(const Point& pos);
/** returns the original (non-transformed) vertex at a given position */
ccVertex3F originalVertex(const Point& pos);
/** sets a new vertex at a given position */
void setVertex(const Point& pos, const ccVertex3F& vertex);
2012-04-18 18:43:45 +08:00
virtual void blit(void);
virtual void reuse(void);
virtual void calculateVertexPoints(void);
2012-04-18 18:43:45 +08:00
public:
/** create one Grid */
static Grid3D* create(const Size& gridSize, Texture2D *pTexture, bool bFlipped);
/** create one Grid */
static Grid3D* create(const Size& gridSize);
2012-04-18 18:43:45 +08:00
protected:
GLvoid *_texCoordinates;
GLvoid *_vertices;
GLvoid *_originalVertices;
GLushort *_indices;
2012-04-18 18:43:45 +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.
*/
class CC_DLL TiledGrid3D : public GridBase
#ifdef EMSCRIPTEN
, public GLBufferedNode
#endif // EMSCRIPTEN
2010-08-16 16:46:45 +08:00
{
2012-04-18 18:43:45 +08:00
public:
TiledGrid3D();
~TiledGrid3D(void);
2012-04-18 18:43:45 +08:00
/** returns the tile at the given position */
ccQuad3 tile(const Point& pos);
/** returns the original tile (untransformed) at the given position */
ccQuad3 originalTile(const Point& pos);
/** sets a new tile */
void setTile(const Point& pos, const ccQuad3& coords);
2012-04-18 18:43:45 +08:00
virtual void blit(void);
virtual void reuse(void);
virtual void calculateVertexPoints(void);
2012-04-18 18:43:45 +08:00
public:
/** create one Grid */
static TiledGrid3D* create(const Size& gridSize, Texture2D *pTexture, bool bFlipped);
/** create one Grid */
static TiledGrid3D* create(const Size& gridSize);
2012-04-18 18:43:45 +08:00
protected:
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__