Correction du fog.

This commit is contained in:
Georges Dupéron 2012-01-16 16:39:21 +01:00
parent 8178e0e4ba
commit 59ca4daf55
6 changed files with 72 additions and 48 deletions

View File

@ -10,7 +10,6 @@ class Chose;
#include <cstdlib> #include <cstdlib>
#include <cmath> #include <cmath>
#include <vector> #include <vector>
//#include <map>
#include <set> #include <set>
#include <SDL/SDL.h> #include <SDL/SDL.h>

View File

@ -0,0 +1,3 @@
#include "all_includes.hh"
const unsigned int Couleurs::fog = mix(skyTop, skyBottom, 0.5);

View File

@ -5,12 +5,29 @@
class Couleurs { class Couleurs {
public: public:
static unsigned int rgb(unsigned char r, unsigned char g, unsigned char b) {
return r * 0x10000 | g* 0x100 | b;
}
static unsigned char r(unsigned int color) { return ((color >> 16) & 0xff); };
static unsigned char g(unsigned int color) { return ((color >> 8) & 0xff); };
static unsigned char b(unsigned int color) { return (color & 0xff); };
static unsigned int mix(unsigned int colorA, unsigned int colorB, float mixA) {
float mixB = 1 - mixA;
return rgb(
r(colorA) * mixA + r(colorB) * mixB,
g(colorA) * mixA + g(colorB) * mixB,
b(colorA) * mixA + b(colorB) * mixB
);
};
static const unsigned int mur = 0xF1E3AD; static const unsigned int mur = 0xF1E3AD;
static const unsigned int toit = 0x961618; static const unsigned int toit = 0x961618;
static const unsigned int route = 0x363636; static const unsigned int route = 0x363636;
static const unsigned int trottoir = 0x666666; static const unsigned int trottoir = 0x666666;
static const unsigned int bordureTrottoir = 0xAAAAAA; static const unsigned int bordureTrottoir = 0xAAAAAA;
static const unsigned int herbe = 0x11AA22; static const unsigned int herbe = 0x0c4010; // 11AA22
static const unsigned int skyTop = 0x3c14ff;
static const unsigned int skyBottom = 0x7F7FFF;
static const unsigned int fog; // définie dans couleurs.cpp .
}; };
#endif #endif

View File

