mirror of
https://github.com/overte-org/overte.git
synced 2025-06-20 19:00:07 +02:00
Look at all the pretty colours!
We now have color values for the field elements, which are gradually added to the particles as they move.
This commit is contained in:
parent
8d47a75758
commit
9fb480e46e
4 changed files with 37 additions and 17 deletions
19
cloud.cpp
19
cloud.cpp
|
@ -21,14 +21,20 @@ Cloud::Cloud(int num,
|
||||||
particles = new Particle[count];
|
particles = new Particle[count];
|
||||||
|
|
||||||
for (i = 0; i < count; i++) {
|
for (i = 0; i < count; i++) {
|
||||||
particles[i].position.x = randFloat()*box.x;
|
float x = randFloat()*box.x;
|
||||||
particles[i].position.y = randFloat()*box.y;
|
float y = randFloat()*box.y;
|
||||||
particles[i].position.z = randFloat()*box.z;
|
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.x = 0; //randFloat() - 0.5;
|
||||||
particles[i].velocity.y = 0; //randFloat() - 0.5;
|
particles[i].velocity.y = 0; //randFloat() - 0.5;
|
||||||
particles[i].velocity.z = 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -38,7 +44,7 @@ void Cloud::render() {
|
||||||
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f };
|
float particle_attenuation_quadratic[] = { 0.0f, 0.0f, 2.0f };
|
||||||
|
|
||||||
glEnable( GL_TEXTURE_2D );
|
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 );
|
glPointParameterfvARB( GL_POINT_DISTANCE_ATTENUATION_ARB, particle_attenuation_quadratic );
|
||||||
|
|
||||||
float maxSize = 0.0f;
|
float maxSize = 0.0f;
|
||||||
|
@ -52,6 +58,9 @@ void Cloud::render() {
|
||||||
glBegin( GL_POINTS );
|
glBegin( GL_POINTS );
|
||||||
for (int i = 0; i < count; i++)
|
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,
|
glVertex3f(particles[i].position.x,
|
||||||
particles[i].position.y,
|
particles[i].position.y,
|
||||||
particles[i].position.z);
|
particles[i].position.z);
|
||||||
|
@ -75,7 +84,7 @@ void Cloud::simulate (float deltaTime) {
|
||||||
|
|
||||||
// Interact with Field
|
// Interact with Field
|
||||||
const float FIELD_COUPLE = 0.0000001;
|
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
|
// Bounce or Wrap
|
||||||
if (wrapBounds) {
|
if (wrapBounds) {
|
||||||
|
|
2
cloud.h
2
cloud.h
|
@ -22,7 +22,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct Particle {
|
struct Particle {
|
||||||
glm::vec3 position, velocity;
|
glm::vec3 position, velocity, color;
|
||||||
} *particles;
|
} *particles;
|
||||||
unsigned int count;
|
unsigned int count;
|
||||||
glm::vec3 bounds;
|
glm::vec3 bounds;
|
||||||
|
|
17
field.cpp
17
field.cpp
|
@ -7,15 +7,11 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
#include "field.h"
|
#include "field.h"
|
||||||
|
#include "glm/glm.hpp"
|
||||||
#define FIELD_SCALE 0.00050
|
#define FIELD_SCALE 0.00050
|
||||||
|
|
||||||
// A vector-valued field over an array of elements arranged as a 3D lattice
|
// 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)
|
int field_value(float *value, float *pos)
|
||||||
// sets the vector value (3 floats) to field value at location pos in space.
|
// sets the vector value (3 floats) to field value at location pos in space.
|
||||||
// returns zero if the location is outside world bounds
|
// returns zero if the location is outside world bounds
|
||||||
|
@ -33,7 +29,6 @@ int field_value(float *value, float *pos)
|
||||||
else return 0;
|
else return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void field_init()
|
void field_init()
|
||||||
// Initializes the field to some random values
|
// Initializes the field to some random values
|
||||||
{
|
{
|
||||||
|
@ -43,6 +38,10 @@ void field_init()
|
||||||
field[i].val.x = (randFloat() - 0.5)*FIELD_SCALE;
|
field[i].val.x = (randFloat() - 0.5)*FIELD_SCALE;
|
||||||
field[i].val.y = (randFloat() - 0.5)*FIELD_SCALE;
|
field[i].val.y = (randFloat() - 0.5)*FIELD_SCALE;
|
||||||
field[i].val.z = (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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,7 +59,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 index = (int)(pos->x/WORLD_SIZE*10.0) +
|
||||||
(int)(pos->y/WORLD_SIZE*10.0)*10 +
|
(int)(pos->y/WORLD_SIZE*10.0)*10 +
|
||||||
|
@ -72,6 +71,9 @@ void field_interact(glm::vec3 * pos, glm::vec3 * vel, float coupling) {
|
||||||
glm::vec3 temp = *vel;
|
glm::vec3 temp = *vel;
|
||||||
temp *= coupling;
|
temp *= coupling;
|
||||||
field[index].val += temp;
|
field[index].val += temp;
|
||||||
|
|
||||||
|
// add a fraction of the field color to the particle color
|
||||||
|
*color = (*color * 0.999f) + (fieldcolors[index].rgb * 0.001f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -172,3 +174,4 @@ void field_render()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
14
field.h
14
field.h
|
@ -20,14 +20,22 @@
|
||||||
#include "glm/glm.hpp"
|
#include "glm/glm.hpp"
|
||||||
|
|
||||||
// Field is a lattice of vectors uniformly distributed FIELD_ELEMENTS^(1/3) on side
|
// Field is a lattice of vectors uniformly distributed FIELD_ELEMENTS^(1/3) on side
|
||||||
|
|
||||||
const int FIELD_ELEMENTS = 1000;
|
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();
|
void field_init();
|
||||||
int field_value(float *ret, float *pos);
|
int field_value(float *ret, float *pos);
|
||||||
void field_render();
|
void field_render();
|
||||||
void field_add(float* add, float *loc);
|
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);
|
void field_simulate(float dt);
|
||||||
|
glm::vec3 hsv2rgb(glm::vec3 in);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in a new issue