Permalink
Browse files

It is now possible to add galaxies while running. Not possible yet wi…

…th seperate (higher performance) dust treatment
  • Loading branch information...
1 parent 138ceb5 commit e1e90545a44cc4039aa548650b450b0876ef927d @jbedorf jbedorf committed May 7, 2012
@@ -11,7 +11,7 @@ typedef float4 real4;
//If you uncomment the next line dust/massless particles will be treated
//like normal particles and used in the tree-construction
-#define USE_DUST
+// #define USE_DUST
#define IMPBH //Improved barnes hut opening method
@@ -35,8 +35,8 @@
using namespace nv;
-SmokeRenderer::SmokeRenderer(int numParticles) :
- mMaxParticles(numParticles),
+SmokeRenderer::SmokeRenderer(int numParticles, int maxParticles) :
+ mMaxParticles(maxParticles),
mNumParticles(numParticles),
mPosVbo(0),
mVelVbo(0),
@@ -276,6 +276,20 @@ void SmokeRenderer::loadSmokeTextures(int nImages, int offset, char* sTexturePre
}
#endif
+void SmokeRenderer::setNumberOfParticles(uint n_particles)
+{
+ if(n_particles > this->mMaxParticles)
+ {
+ //Uhohhh too many particles
+ fprintf(stderr, "Sorry increase the number of maxParticles \n");
+ this->mNumParticles = this->mMaxParticles;
+ }
+ else
+ {
+ this->mNumParticles = n_particles;
+ }
+}
+
void SmokeRenderer::setPositions(float *pos)
{
memcpy(mParticlePos.getHostPtr(), pos, mNumParticles*4*sizeof(float));
@@ -297,7 +311,9 @@ void SmokeRenderer::setColors(float *color)
// allocate
glGenBuffers(1, &mColorVbo);
glBindBuffer(GL_ARRAY_BUFFER_ARB, mColorVbo);
- glBufferData(GL_ARRAY_BUFFER_ARB, mNumParticles * 4 * sizeof(float), color, GL_DYNAMIC_DRAW);
+// glBufferData(GL_ARRAY_BUFFER_ARB, mNumParticles * 4 * sizeof(float), color, GL_DYNAMIC_DRAW);
+ //Jeroen, I allocate the maximum number of particles
+ glBufferData(GL_ARRAY_BUFFER_ARB, mMaxParticles * 4 * sizeof(float), color, GL_DYNAMIC_DRAW);
}
glBindBuffer(GL_ARRAY_BUFFER_ARB, mColorVbo);
@@ -24,7 +24,7 @@
class SmokeRenderer
{
public:
- SmokeRenderer(int numParticles);
+ SmokeRenderer(int numParticles, int maxParticles);
~SmokeRenderer();
enum DisplayMode
@@ -103,6 +103,10 @@ class SmokeRenderer
void render();
void debugVectors();
+
+ //By JB to modify particle count while running
+ void setNumberOfParticles(uint n_particles);
+ int getNumberOfParticles() {return this->mNumParticles; }
private:
//GLuint loadTexture(char *filename);
@@ -64,14 +64,17 @@ bool octree::addGalaxy(int galaxyID)
vector<real4> newGalaxy_pos;
vector<real4> newGalaxy_vel;
vector<int> newGalaxy_ids;
+ vector<real4> currentGalaxy_pos;
+ vector<real4> currentGalaxy_vel;
+ vector<int> currentGalaxy_ids;
int n_particles = this->localTree.n;
- newGalaxy_pos.insert(newGalaxy_pos.begin(), &this->localTree.bodies_pos[0],
+ currentGalaxy_pos.insert(currentGalaxy_pos.begin(), &this->localTree.bodies_pos[0],
&this->localTree.bodies_pos[0]+n_particles);
- newGalaxy_vel.insert(newGalaxy_vel.begin(), &this->localTree.bodies_vel[0],
+ currentGalaxy_vel.insert(currentGalaxy_vel.begin(), &this->localTree.bodies_vel[0],
&this->localTree.bodies_vel[0]+n_particles);
- newGalaxy_ids.insert(newGalaxy_ids.begin(), &this->localTree.bodies_ids[0],
+ currentGalaxy_ids.insert(newGalaxy_ids.begin(), &this->localTree.bodies_ids[0],
&this->localTree.bodies_ids[0]+n_particles);
vector<real4> newGalaxy_pos_dust;
@@ -86,9 +89,7 @@ bool octree::addGalaxy(int galaxyID)
rank, procs, NTotal, NFirst, NSecond, NThird, this,
newGalaxy_pos_dust, newGalaxy_vel_dust, newGalaxy_ids_dust);
-
- setupMergerModel(newGalaxy_pos, newGalaxy_vel, newGalaxy_ids,
- newGalaxy_pos_dust, newGalaxy_vel_dust, newGalaxy_ids_dust);
+
//First we need to compute the merger parameters
@@ -109,15 +110,19 @@ bool octree::addGalaxy(int galaxyID)
//Now put everything together:
- int extraN = newGalaxy_pos.size() - this->localTree.n;
+ int extraN = newGalaxy_pos.size();
int extraDust = 1;
int old_n = this->localTree.n;
int old_ndust = this->localTree.n_dust;
+
//Increase the size of the buffers
this->localTree.setN(extraN+ this->localTree.n);
this->reallocateParticleMemory(this->localTree); //Resize preserves original data
+
+ setupMergerModel(currentGalaxy_pos,currentGalaxy_vel ,currentGalaxy_ids ,
+ newGalaxy_pos, newGalaxy_vel, newGalaxy_ids);
#ifdef USE_DUST
this->localTree.setNDust(extraDust + this->localTree.n_dust);
@@ -134,13 +139,13 @@ bool octree::addGalaxy(int galaxyID)
this->localTree.bodies_Ppos.d2h();
this->localTree.bodies_Pvel.d2h();
- memcpy(&this->localTree.bodies_pos[0], &newGalaxy_pos[0], sizeof(real4)*newGalaxy_pos.size());
- memcpy(&this->localTree.bodies_Ppos[0], &newGalaxy_pos[0], sizeof(real4)*newGalaxy_pos.size());
+ memcpy(&this->localTree.bodies_pos[0], &currentGalaxy_pos[0], sizeof(real4)*currentGalaxy_pos.size());
+ memcpy(&this->localTree.bodies_Ppos[0], &currentGalaxy_pos[0], sizeof(real4)*currentGalaxy_pos.size());
- memcpy(&this->localTree.bodies_vel[0], &newGalaxy_vel[0], sizeof(real4)*newGalaxy_vel.size());
- memcpy(&this->localTree.bodies_vel[0], &newGalaxy_vel[0], sizeof(real4)*newGalaxy_vel.size());
+ memcpy(&this->localTree.bodies_vel[0], &currentGalaxy_vel[0], sizeof(real4)*currentGalaxy_vel.size());
+ memcpy(&this->localTree.bodies_vel[0], &currentGalaxy_vel[0], sizeof(real4)*currentGalaxy_vel.size());
- memcpy(&this->localTree.bodies_ids[0], &newGalaxy_ids[0], sizeof(int)*newGalaxy_ids.size());
+ memcpy(&this->localTree.bodies_ids[0], &currentGalaxy_ids[0], sizeof(int)*currentGalaxy_ids.size());
float2 curTime = this->localTree.bodies_time[0];
for(int i=0; i < this->localTree.n; i++)
@@ -202,7 +207,7 @@ bool octree::iterate_once(IterationData &idata) {
if(iter == 5)
{
-// addGalaxy(0);
+// addGalaxy(0);
forceTreeRebuild = true;
}
View
@@ -99,12 +99,14 @@ void drawWireBox(float3 boxMin, float3 boxMax) {
#endif
}
+#define MAX_PARTICLES 5000000
class BonsaiDemo
{
public:
BonsaiDemo(octree *tree, octree::IterationData &idata)
: m_tree(tree), m_idata(idata), iterationsRemaining(true),
- m_renderer(tree->localTree.n + tree->localTree.n_dust),
+// m_renderer(tree->localTree.n + tree->localTree.n_dust),
+ m_renderer(tree->localTree.n + tree->localTree.n_dust, MAX_PARTICLES),
//m_displayMode(ParticleRenderer::PARTICLE_SPRITES_COLOR),
m_displayMode(SmokeRenderer::SPRITES),
m_ox(0), m_oy(0), m_buttonState(0), m_inertia(0.2f),
@@ -134,7 +136,8 @@ class BonsaiDemo
int arraySize = tree->localTree.n;
arraySize += tree->localTree.n_dust;
- m_particleColors = new float4[arraySize];
+// m_particleColors = new float4[arraySize];
+ m_particleColors = new float4[MAX_PARTICLES];
m_renderer.setFOV(m_fov);
m_renderer.setWindowSize(m_windowDims.x, m_windowDims.y);
@@ -180,7 +183,17 @@ class BonsaiDemo
void display() {
if (m_renderingEnabled)
{
+ //Check if we need to update the number of particles
+ if((m_tree->localTree.n + m_tree->localTree.n_dust) > m_renderer.getNumberOfParticles())
+ {
+ //Update the particle count in the renderer
+ m_renderer.setNumberOfParticles(m_tree->localTree.n + m_tree->localTree.n_dust);
+ fitCamera(); //Try to get the model back in view
+ }
+
getBodyData();
+
+
moveCamera();
m_cameraTransLag += (m_cameraTrans - m_cameraTransLag) * m_inertia;

0 comments on commit e1e9054

Please sign in to comment.