mirror of
https://github.com/overte-org/overte.git
synced 2025-06-22 14:20:31 +02:00
got basic cloud working
This commit is contained in:
parent
afd553330a
commit
906f3c8c60
2 changed files with 27 additions and 19 deletions
|
@ -21,6 +21,7 @@ Cloud::Cloud() {
|
||||||
// Create and initialize particles
|
// Create and initialize particles
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
glm::vec3 box = glm::vec3(WORLD_SIZE);
|
glm::vec3 box = glm::vec3(WORLD_SIZE);
|
||||||
|
bounds = box;
|
||||||
count = NUM_PARTICLES;
|
count = NUM_PARTICLES;
|
||||||
wrapBounds = false;
|
wrapBounds = false;
|
||||||
particles = new Particle[count];
|
particles = new Particle[count];
|
||||||
|
@ -34,9 +35,9 @@ Cloud::Cloud() {
|
||||||
particles[i].position.y = y;
|
particles[i].position.y = y;
|
||||||
particles[i].position.z = z;
|
particles[i].position.z = z;
|
||||||
|
|
||||||
particles[i].velocity.x = randFloat() - 0.5f;
|
const float INIT_VEL_SCALE = 0.10;
|
||||||
particles[i].velocity.y = randFloat() - 0.5f;
|
particles[i].velocity = randVector();
|
||||||
particles[i].velocity.z = randFloat() - 0.5f;
|
particles[i].velocity *= WORLD_SIZE * INIT_VEL_SCALE;
|
||||||
|
|
||||||
float color_mult = 1 - COLOR_MIN;
|
float color_mult = 1 - COLOR_MIN;
|
||||||
particles[i].color = glm::vec3(x*color_mult/WORLD_SIZE + COLOR_MIN,
|
particles[i].color = glm::vec3(x*color_mult/WORLD_SIZE + COLOR_MIN,
|
||||||
|
@ -48,12 +49,13 @@ Cloud::Cloud() {
|
||||||
|
|
||||||
void Cloud::render() {
|
void Cloud::render() {
|
||||||
|
|
||||||
|
field->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_MODULATE);
|
glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
|
||||||
|
|
||||||
|
|
||||||
float maxSize = 0.0f;
|
float maxSize = 0.0f;
|
||||||
glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize );
|
glGetFloatv( GL_POINT_SIZE_MAX_ARB, &maxSize );
|
||||||
glPointSize( maxSize );
|
glPointSize( maxSize );
|
||||||
|
@ -65,6 +67,12 @@ void Cloud::render() {
|
||||||
|
|
||||||
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
|
glTexEnvf( GL_POINT_SPRITE_ARB, GL_COORD_REPLACE_ARB, GL_TRUE );
|
||||||
glEnable( GL_POINT_SPRITE_ARB );
|
glEnable( GL_POINT_SPRITE_ARB );
|
||||||
|
*/
|
||||||
|
glPointSize(3.0f);
|
||||||
|
glDisable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
|
glEnable(GL_POINT_SMOOTH);
|
||||||
|
|
||||||
glBegin( GL_POINTS );
|
glBegin( GL_POINTS );
|
||||||
for (unsigned int i = 0; i < count; i++)
|
for (unsigned int i = 0; i < count; i++)
|
||||||
{
|
{
|
||||||
|
@ -90,7 +98,7 @@ void Cloud::simulate (float deltaTime) {
|
||||||
//particles[i].position += particles[i].velocity;
|
//particles[i].position += particles[i].velocity;
|
||||||
|
|
||||||
// Decay Velocity (Drag)
|
// Decay Velocity (Drag)
|
||||||
const float CONSTANT_DAMPING = 0.5;
|
const float CONSTANT_DAMPING = 0.15;
|
||||||
particles[i].velocity *= (1.f - CONSTANT_DAMPING*deltaTime);
|
particles[i].velocity *= (1.f - CONSTANT_DAMPING*deltaTime);
|
||||||
|
|
||||||
// Interact with Field
|
// Interact with Field
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
#include "Field.h"
|
#include "Field.h"
|
||||||
|
|
||||||
#define FIELD_SCALE 0.00050
|
#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_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
|
#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;
|
float fx, fy, fz;
|
||||||
for (i = 0; i < FIELD_ELEMENTS; i++)
|
for (i = 0; i < FIELD_ELEMENTS; i++)
|
||||||
{
|
{
|
||||||
field[i].val.x = (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;
|
field[i].val.y = (randFloat() - 0.5f)*FIELD_SCALEf * WORLD_SIZE;
|
||||||
field[i].val.z = (randFloat() - 0.5f)*FIELD_SCALEf;
|
field[i].val.z = (randFloat() - 0.5f)*FIELD_SCALEf * WORLD_SIZE;
|
||||||
field[i].scalar = 0;
|
field[i].scalar = 0;
|
||||||
// Record center point for this field cell
|
// Record center point for this field cell
|
||||||
fx = static_cast<float>(i % 10);
|
fx = static_cast<float>(i % 10);
|
||||||
|
@ -182,15 +182,15 @@ void Field::render()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float fx, fy, fz;
|
float fx, fy, fz;
|
||||||
float scale_view = 0.1f;
|
float scale_view = 0.1f * WORLD_SIZE;
|
||||||
|
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glBegin(GL_LINES);
|
glBegin(GL_LINES);
|
||||||
for (i = 0; i < FIELD_ELEMENTS; i++)
|
for (i = 0; i < FIELD_ELEMENTS; i++)
|
||||||
{
|
{
|
||||||
fx = field[i].center.x;
|
fx = field[i].center.x * WORLD_SIZE;
|
||||||
fy = field[i].center.y;
|
fy = field[i].center.y * WORLD_SIZE;
|
||||||
fz = field[i].center.z;
|
fz = field[i].center.z * WORLD_SIZE;
|
||||||
|
|
||||||
glColor3f(0, 1, 0);
|
glColor3f(0, 1, 0);
|
||||||
glVertex3f(fx, fy, fz);
|
glVertex3f(fx, fy, fz);
|
||||||
|
@ -222,7 +222,7 @@ void Field::render()
|
||||||
fy = static_cast<float>(i%100 / 10);
|
fy = static_cast<float>(i%100 / 10);
|
||||||
fz = static_cast<float>(i / 100);
|
fz = static_cast<float>(i / 100);
|
||||||
|
|
||||||
glVertex3f(fx, fy, fz);
|
glVertex3f(fx / 10.f * WORLD_SIZE, fy / 10.f * WORLD_SIZE, fz / 10.f * WORLD_SIZE);
|
||||||
}
|
}
|
||||||
glEnd();
|
glEnd();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue