2015-02-11 18:14:22 +08:00
|
|
|
/****************************************************************************
|
2015-03-02 16:05:26 +08:00
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
|
|
|
Copyright (c) 2015 Chukong Technologies Inc.
|
2015-02-11 18:14:22 +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 __CC_PU_PARTICLE_3D_RENDER_H__
|
|
|
|
#define __CC_PU_PARTICLE_3D_RENDER_H__
|
|
|
|
|
|
|
|
#include "base/CCRef.h"
|
|
|
|
#include "math/CCMath.h"
|
2015-03-02 16:05:26 +08:00
|
|
|
#include "extensions/Particle3D/CCParticle3DRender.h"
|
2015-02-11 18:14:22 +08:00
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
// particle render for quad
|
|
|
|
struct PUParticle3D;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
class CC_DLL PURender : public Particle3DRender
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
virtual void prepare(){};
|
|
|
|
virtual void unPrepare(){};
|
|
|
|
virtual void updateRender(PUParticle3D *particle, float deltaTime, bool firstParticle){};
|
|
|
|
|
|
|
|
const std::string& getRenderType(void) const {return _renderType;};
|
|
|
|
void setRenderType(const std::string& observerType) {_renderType = observerType;};
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
virtual PURender* clone() = 0;
|
|
|
|
virtual void copyAttributesTo (PURender *render);
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
bool autoRotate; // Means that the objects to render automatically rotate if the node to which the particle system is attached, rotates.
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::string _renderType;
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
class CC_DLL PUParticle3DEntityRender : public PURender
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-03-15 07:10:08 +08:00
|
|
|
virtual void setDepthTest(bool isDepthTest) override;
|
|
|
|
virtual void setDepthWrite(bool isDepthWrite) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual void copyAttributesTo (PURender *render) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
PUParticle3DEntityRender();
|
|
|
|
virtual ~PUParticle3DEntityRender();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-03-02 17:47:26 +08:00
|
|
|
bool initRender(const std::string &texFile);
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
struct VertexInfo
|
|
|
|
{
|
|
|
|
Vec3 position;
|
|
|
|
Vec2 uv;
|
|
|
|
Vec4 color;
|
|
|
|
};
|
|
|
|
MeshCommand* _meshCommand;
|
|
|
|
Texture2D* _texture;
|
|
|
|
GLProgramState* _glProgramState;
|
|
|
|
IndexBuffer* _indexBuffer; //index buffer
|
|
|
|
VertexBuffer* _vertexBuffer; // vertex buffer
|
|
|
|
|
|
|
|
std::vector<VertexInfo> _vertices;
|
|
|
|
std::vector<unsigned short> _indices;
|
|
|
|
|
|
|
|
std::string _texFile;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CC_DLL PUParticle3DQuadRender : public PUParticle3DEntityRender
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
enum Type
|
|
|
|
{
|
|
|
|
POINT,
|
|
|
|
ORIENTED_COMMON,
|
|
|
|
ORIENTED_SELF,
|
|
|
|
ORIENTED_SHAPE,
|
|
|
|
PERPENDICULAR_COMMON,
|
|
|
|
PERPENDICULAR_SELF,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Origin
|
|
|
|
{
|
|
|
|
TOP_LEFT,
|
|
|
|
TOP_CENTER,
|
|
|
|
TOP_RIGHT,
|
|
|
|
CENTER_LEFT,
|
|
|
|
CENTER,
|
|
|
|
CENTER_RIGHT,
|
|
|
|
BOTTOM_LEFT,
|
|
|
|
BOTTOM_CENTER,
|
|
|
|
BOTTOM_RIGHT
|
|
|
|
};
|
|
|
|
|
|
|
|
enum RotateType
|
|
|
|
{
|
|
|
|
TEXTURE_COORDS,
|
|
|
|
VERTEX
|
|
|
|
};
|
|
|
|
|
|
|
|
static PUParticle3DQuadRender* create(const std::string& texFile = "");
|
|
|
|
|
|
|
|
void setType(Type type);
|
|
|
|
Type getType() const { return _type; }
|
|
|
|
void setOrigin(Origin origin) { _origin = origin; }
|
|
|
|
Origin getOrigin() const { return _origin; }
|
|
|
|
void setRotateType(RotateType type) { _rotateType = type; }
|
|
|
|
RotateType getRotateType() const { return _rotateType; }
|
|
|
|
void setCommonDirection(const Vec3 &dir) { _commonDir = dir; }
|
|
|
|
const Vec3& getCommonDirection() const { return _commonDir; }
|
|
|
|
void setCommonUp(const Vec3 &up) { _commonUp = up; }
|
|
|
|
const Vec3& getCommonUp() const { return _commonUp; }
|
|
|
|
|
|
|
|
unsigned short getTextureCoordsRows() const;
|
|
|
|
void setTextureCoordsRows(unsigned short textureCoordsRows);
|
|
|
|
unsigned short getTextureCoordsColumns() const;
|
|
|
|
void setTextureCoordsColumns(unsigned short textureCoordsColumns);
|
|
|
|
unsigned int getNumTextureCoords();
|
|
|
|
|
|
|
|
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual PUParticle3DQuadRender* clone() override;
|
|
|
|
virtual void copyAttributesTo (PURender *render) override;
|
2015-02-11 18:14:22 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
PUParticle3DQuadRender();
|
|
|
|
virtual ~PUParticle3DQuadRender();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void getOriginOffset(int &offsetX, int &offsetY);
|
|
|
|
void determineUVCoords(PUParticle3D *particle);
|
2015-03-03 11:52:55 +08:00
|
|
|
void fillVertex(unsigned short index, const Vec3 &pos, const Vec4 &color, const Vec2 &uv);
|
2015-02-11 18:14:22 +08:00
|
|
|
void fillTriangle(unsigned short index, unsigned short v0, unsigned short v1, unsigned short v2);
|
|
|
|
|
|
|
|
protected:
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
Type _type;
|
|
|
|
Origin _origin;
|
|
|
|
RotateType _rotateType;
|
|
|
|
Vec3 _commonDir;
|
|
|
|
Vec3 _commonUp;
|
|
|
|
|
|
|
|
unsigned short _textureCoordsRows;
|
|
|
|
unsigned short _textureCoordsColumns;
|
|
|
|
float _textureCoordsRowStep;
|
|
|
|
float _textureCoordsColStep;
|
|
|
|
};
|
|
|
|
|
|
|
|
// particle render for Sprite3D
|
2015-03-05 13:24:06 +08:00
|
|
|
class CC_DLL PUParticle3DModelRender : public PURender
|
2015-02-11 18:14:22 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
static PUParticle3DModelRender* create(const std::string& modelFile, const std::string &texFile = "");
|
|
|
|
|
|
|
|
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual PUParticle3DModelRender* clone() override;
|
|
|
|
virtual void copyAttributesTo (PURender *render) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
2015-02-11 18:14:22 +08:00
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
PUParticle3DModelRender();
|
|
|
|
virtual ~PUParticle3DModelRender();
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
std::vector<Sprite3D *> _spriteList;
|
|
|
|
std::string _modelFile;
|
|
|
|
std::string _texFile;
|
|
|
|
Vec3 _spriteSize;
|
|
|
|
};
|
|
|
|
|
|
|
|
class CC_DLL PUParticle3DBoxRender : public PUParticle3DEntityRender
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
static PUParticle3DBoxRender* create(const std::string &texFile = "");
|
|
|
|
|
|
|
|
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual PUParticle3DBoxRender* clone() override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
|
|
|
PUParticle3DBoxRender();
|
|
|
|
virtual ~PUParticle3DBoxRender();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void reBuildIndices(unsigned short count);
|
|
|
|
};
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
class CC_DLL PUSphereRender : public PUParticle3DEntityRender
|
2015-03-02 13:07:32 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
2015-03-05 13:24:06 +08:00
|
|
|
static PUSphereRender* create(const std::string &texFile = "");
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
virtual void render(Renderer* renderer, const Mat4 &transform, ParticleSystem3D* particleSystem) override;
|
|
|
|
|
2015-03-15 02:33:15 +08:00
|
|
|
virtual PUSphereRender* clone() override;
|
|
|
|
virtual void copyAttributesTo (PURender *render) override;
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
CC_CONSTRUCTOR_ACCESS:
|
2015-03-05 13:24:06 +08:00
|
|
|
PUSphereRender();
|
|
|
|
virtual ~PUSphereRender();
|
2015-03-02 13:07:32 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
void buildBuffers(unsigned short count);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
|
|
|
unsigned short _numberOfRings;
|
|
|
|
unsigned short _numberOfSegments;
|
|
|
|
std::vector<VertexInfo> _vertexTemplate;
|
2015-02-11 18:14:22 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
#endif
|