From 8b720d53df0a049e2eab15287fbc4baad6868342 Mon Sep 17 00:00:00 2001 From: Yoz Grahame Date: Wed, 28 Nov 2012 14:01:35 -0800 Subject: [PATCH] Move constants to macros; increase particle count --- cloud.cpp | 9 ++++++--- field.cpp | 11 +++++++---- interface.xcodeproj/project.pbxproj | 3 ++- main.cpp | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/cloud.cpp b/cloud.cpp index 02b65534b9..329b840ab5 100644 --- a/cloud.cpp +++ b/cloud.cpp @@ -10,6 +10,8 @@ #include "cloud.h" #include "util.h" +#define COLOR_MIN 0.3f // minimum R/G/B value at 0,0,0 - also needs setting in field.cpp + Cloud::Cloud(int num, glm::vec3 box, int wrap) { @@ -32,9 +34,10 @@ Cloud::Cloud(int num, particles[i].velocity.y = 0; //randFloat() - 0.5; particles[i].velocity.z = 0; //randFloat() - 0.5; - particles[i].color = glm::vec3(x*0.8f/WORLD_SIZE + 0.2f, - y*0.8f/WORLD_SIZE + 0.2f, - z*0.8f/WORLD_SIZE + 0.2f); + float color_mult = 1 - COLOR_MIN; + particles[i].color = glm::vec3(x*color_mult/WORLD_SIZE + COLOR_MIN, + y*color_mult/WORLD_SIZE + COLOR_MIN, + z*color_mult/WORLD_SIZE + COLOR_MIN); } } diff --git a/field.cpp b/field.cpp index 17570c31ed..011fb6515f 100644 --- a/field.cpp +++ b/field.cpp @@ -9,6 +9,8 @@ #include "field.h" #include "glm/glm.hpp" #define FIELD_SCALE 0.00050 +#define COLOR_DRIFT_RATE 0.001f // per-frame drift of particle color towards field element color +#define COLOR_MIN 0.3f // minimum R/G/B value at 0,0,0 - also needs setting in cloud.cpp // A vector-valued field over an array of elements arranged as a 3D lattice @@ -39,9 +41,10 @@ void field_init() field[i].val.y = (randFloat() - 0.5)*FIELD_SCALE; field[i].val.z = (randFloat() - 0.5)*FIELD_SCALE; // and set up the RGB values for each field element. - fieldcolors[i].rgb = glm::vec3(((i%10)*0.08) + 0.2f, - ((i%100)*0.008) + 0.2f, - (i*0.0008) + 0.2f); + float color_mult = 1 - COLOR_MIN; + fieldcolors[i].rgb = glm::vec3(((i%10)*(color_mult/10.0f)) + COLOR_MIN, + ((i%100)*(color_mult/100.0f)) + COLOR_MIN, + (i*(color_mult/1000.0f)) + COLOR_MIN); } } @@ -73,7 +76,7 @@ void field_interact(glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float c field[index].val += temp; // add a fraction of the field color to the particle color - *color = (*color * 0.999f) + (fieldcolors[index].rgb * 0.001f); + *color = (*color * (1 - COLOR_DRIFT_RATE)) + (fieldcolors[index].rgb * COLOR_DRIFT_RATE); } } diff --git a/interface.xcodeproj/project.pbxproj b/interface.xcodeproj/project.pbxproj index 46d29d8132..166c6ad19c 100644 --- a/interface.xcodeproj/project.pbxproj +++ b/interface.xcodeproj/project.pbxproj @@ -57,7 +57,7 @@ /* Begin PBXFileReference section */ 08FB7796FE84155DC02AAC07 /* main.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = main.cpp; sourceTree = ""; }; - 8DD76F6C0486A84900D96B5E /* interface */ = {isa = PBXFileReference; includeInIndex = 0; lastKnownFileType = "compiled.mach-o.executable"; path = interface; sourceTree = BUILT_PRODUCTS_DIR; }; + 8DD76F6C0486A84900D96B5E /* interface */ = {isa = PBXFileReference; explicitFileType = "compiled.mach-o.executable"; includeInIndex = 0; path = interface; sourceTree = BUILT_PRODUCTS_DIR; }; B6BDADD115F4084F002A07DF /* audio.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = audio.h; sourceTree = ""; }; B6BDADD315F4085B002A07DF /* audio.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = audio.cpp; sourceTree = ""; }; B6BDADD515F40B04002A07DF /* libportaudio.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libportaudio.a; sourceTree = ""; }; @@ -321,6 +321,7 @@ /usr/local/lib, /usr/local/Cellar/libpng/1.5.13/lib, ); + ONLY_ACTIVE_ARCH = NO; OTHER_CPLUSPLUSFLAGS = ( "-O3", "$(OTHER_CFLAGS)", diff --git a/main.cpp b/main.cpp index 5010dcf1d5..256a550058 100644 --- a/main.cpp +++ b/main.cpp @@ -92,7 +92,7 @@ ParticleSystem balls(0, 0.0 // Gravity ); -Cloud cloud(100000, // Particles +Cloud cloud(200000, // Particles box, // Bounding Box false // Wrap );