@ -28,7 +28,7 @@ bool Chose::merge() {
} }
void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, unsigned int rgb) { void Chose::addGPUTriangle(Vertex left, Vertex top, Vertex right, unsigned int rgb) {
triangles.push_back(new GPUTriangle(left, top, right, (rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff)); triangles.push_back(new GPUTriangle(left, top, right, Couleurs::r(rgb), Couleurs::g(rgb), Couleurs::b(rgb)));
} }
void Chose::addGPUTriangle(Triangle t, unsigned int rgb) { void Chose::addGPUTriangle(Triangle t, unsigned int rgb) {

View File

@ -2,14 +2,13 @@
View::View(Chose* _root) View::View(Chose* _root)
: root(_root), : root(_root),
camera(Camera(Vertex(9600,10000,15300 + 80000),0,179,1000,0.6f)), camera(Camera(Vertex(2980,1567,16012), 45, 150, 1000, 0.6f)),
lod(camera.cameraCenter, _root) { lod(camera.cameraCenter, _root) {
fogColor[0] = 0.5; fogColor[0] = Couleurs::r(Couleurs::fog) / 255.f;
fogColor[1] = 0.5; fogColor[1] = Couleurs::g(Couleurs::fog) / 255.f;
fogColor[2] = 0.5; fogColor[2] = Couleurs::b(Couleurs::fog) / 255.f;
fogColor[3] = 1.0; fogColor[3] = 1.0;
density = 0.000015;
initWindow(); initWindow();
mainLoop(); mainLoop();
} }
@ -48,9 +47,10 @@ void View::initWindow() {
glEnable(GL_LIGHT0); // Active la lumière 0; glEnable(GL_LIGHT0); // Active la lumière 0;
glEnable (GL_FOG); glEnable (GL_FOG);
glFogi (GL_FOG_MODE, GL_EXP2); glFogi (GL_FOG_MODE, GL_LINEAR);
glFogfv (GL_FOG_COLOR, fogColor); glFogfv (GL_FOG_COLOR, fogColor);
glFogf (GL_FOG_DENSITY, density); glFogf (GL_FOG_START, backFrustum / sqrt(3) / 2.f);
glFogf (GL_FOG_END, backFrustum / sqrt(3));
//glHint (GL_FOG_HINT, GL_NICEST); //glHint (GL_FOG_HINT, GL_NICEST);
} }
@ -93,37 +93,43 @@ void View::displayAxes() {
} }
void View::setSkybox() { void View::setSkybox() {
int z = 40000; //int z = 40000;
int d = 160000; float d = View::backFrustum / std::sqrt(3) * 0.9;
glDisable(GL_FOG); glDisable(GL_FOG);
glDisable(GL_LIGHTING); glDisable(GL_LIGHTING);
glPushMatrix(); glPushMatrix();
glTranslated(camera.cameraCenter.x,camera.cameraCenter.y,0); glTranslated(camera.cameraCenter.x,camera.cameraCenter.y,0);
for(int ii=0; ii<4;ii++) { for(int ii=0; ii<4;ii++) {
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3ub(128,128,255); {
glVertex3f(-d,d,z-d); glColor3ub(Couleurs::r(Couleurs::skyBottom),Couleurs::g(Couleurs::skyBottom),Couleurs::b(Couleurs::skyBottom));
glVertex3f(d,d,z-d); glVertex3f(-d,d,-d);
glColor3ub(60,20,255); glVertex3f(d,d,-d);
glVertex3f(d,d,z+d); glColor3ub(Couleurs::r(Couleurs::skyTop),Couleurs::g(Couleurs::skyTop),Couleurs::b(Couleurs::skyTop));
glVertex3f(-d,d,z+d); glVertex3f(d,d,d);
glVertex3f(-d,d,d);
}
glEnd(); glEnd();
glRotated(90,0,0,1); glRotated(90,0,0,1);
} }
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3ub(60,20,255); {
glVertex3f(-d,d,z+d); glColor3ub(Couleurs::r(Couleurs::skyTop),Couleurs::g(Couleurs::skyTop),Couleurs::b(Couleurs::skyTop));
glVertex3f(d,d,z+d); glVertex3f(-d,d,d);
glVertex3f(d,-d,z+d); glVertex3f(d,d,d);
glVertex3f(-d,-d,z+d); glVertex3f(d,-d,d);
glVertex3f(-d,-d,d);
}
glEnd(); glEnd();
glBegin(GL_QUADS); glBegin(GL_QUADS);
glColor3ub(12,64,12); {
glVertex3f(-d,d,z-d); glColor3ub(Couleurs::r(Couleurs::herbe),Couleurs::g(Couleurs::herbe),Couleurs::b(Couleurs::herbe));
glVertex3f(d,d,z-d); glVertex3f(-d,d,-d);
glVertex3f(d,-d,z-d); glVertex3f(d,d,-d);
glVertex3f(-d,-d,z-d); glVertex3f(d,-d,-d);
glVertex3f(-d,-d,-d);
}
glEnd(); glEnd();
glPopMatrix(); glPopMatrix();
glEnable(GL_LIGHTING); glEnable(GL_LIGHTING);
@ -164,7 +170,7 @@ void View::mainLoop() {
short continuer = 1; short continuer = 1;
SDL_Event event; SDL_Event event;
SDL_EnableKeyRepeat(40,40); SDL_EnableKeyRepeat(40,40);
SDL_WM_GrabInput(SDL_GRAB_OFF); SDL_WM_GrabInput(SDL_GRAB_ON);
SDL_ShowCursor(SDL_DISABLE); SDL_ShowCursor(SDL_DISABLE);
while ( SDL_PollEvent(&event) ); // empty queue. while ( SDL_PollEvent(&event) ); // empty queue.

View File

@ -37,12 +37,11 @@ private :
public : public :
Camera camera; Camera camera;
static const int frontFrustum = 1; static const float frontFrustum = 1;
static const int backFrustum = 400000; // 1km static const float backFrustum = 400000; // 1km
private: private:
Lod lod; Lod lod;
GLfloat fogColor[4]; GLfloat fogColor[4];
GLfloat density;
static const int windowWidth = 1024; static const int windowWidth = 1024;
static const int windowHeight = 768; static const int windowHeight = 768;