mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Moving I/O code into head class, playing with blocks
This commit is contained in:
commit
255e628a92
8 changed files with 61 additions and 29 deletions
22
cloud.cpp
22
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) {
|
||||
|
@ -21,14 +23,21 @@ Cloud::Cloud(int num,
|
|||
particles = new Particle[count];
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
particles[i].position.x = randFloat()*box.x;
|
||||
particles[i].position.y = randFloat()*box.y;
|
||||
particles[i].position.z = randFloat()*box.z;
|
||||
float x = randFloat()*box.x;
|
||||
float y = randFloat()*box.y;
|
||||
float z = randFloat()*box.z;
|
||||
particles[i].position.x = x;
|
||||
particles[i].position.y = y;
|
||||
particles[i].position.z = z;
|
||||
|
||||
particles[i].velocity.x = 0; //randFloat() - 0.5;
|
||||
particles[i].velocity.y = 0; //randFloat() - 0.5;
|
||||
particles[i].velocity.z = 0; //randFloat() - 0.5;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -38,7 +47,7 @@ void Cloud::render() {
|
|||
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f };
|
||||
|
||||
glEnable( GL_TEXTURE_2D );
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
|
||||
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particle_attenuation_quadratic );
|
||||
|
||||
float maxSize = 0.0f;
|
||||
|
@ -52,6 +61,9 @@ void Cloud::render() {
|
|||
glBegin( GL_POINTS );
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
glColor3f(particles[i].color.x,
|
||||
particles[i].color.y,
|
||||
particles[i].color.z);
|
||||
glVertex3f(particles[i].position.x,
|
||||
particles[i].position.y,
|
||||
particles[i].position.z);
|
||||
|
@ -75,7 +87,7 @@ void Cloud::simulate (float deltaTime) {
|
|||
|
||||
// Interact with Field
|
||||
const float FIELD_COUPLE = 0.0000001;
|
||||
field_interact(&particles[i].position, &particles[i].velocity, FIELD_COUPLE);
|
||||
field_interact(&particles[i].position, &particles[i].velocity, &particles[i].color, FIELD_COUPLE);
|
||||
|
||||
// Bounce or Wrap
|
||||
if (wrapBounds) {
|
||||
|
|
2
cloud.h
2
cloud.h
|
@ -22,7 +22,7 @@ public:
|
|||
|
||||
private:
|
||||
struct Particle {
|
||||
glm::vec3 position, velocity;
|
||||
glm::vec3 position, velocity, color;
|
||||
} *particles;
|
||||
unsigned int count;
|
||||
glm::vec3 bounds;
|
||||
|
|
22
field.cpp
22
field.cpp
|
@ -7,15 +7,13 @@
|
|||
//
|
||||
|
||||
#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
|
||||
|
||||
struct {
|
||||
glm::vec3 val;
|
||||
} field[FIELD_ELEMENTS];
|
||||
|
||||
|
||||
int field_value(float *value, float *pos)
|
||||
// sets the vector value (3 floats) to field value at location pos in space.
|
||||
// returns zero if the location is outside world bounds
|
||||
|
@ -33,7 +31,6 @@ int field_value(float *value, float *pos)
|
|||
else return 0;
|
||||
}
|
||||
|
||||
|
||||
void field_init()
|
||||
// Initializes the field to some random values
|
||||
{
|
||||
|
@ -43,7 +40,12 @@ void field_init()
|
|||
field[i].val.x = (randFloat() - 0.5)*FIELD_SCALE;
|
||||
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.
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
void field_add(float* add, float *pos)
|
||||
|
@ -60,7 +62,7 @@ void field_add(float* add, float *pos)
|
|||
}
|
||||
}
|
||||
|
||||
void field_interact(glm::vec3 * pos, glm::vec3 * vel, float coupling) {
|
||||
void field_interact(glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling) {
|
||||
|
||||
int index = (int)(pos->x/WORLD_SIZE*10.0) +
|
||||
(int)(pos->y/WORLD_SIZE*10.0)*10 +
|
||||
|
@ -72,6 +74,9 @@ void field_interact(glm::vec3 * pos, glm::vec3 * vel, float coupling) {
|
|||
glm::vec3 temp = *vel;
|
||||
temp *= coupling;
|
||||
field[index].val += temp;
|
||||
|
||||
// add a fraction of the field color to the particle color
|
||||
*color = (*color * (1 - COLOR_DRIFT_RATE)) + (fieldcolors[index].rgb * COLOR_DRIFT_RATE);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,3 +177,4 @@ void field_render()
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
|
14
field.h
14
field.h
|
@ -20,14 +20,22 @@
|
|||
#include "glm/glm.hpp"
|
||||
|
||||
// Field is a lattice of vectors uniformly distributed FIELD_ELEMENTS^(1/3) on side
|
||||
|
||||
const int FIELD_ELEMENTS = 1000;
|
||||
|
||||
struct {
|
||||
glm::vec3 val;
|
||||
} field[FIELD_ELEMENTS];
|
||||
|
||||
// Pre-calculated RGB values for each field element
|
||||
struct {
|
||||
glm::vec3 rgb;
|
||||
} fieldcolors[FIELD_ELEMENTS];
|
||||
|
||||
void field_init();
|
||||
int field_value(float *ret, float *pos);
|
||||
void field_render();
|
||||
void field_add(float* add, float *loc);
|
||||
void field_interact(glm::vec3 * pos, glm::vec3 * vel, float coupling);
|
||||
void field_interact(glm::vec3 * pos, glm::vec3 * vel, glm::vec3 * color, float coupling);
|
||||
void field_simulate(float dt);
|
||||
|
||||
glm::vec3 hsv2rgb(glm::vec3 in);
|
||||
#endif
|
||||
|
|
|
@ -302,6 +302,7 @@
|
|||
"$(OTHER_CFLAGS)",
|
||||
);
|
||||
PRODUCT_NAME = interface;
|
||||
SDKROOT = macosx10.7;
|
||||
};
|
||||
name = Debug;
|
||||
};
|
||||
|
@ -320,11 +321,13 @@
|
|||
/usr/local/lib,
|
||||
/usr/local/Cellar/libpng/1.5.13/lib,
|
||||
);
|
||||
ONLY_ACTIVE_ARCH = NO;
|
||||
OTHER_CPLUSPLUSFLAGS = (
|
||||
"-O3",
|
||||
"$(OTHER_CFLAGS)",
|
||||
);
|
||||
PRODUCT_NAME = interface;
|
||||
SDKROOT = macosx10.7;
|
||||
};
|
||||
name = Release;
|
||||
};
|
||||
|
|
Binary file not shown.
26
main.cpp
26
main.cpp
|
@ -49,9 +49,6 @@
|
|||
#include "cloud.h"
|
||||
#include "agent.h"
|
||||
|
||||
|
||||
//TGAImg Img;
|
||||
|
||||
using namespace std;
|
||||
|
||||
// Junk for talking to the Serial Port
|
||||
|
@ -95,7 +92,8 @@ ParticleSystem balls(0,
|
|||
0.0 // Gravity
|
||||
);
|
||||
|
||||
Cloud cloud(100000, // Particles
|
||||
|
||||
Cloud cloud(200000, // Particles
|
||||
box, // Bounding Box
|
||||
false // Wrap
|
||||
);
|
||||
|
@ -108,7 +106,7 @@ int cube_count = 0;
|
|||
#define RENDER_FRAME_MSECS 10
|
||||
#define SLEEP 0
|
||||
|
||||
float yaw =0.f; // The yaw, pitch for the avatar head
|
||||
float yaw =0.f; // The yaw, pitch for the avatar head
|
||||
float pitch = 0.f; //
|
||||
float start_yaw = 90.0;
|
||||
float render_yaw = start_yaw;
|
||||
|
@ -244,11 +242,13 @@ void initDisplay(void)
|
|||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_LIGHT0);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
|
||||
load_png_as_texture(texture_filename);
|
||||
}
|
||||
|
||||
void init(void)
|
||||
{
|
||||
int i;
|
||||
int i;
|
||||
|
||||
if (audio_on) {
|
||||
Audio::init();
|
||||
|
@ -277,6 +277,10 @@ void init(void)
|
|||
myHead.setNoise(noise);
|
||||
}
|
||||
|
||||
// turning cubes off for the moment -
|
||||
// uncomment to re-enable
|
||||
/*
|
||||
|
||||
int index = 0;
|
||||
while (index < MAX_CUBES) {
|
||||
cubes_position[index*3] = randFloat()*WORLD_SIZE;
|
||||
|
@ -297,16 +301,16 @@ void init(void)
|
|||
float scale = 10.0;
|
||||
int j = 0;
|
||||
|
||||
while (index < 4) { //(index < (MAX_CUBES/2)) {
|
||||
while (index < (MAX_CUBES/2)) {
|
||||
|
||||
index = 0;
|
||||
j++;
|
||||
makeCubes(location, scale, &index, cubes_position, cubes_scale, cubes_color);
|
||||
std::cout << "Run " << j << " Made " << index << " cubes\n";
|
||||
cube_count = index;
|
||||
}*/
|
||||
}
|
||||
*/
|
||||
|
||||
//load_png_as_texture(texture_filename);
|
||||
|
||||
if (serial_on)
|
||||
{
|
||||
// Call readsensors for a while to get stable initial values on sensors
|
||||
|
@ -533,8 +537,6 @@ void display(void)
|
|||
|
||||
/* Draw Point Sprites */
|
||||
|
||||
load_png_as_texture(texture_filename);
|
||||
|
||||
glDisable( GL_POINT_SPRITE_ARB );
|
||||
glDisable( GL_TEXTURE_2D );
|
||||
if (!display_head) cloud.render();
|
||||
|
|
|
@ -34,6 +34,7 @@ int load_png_as_texture(char* filename)
|
|||
unsigned int width = 1, height = 1;
|
||||
unsigned error = lodepng::decode(image, width, height, filename);
|
||||
if (error) {
|
||||
std::cout << "Error loading texture" << std::endl;
|
||||
return (int) error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue