Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added controls for balls

  • Loading branch information...
commit f732f9332e9ba20e4fc7f55357dbad0c629a7ce3 1 parent f83ae1e
@bettsmatt authored
Showing with 35 additions and 18 deletions.
  1. +9 −4 Particle.cpp
  2. +3 −1 Particle.h
  3. +23 −13 ParticleEmitter.cpp
View
13 Particle.cpp
@@ -20,14 +20,18 @@
#include <stdlib.h>
#include <math.h>
-void Particle::init(float* pos, float* initialVelocity, float m, G308_Point* cam, bool d) {
+Particle::Particle(float* pos, float* initialVelocity, float m, G308_Point* cam, bool d) {
position = new float[3];
velocity = new float[3];
acceletation = new float[3];
-
for (int i = 0 ; i < 3 ; i ++){
+ acceletation[i] = 0;
+ position[i] = 0;
+ velocity[i] = 0;
+
+ ;
position[i] = pos[i];
velocity[i] = initialVelocity[i];
}
@@ -35,10 +39,11 @@ void Particle::init(float* pos, float* initialVelocity, float m, G308_Point* cam
mass = m; // Default
/*
- * Lifespan
+ * Life span
*/
float HI = 2000;
- float LO = 1000;
+ float LO = 1500;
+
lifeSpanLeft = lifeSpan = LO + (float)rand()/((float)RAND_MAX/(HI-LO));
camera = cam;
View
4 Particle.h
@@ -36,11 +36,13 @@ class Particle
public:
+
+ Particle(float*, float*, float, G308_Point*, bool);
int lifeSpanLeft;
float* position; // x, y, z
float* velocity; // x, y, z
- void init(float*, float*, float, G308_Point*, bool); // position, velocity, mass, camera, dies
+ //void init(float*, float*, float, G308_Point*, bool); // position, velocity, mass, camera, dies
void tick(); // Simulate one frame
bool isDead(); // Particle has expired
View
36 ParticleEmitter.cpp
@@ -24,7 +24,7 @@
#include <vector>
#define PI 3.14159265359f
-#define MAX_PARTICLES 10000
+#define MAX_PARTICLES 1000
using namespace std;
@@ -35,9 +35,6 @@ ParticleEmitter::ParticleEmitter(G308_Point* c) {
position = new float[3];
vec = new float[3];
- vector <Particle> particleVector;
-
-
particles = (Particle**) malloc (sizeof(Particle*) * MAX_PARTICLES);
index = 0;
@@ -73,7 +70,7 @@ void ParticleEmitter::removeParticles(){
}
void ParticleEmitter::spawnSuns(){
-
+ removeSuns();
numGravity = 3;
float** v = (float**) malloc (sizeof (float) * numGravity);
@@ -109,8 +106,7 @@ void ParticleEmitter::spawnSuns(){
*/
gravity = (Particle**) malloc (sizeof(Particle*) * numGravity);
for(int i = 0 ; i < numGravity ; i ++){
- gravity[i] = (Particle*) malloc (sizeof(Particle));
- gravity[i]->init(p[i],v[i], 100, camera, false);
+ gravity[i] = new Particle (p[i],v[i], 100, camera, false);
}
gravityOn = true;
@@ -119,7 +115,7 @@ void ParticleEmitter::spawnSuns(){
}
void ParticleEmitter::spawnSun(){
-
+ removeSuns();
numGravity = 1;
float** v = (float**) malloc (sizeof (float) * numGravity);
@@ -137,7 +133,7 @@ void ParticleEmitter::spawnSun(){
gravity = (Particle**) malloc (sizeof(Particle*) * numGravity);
for(int i = 0 ; i < numGravity ; i ++){
gravity[i] = (Particle*) malloc (sizeof(Particle));
- gravity[i]->init(p[i],v[i], 100, camera, false);
+ gravity[i] = new Particle (p[i],v[i], 100, camera, false);
}
gravityOn = true;
@@ -181,7 +177,21 @@ void ParticleEmitter::cloud(int num, float radius){
}
+void ParticleEmitter::create(float* p, float * v, float m){
+
+ if(index >= MAX_PARTICLES)
+ index = 0;
+ delete particles[index];
+
+ particles[index] = new Particle(p,v, 1, camera,true);
+
+ index++;
+ created++;
+
+
+}
+/*
void ParticleEmitter::create(float* p, float * v, float m){
int start = index;
@@ -221,7 +231,7 @@ void ParticleEmitter::create(float* p, float * v, float m){
found:; // Never again...
}
-
+*/
void ParticleEmitter::emit(){
@@ -235,9 +245,9 @@ void ParticleEmitter::emit(){
float ZLO = 0.3f;
float* v = new float[3];
- v[0] = 0; //XLO + (float)rand()/((float)RAND_MAX/(XHI-XLO));
- v[1] = 0; //YLO + (float)rand()/((float)RAND_MAX/(YHI-YLO));
- v[2] = 0.2f; //ZLO + (float)rand()/((float)RAND_MAX/(ZHI-ZLO));
+ v[0] = XLO + (float)rand()/((float)RAND_MAX/(XHI-XLO));
+ v[1] = YLO + (float)rand()/((float)RAND_MAX/(YHI-YLO));
+ v[2] = ZLO + (float)rand()/((float)RAND_MAX/(ZHI-ZLO));
float* p = new float[3];
p[0] = position[0];
Please sign in to comment.
Something went wrong with that request. Please try again.