commit 5bf518a6845d48ce083e2f43f375dd06023c3ce0
parent 3572c337d689075a8ddfb57f7ed119046e7c4a74
Author: Georges Dupéron <jahvascriptmaniac+github@free.fr>
Date: Fri, 13 Jan 2012 01:06:55 +0100
Re-correction des poids du LOD.
Diffstat:
3 files changed, 21 insertions(+), 22 deletions(-)
diff --git a/rules/chose.cpp b/rules/chose.cpp
@@ -120,16 +120,20 @@ void Chose::addBBPoints(const Quad q, float height) {
}
void Chose::updateAABB() {
+ float splitFactor = 5.f;
+ float mergeFactor = 6.f;
lod.firstBBPoint = true;
getBoundingBoxPoints();
- float dx = lod.aabb[1] - lod.aabb[0];
- float dy = lod.aabb[3] - lod.aabb[2];
- float dz = lod.aabb[5] - lod.aabb[4];
- // TODO pour la pseudoLength sur l'axe x, utiliser y*z, pseudolength_y = x*z, pseudolength_z = x*y.
- float pseudoLength = std::sqrt(dx*dy + dy*dz + dx*dz);
- float splitIncrement = 5 * pseudoLength;
- float mergeIncrement = 6 * pseudoLength;
+ float size[3];
+ for (int i = 0; i < 3; i++)
+ size[i] = lod.aabb[2*i+1] - lod.aabb[2*i];
+ float areaFacing[3];
+ for (int i = 0; i < 3; i++)
+ areaFacing[i] = size[(i+1)%3]*size[(i+1)%3];
for (int i = 0; i < 3; i++) {
+ float pseudoLength = std::max(1.f, std::sqrt(areaFacing[i] + areaFacing[(i+1)%3] / 2.f + areaFacing[(i+1)%3] / 2.f));
+ float splitIncrement = std::min((float)View::backFrustum, splitFactor * pseudoLength);
+ float mergeIncrement = std::min(View::backFrustum * mergeFactor/splitFactor, mergeFactor * pseudoLength);
lod.splitBox[2*i] = lod.aabb[2*i] - splitIncrement;
lod.splitBox[2*i+1] = lod.aabb[2*i+1] + splitIncrement;
lod.mergeBox[2*i] = lod.aabb[2*i] - mergeIncrement;
diff --git a/view.cpp b/view.cpp
@@ -24,7 +24,7 @@ void View::initWindow() {
SDL_SetVideoMode(windowWidth, windowHeight, 32, SDL_OPENGL);
glMatrixMode( GL_PROJECTION );
glLoadIdentity();
- gluPerspective(70,(double)windowWidth/windowHeight,1,100000); // back frustum : 1km
+ gluPerspective(70,(double)windowWidth/windowHeight,frontFrustum,backFrustum);
glEnable(GL_DEPTH_TEST);
glewInit();
diff --git a/view.hh b/view.hh
@@ -3,18 +3,12 @@
#include "all_includes.hh"
-// TODO :
-// flycam : le centre ne bouge pas, la souris contrôle l'angle de vue x & y
-// les flèches avant/arrière permettent d'avancer/reculer.
-// Calcul correct des normales dans triangle.cpp
-// Prendre en compte tous les évènements X en attente avant de relancer le rendu.
-
class Camera {
- public :
+public :
Vertex cameraCenter;
Vertex cameraSight;
- private :
+private :
float xAngle;
float yAngle;
int moveSensitivity;
@@ -26,7 +20,7 @@ class Camera {
bool pageUp;
bool pageDown;
- public :
+public :
Camera(Vertex pos, float xA, float yA, int moveSensitivity, float mouseSensitivity);
void setCamera();
void mouseMotion(const SDL_MouseMotionEvent &event);
@@ -38,19 +32,20 @@ class Camera {
class View {
- private :
+private :
Chose* root;
- public :
+public :
Camera camera;
+ static const int frontFrustum = 1;
+ static const int backFrustum = 100000; // 1km
private:
Lod lod;
static const int windowWidth = 1024;
static const int windowHeight = 768;
-
- public :
+public :
View(Chose* root);
void initWindow();
void mainLoop();
@@ -59,7 +54,7 @@ private:
static void setColor(unsigned char r, unsigned char g, unsigned char b);
- private :
+private :
void setLight();
};