![]() |
WhirlyGlobe
1.2
A 3D interactive globe toolkit for iOS
|
00001 /* 00002 * ParticleGenerator.h 00003 * WhirlyGlobeLib 00004 * 00005 * Created by Steve Gifford on 10/12/11. 00006 * Copyright 2011 mousebird consulting. All rights reserved. 00007 * 00008 * Licensed under the Apache License, Version 2.0 (the "License"); 00009 * you may not use this file except in compliance with the License. 00010 * You may obtain a copy of the License at 00011 * http://www.apache.org/licenses/LICENSE-2.0 00012 * 00013 * Unless required by applicable law or agreed to in writing, software 00014 * distributed under the License is distributed on an "AS IS" BASIS, 00015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00016 * See the License for the specific language governing permissions and 00017 * limitations under the License. 00018 * 00019 */ 00020 00021 #import <math.h> 00022 #import <set> 00023 #import <map> 00024 #import "Identifiable.h" 00025 #import "Drawable.h" 00026 #import "Generator.h" 00027 00028 namespace WhirlyGlobe 00029 { 00030 00036 class ParticleGenerator : public Generator 00037 { 00038 public: 00041 ParticleGenerator(int maxNumParticles); 00042 virtual ~ParticleGenerator(); 00043 00045 void generateDrawables(RendererFrameInfo *frameInfo,std::vector<Drawable *> &drawables); 00046 00048 class Particle 00049 { 00050 public: 00052 Point3f loc; 00054 Vector3f dir; 00056 RGBAColor color; 00058 float velocity; 00060 CFTimeInterval expiration; 00061 }; 00062 00065 class ParticleSystem : public Identifiable 00066 { 00067 public: 00068 ParticleSystem() : Identifiable() { } 00069 ~ParticleSystem() { } 00070 00072 static ParticleSystem makeDefault(); 00073 00075 Particle generateParticle(); 00076 00078 Point3f loc; 00080 Vector3f dirN,dirE,dirUp; 00082 float minLength,maxLength; 00084 int numPerSecMin,numPerSecMax; 00086 float minLifetime,maxLifetime; 00088 float minPhi,maxPhi; 00090 std::vector<RGBAColor> colors; 00092 float minVis,maxVis; 00093 }; 00094 00096 void addParticleSystem(ParticleSystem *particleSystem); 00097 00099 void removeParticleSystem(SimpleIdentity systemId); 00100 00101 protected: 00102 // All times are offset from here 00103 CFTimeInterval startTime; 00104 // When we last updated 00105 CFTimeInterval lastUpdateTime; 00106 00107 int maxNumParticles; // All the particles we can have at once. Ever. 00108 std::vector<Particle> particles; 00109 typedef std::set<ParticleSystem *,IdentifiableSorter> ParticleSystemSet; 00110 ParticleSystemSet particleSystems; 00111 }; 00112 00115 class ParticleGeneratorAddSystemRequest : public GeneratorChangeRequest 00116 { 00117 public: 00118 ParticleGeneratorAddSystemRequest(SimpleIdentity generatorID,ParticleGenerator::ParticleSystem *partSystem); 00119 ~ParticleGeneratorAddSystemRequest(); 00120 00121 virtual void execute2(GlobeScene *scene,Generator *gen); 00122 00123 protected: 00124 ParticleGenerator::ParticleSystem *system; 00125 }; 00126 00128 class ParticleGeneratorRemSystemRequest : public GeneratorChangeRequest 00129 { 00130 public: 00131 ParticleGeneratorRemSystemRequest(SimpleIdentity generatorID,SimpleIdentity systemId); 00132 ~ParticleGeneratorRemSystemRequest() { } 00133 00134 virtual void execute2(GlobeScene *scene,Generator *gen); 00135 00136 protected: 00137 SimpleIdentity systemId; 00138 }; 00139 00140 }