Correction du fog.
This commit is contained in:
parent
8178e0e4ba
commit
59ca4daf55
|
@ -10,7 +10,6 @@ class Chose;
|
|||
#include <cstdlib>
|
||||
#include <cmath>
|
||||
#include <vector>
|
||||
//#include <map>
|
||||
#include <set>
|
||||
|
||||
#include <SDL/SDL.h>
|
||||
|
|
3
rules/architecture/couleurs.cpp
Normal file
3
rules/architecture/couleurs.cpp
Normal file
|
@ -0,0 +1,3 @@
|
|||
#include "all_includes.hh"
|
||||
|
||||
const unsigned int Couleurs::fog = mix(skyTop, skyBottom, 0.5);
|
|
@ -5,12 +5,29 @@
|
|||
|
||||
class Couleurs {
|
||||
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 toit = 0x961618;
|
||||
static const unsigned int route = 0x363636;
|
||||
static const unsigned int trottoir = 0x666666;
|
||||
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
|
||||
|
|
|
@ -28,7 +28,7 @@ bool Chose::merge() {
|
|||
}
|
||||
|
||||
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) {
|
||||
|
|
90
view.cpp
90
view.cpp
|
@ -2,14 +2,13 @@
|
|||
|
||||
View::View(Chose* _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) {
|
||||
|
||||
fogColor[0] = 0.5;
|
||||
fogColor[1] = 0.5;
|
||||
fogColor[2] = 0.5;
|
||||
fogColor[0] = Couleurs::r(Couleurs::fog) / 255.f;
|
||||
fogColor[1] = Couleurs::g(Couleurs::fog) / 255.f;
|
||||
fogColor[2] = Couleurs::b(Couleurs::fog) / 255.f;
|
||||
fogColor[3] = 1.0;
|
||||
density = 0.000015;
|
||||
initWindow();
|
||||
mainLoop();
|
||||
}
|
||||
|
@ -48,9 +47,10 @@ void View::initWindow() {
|
|||
glEnable(GL_LIGHT0); // Active la lumière 0;
|
||||
|
||||
glEnable (GL_FOG);
|
||||
glFogi (GL_FOG_MODE, GL_EXP2);
|
||||
glFogi (GL_FOG_MODE, GL_LINEAR);
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -93,41 +93,47 @@ void View::displayAxes() {
|
|||
}
|
||||
|
||||
void View::setSkybox() {
|
||||
int z = 40000;
|
||||
int d = 160000;
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_LIGHTING);
|
||||
glPushMatrix();
|
||||
glTranslated(camera.cameraCenter.x,camera.cameraCenter.y,0);
|
||||
for(int ii=0; ii<4;ii++) {
|
||||
glBegin(GL_QUADS);
|
||||
glColor3ub(128,128,255);
|
||||
glVertex3f(-d,d,z-d);
|
||||
glVertex3f(d,d,z-d);
|
||||
glColor3ub(60,20,255);
|
||||
glVertex3f(d,d,z+d);
|
||||
glVertex3f(-d,d,z+d);
|
||||
glEnd();
|
||||
glRotated(90,0,0,1);
|
||||
}
|
||||
//int z = 40000;
|
||||
float d = View::backFrustum / std::sqrt(3) * 0.9;
|
||||
glDisable(GL_FOG);
|
||||
glDisable(GL_LIGHTING);
|
||||
glPushMatrix();
|
||||
glTranslated(camera.cameraCenter.x,camera.cameraCenter.y,0);
|
||||
for(int ii=0; ii<4;ii++) {
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
glColor3ub(Couleurs::r(Couleurs::skyBottom),Couleurs::g(Couleurs::skyBottom),Couleurs::b(Couleurs::skyBottom));
|
||||
glVertex3f(-d,d,-d);
|
||||
glVertex3f(d,d,-d);
|
||||
glColor3ub(Couleurs::r(Couleurs::skyTop),Couleurs::g(Couleurs::skyTop),Couleurs::b(Couleurs::skyTop));
|
||||
glVertex3f(d,d,d);
|
||||
glVertex3f(-d,d,d);
|
||||
}
|
||||
glEnd();
|
||||
glRotated(90,0,0,1);
|
||||
}
|
||||
|
||||
glBegin(GL_QUADS);
|
||||
glColor3ub(60,20,255);
|
||||
glVertex3f(-d,d,z+d);
|
||||
glVertex3f(d,d,z+d);
|
||||
glVertex3f(d,-d,z+d);
|
||||
glVertex3f(-d,-d,z+d);
|
||||
glEnd();
|
||||
glBegin(GL_QUADS);
|
||||
glColor3ub(12,64,12);
|
||||
glVertex3f(-d,d,z-d);
|
||||
glVertex3f(d,d,z-d);
|
||||
glVertex3f(d,-d,z-d);
|
||||
glVertex3f(-d,-d,z-d);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_FOG);
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
glColor3ub(Couleurs::r(Couleurs::skyTop),Couleurs::g(Couleurs::skyTop),Couleurs::b(Couleurs::skyTop));
|
||||
glVertex3f(-d,d,d);
|
||||
glVertex3f(d,d,d);
|
||||
glVertex3f(d,-d,d);
|
||||
glVertex3f(-d,-d,d);
|
||||
}
|
||||
glEnd();
|
||||
glBegin(GL_QUADS);
|
||||
{
|
||||
glColor3ub(Couleurs::r(Couleurs::herbe),Couleurs::g(Couleurs::herbe),Couleurs::b(Couleurs::herbe));
|
||||
glVertex3f(-d,d,-d);
|
||||
glVertex3f(d,d,-d);
|
||||
glVertex3f(d,-d,-d);
|
||||
glVertex3f(-d,-d,-d);
|
||||
}
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
glEnable(GL_LIGHTING);
|
||||
glEnable(GL_FOG);
|
||||
}
|
||||
|
||||
void View::renderScene(int lastTime, int currentTime) {
|
||||
|
@ -164,7 +170,7 @@ void View::mainLoop() {
|
|||
short continuer = 1;
|
||||
SDL_Event event;
|
||||
SDL_EnableKeyRepeat(40,40);
|
||||
SDL_WM_GrabInput(SDL_GRAB_OFF);
|
||||
SDL_WM_GrabInput(SDL_GRAB_ON);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
while ( SDL_PollEvent(&event) ); // empty queue.
|
||||
|
||||
|
|
5
view.hh
5
view.hh
|
@ -37,12 +37,11 @@ private :
|
|||
|
||||
public :
|
||||
Camera camera;
|
||||
static const int frontFrustum = 1;
|
||||
static const int backFrustum = 400000; // 1km
|
||||
static const float frontFrustum = 1;
|
||||
static const float backFrustum = 400000; // 1km
|
||||
private:
|
||||
Lod lod;
|
||||
GLfloat fogColor[4];
|
||||
GLfloat density;
|
||||
static const int windowWidth = 1024;
|
||||
static const int windowHeight = 768;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user