From 906f3c8c60d4c4a422e01e24b51ce74889a776da Mon Sep 17 00:00:00 2001 From: Philip Rosedale Date: Tue, 8 Oct 2013 23:15:29 -0700 Subject: [PATCH] got basic cloud working --- interface/src/Cloud.cpp | 22 +++++++++++++++------- interface/src/Field.cpp | 24 ++++++++++++------------ 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/interface/src/Cloud.cpp b/interface/src/Cloud.cpp index e1149b8355..3f4b0b2c82 100644 --- a/interface/src/Cloud.cpp +++ b/interface/src/Cloud.cpp @@ -21,6 +21,7 @@ Cloud::Cloud() { // Create and initialize particles unsigned int i; glm::vec3 box = glm::vec3(WORLD_SIZE); + bounds = box; count = NUM_PARTICLES; wrapBounds = false; particles = new Particle[count]; @@ -33,10 +34,10 @@ Cloud::Cloud() { particles[i].position.x = x; particles[i].position.y = y; particles[i].position.z = z; - - particles[i].velocity.x = randFloat() - 0.5f; - particles[i].velocity.y = randFloat() - 0.5f; - particles[i].velocity.z = randFloat() - 0.5f; + + const float INIT_VEL_SCALE = 0.10; + particles[i].velocity = randVector(); + particles[i].velocity *= WORLD_SIZE * INIT_VEL_SCALE; float color_mult = 1 - COLOR_MIN; particles[i].color = glm::vec3(x*color_mult/WORLD_SIZE + COLOR_MIN, @@ -48,12 +49,13 @@ Cloud::Cloud() { void Cloud::render() { + field->render(); + /* float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f }; - + glEnable( GL_TEXTURE_2D ); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE); - float maxSize = 0.0f; glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize ); glPointSize( maxSize ); @@ -65,6 +67,12 @@ void Cloud::render() { glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE ); glEnable( GL_POINT_SPRITE_ARB ); + */ + glPointSize(3.0f); + glDisable(GL_TEXTURE_2D); + + glEnable(GL_POINT_SMOOTH); + glBegin( GL_POINTS ); for (unsigned int i = 0; i < count; i++) { @@ -90,7 +98,7 @@ void Cloud::simulate (float deltaTime) { //particles[i].position += particles[i].velocity; // Decay Velocity (Drag) - const float CONSTANT_DAMPING = 0.5; + const float CONSTANT_DAMPING = 0.15; particles[i].velocity *= (1.f - CONSTANT_DAMPING*deltaTime); // Interact with Field diff --git a/interface/src/Field.cpp b/interface/src/Field.cpp index 0beb9e0cf0..5015a3e9f5 100644 --- a/interface/src/Field.cpp +++ b/interface/src/Field.cpp @@ -9,7 +9,7 @@ #include "Field.h" #define FIELD_SCALE 0.00050 -#define FIELD_SCALEf 0.00050f +#define FIELD_SCALEf 0.1f #define COLOR_DRIFT_RATE 0.001f // per-frame drift of particle color towards field element color #define COLOR_MIN 0.2f // minimum R/G/B value at 0,0,0 - also needs setting in cloud.cpp @@ -43,9 +43,9 @@ Field::Field() float fx, fy, fz; for (i = 0; i < FIELD_ELEMENTS; i++) { - field[i].val.x = (randFloat() - 0.5f)*FIELD_SCALEf; - field[i].val.y = (randFloat() - 0.5f)*FIELD_SCALEf; - field[i].val.z = (randFloat() - 0.5f)*FIELD_SCALEf; + field[i].val.x = (randFloat() - 0.5f)*FIELD_SCALEf * WORLD_SIZE; + field[i].val.y = (randFloat() - 0.5f)*FIELD_SCALEf * WORLD_SIZE; + field[i].val.z = (randFloat() - 0.5f)*FIELD_SCALEf * WORLD_SIZE; field[i].scalar = 0; // Record center point for this field cell fx = static_cast(i % 10); @@ -182,21 +182,21 @@ void Field::render() { int i; float fx, fy, fz; - float scale_view = 0.1f; + float scale_view = 0.1f * WORLD_SIZE; glDisable(GL_LIGHTING); glBegin(GL_LINES); for (i = 0; i < FIELD_ELEMENTS; i++) { - fx = field[i].center.x; - fy = field[i].center.y; - fz = field[i].center.z; + fx = field[i].center.x * WORLD_SIZE; + fy = field[i].center.y * WORLD_SIZE; + fz = field[i].center.z * WORLD_SIZE; glColor3f(0, 1, 0); glVertex3f(fx, fy, fz); - glVertex3f(fx + field[i].val.x*scale_view, - fy + field[i].val.y*scale_view, - fz + field[i].val.z*scale_view); + glVertex3f(fx + field[i].val.x * scale_view, + fy + field[i].val.y * scale_view, + fz + field[i].val.z * scale_view); if (USE_SCALAR) { glColor3f(1, 0, 0); glVertex3f(fx, fy, fz); @@ -222,7 +222,7 @@ void Field::render() fy = static_cast(i%100 / 10); fz = static_cast(i / 100); - glVertex3f(fx, fy, fz); + glVertex3f(fx / 10.f * WORLD_SIZE, fy / 10.f * WORLD_SIZE, fz / 10.f * WORLD_SIZE); } glEnd(); }