| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- /*
- Copyright (C) 2011 by Ivan Safrin
-
- 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.
- */
- #include "PolyParticle.h"
- #include "PolyMesh.h"
- #include "PolyPolygon.h"
- #include "PolySceneMesh.h"
- using namespace Polycode;
- Mesh *Particle::billboardMesh = 0;
- Particle::Particle(int particleType, bool isScreenParticle, Material *material, Texture *texture, Mesh *particleMesh) {
- life = 0;
- createSceneParticle(particleType, material, particleMesh);
-
- Reset(true);
- }
- void Particle::createSceneParticle(int particleType, Material *material, Mesh *particleMesh) {
- switch(particleType) {
- case BILLBOARD_PARTICLE:
- {
- if(!billboardMesh) {
- billboardMesh = new Mesh(Mesh::QUAD_MESH);
-
- Polygon *imagePolygon = new Polygon();
- imagePolygon->addVertex(0,1,0,0,0);
- imagePolygon->addVertex(1,1,0, 1, 0);
- imagePolygon->addVertex(1,0,0, 1, 1);
- imagePolygon->addVertex(0,0,0,0,1);
- billboardMesh->addPolygon(imagePolygon);
-
- for(int i=0; i < billboardMesh->getPolygonCount(); i++) {
- for(int j=0; j < billboardMesh->getPolygon(i)->getVertexCount(); j++) {
- billboardMesh->getPolygon(i)->getVertex(j)->x = billboardMesh->getPolygon(i)->getVertex(j)->x - (1.0/2.0f);
- billboardMesh->getPolygon(i)->getVertex(j)->z = billboardMesh->getPolygon(i)->getVertex(j)->z - (1.0/2.0f);
- }
- }
- billboardMesh->calculateNormals();
- billboardMesh->arrayDirtyMap[RenderDataArray::VERTEX_DATA_ARRAY] = true;
- billboardMesh->arrayDirtyMap[RenderDataArray::COLOR_DATA_ARRAY] = true;
- billboardMesh->arrayDirtyMap[RenderDataArray::TEXCOORD_DATA_ARRAY] = true;
- billboardMesh->arrayDirtyMap[RenderDataArray::NORMAL_DATA_ARRAY] = true;
-
- }
- SceneMesh *primitive = new SceneMesh(billboardMesh);
-
- primitive->setMaterial(material);
- primitive->billboardMode = true;
- primitive->billboardRoll = true;
- // primitive->alphaTest = true;
- // primitive->depthTest = false;
- primitive->depthWrite = false;
- primitive->backfaceCulled = false;
- particleBody = primitive;
- }
- break;
- case MESH_PARTICLE:
- {
- SceneMesh *primitive = new SceneMesh(particleMesh);
- if(particleMesh->getMeshType() == Mesh::TRI_MESH)
- primitive->cacheToVertexBuffer(true);
- primitive->setMaterial(material);
- // primitive->billboardMode = true;
- // primitive->billboardRoll = true;
- //primitive->depthTest = false;
- // primitive->backfaceCulled = false;
- particleBody = primitive;
- }
- break;
- default:
- assert(0);
- break;
- }
- }
- void Particle::Reset(bool continuious) {
- if(continuious) {
- if(life > lifespan)
- life = 0 + (life - lifespan);
- else
- life = 0;
- } else {
- life = 0;
- }
- perlinPosX = (Number)rand()/RAND_MAX;
- perlinPosY = (Number)rand()/RAND_MAX;
- perlinPosZ = (Number)rand()/RAND_MAX;
-
- }
- Particle::~Particle() {
- }
|