2012-06-08 15:28:29 +00:00
|
|
|
#include "explorerchunksky.h"
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include "baseexplorerchunk.h"
|
|
|
|
#include "../lib_paysages/camera.h"
|
|
|
|
|
2012-11-25 21:53:01 +00:00
|
|
|
ExplorerChunkSky::ExplorerChunkSky(Renderer* renderer, double size, SkyboxOrientation orientation) : BaseExplorerChunk(renderer)
|
2012-06-08 15:28:29 +00:00
|
|
|
{
|
|
|
|
_box_size = size;
|
|
|
|
_orientation = orientation;
|
2013-02-05 21:25:30 +00:00
|
|
|
_center = VECTOR_ZERO;
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
setMaxTextureSize(256);
|
|
|
|
maintain();
|
|
|
|
}
|
|
|
|
|
2013-02-05 21:25:30 +00:00
|
|
|
void ExplorerChunkSky::onCameraEvent(CameraDefinition* camera)
|
|
|
|
{
|
|
|
|
_center = camera->location;
|
|
|
|
}
|
|
|
|
|
2012-12-24 15:15:40 +00:00
|
|
|
void ExplorerChunkSky::onRenderEvent(QGLWidget*)
|
2012-06-08 15:28:29 +00:00
|
|
|
{
|
2012-06-17 09:40:40 +00:00
|
|
|
double size = _box_size;
|
2013-02-05 21:25:30 +00:00
|
|
|
Vector3 camera = _center;
|
2012-06-08 15:28:29 +00:00
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
switch(_orientation)
|
|
|
|
{
|
|
|
|
case SKYBOX_NORTH:
|
|
|
|
glTexCoord2d(0.0, 0.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
|
|
|
break;
|
|
|
|
case SKYBOX_SOUTH:
|
|
|
|
glTexCoord2d(0.0, 0.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
|
|
|
break;
|
|
|
|
case SKYBOX_EAST:
|
|
|
|
glTexCoord2d(0.0, 0.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
|
|
|
break;
|
|
|
|
case SKYBOX_WEST:
|
|
|
|
glTexCoord2d(0.0, 0.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
|
|
|
break;
|
|
|
|
case SKYBOX_TOP:
|
|
|
|
glTexCoord2d(0.0, 0.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z + size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y + size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z - size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y + size, camera.z + size);
|
|
|
|
break;
|
|
|
|
case SKYBOX_BOTTOM:
|
2013-02-05 21:25:30 +00:00
|
|
|
/*glTexCoord2d(0.0, 0.0);
|
2012-06-08 15:28:29 +00:00
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z - size);
|
|
|
|
glTexCoord2d(0.0, 1.0);
|
|
|
|
glVertex3d(camera.x - size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 1.0);
|
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z + size);
|
|
|
|
glTexCoord2d(1.0, 0.0);
|
2013-02-05 21:25:30 +00:00
|
|
|
glVertex3d(camera.x + size, camera.y - size, camera.z - size);*/
|
2012-06-08 15:28:29 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
2012-12-24 15:15:40 +00:00
|
|
|
double ExplorerChunkSky::getDisplayedSizeHint(CameraDefinition*)
|
2012-06-08 15:28:29 +00:00
|
|
|
{
|
|
|
|
return 1000.0;
|
|
|
|
}
|
|
|
|
|
2012-06-17 09:40:40 +00:00
|
|
|
Color ExplorerChunkSky::getTextureColor(double x, double y)
|
2012-06-08 15:28:29 +00:00
|
|
|
{
|
|
|
|
Vector3 location;
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
x -= 0.5;
|
|
|
|
y -= 0.5;
|
2012-12-24 15:15:40 +00:00
|
|
|
|
2012-06-08 15:28:29 +00:00
|
|
|
switch(_orientation)
|
|
|
|
{
|
|
|
|
case SKYBOX_NORTH:
|
|
|
|
location.x = x;
|
|
|
|
location.y = -y;
|
|
|
|
location.z = -0.5;
|
|
|
|
break;
|
|
|
|
case SKYBOX_SOUTH:
|
|
|
|
location.x = -x;
|
|
|
|
location.y = -y;
|
|
|
|
location.z = 0.5;
|
|
|
|
break;
|
|
|
|
case SKYBOX_EAST:
|
|
|
|
location.x = 0.5;
|
|
|
|
location.y = -y;
|
|
|
|
location.z = x;
|
|
|
|
break;
|
|
|
|
case SKYBOX_WEST:
|
|
|
|
location.x = -0.5;
|
|
|
|
location.y = -y;
|
|
|
|
location.z = -x;
|
|
|
|
break;
|
|
|
|
case SKYBOX_TOP:
|
|
|
|
location.x = x;
|
|
|
|
location.y = 0.5;
|
|
|
|
location.z = -y;
|
|
|
|
break;
|
|
|
|
case SKYBOX_BOTTOM:
|
|
|
|
location.x = x;
|
|
|
|
location.y = -0.5;
|
|
|
|
location.z = y;
|
|
|
|
break;
|
|
|
|
}
|
2013-01-18 10:31:13 +00:00
|
|
|
location = v3Normalize(location);
|
|
|
|
if (location.y < 0.0)
|
|
|
|
{
|
|
|
|
location.y = 0.0;
|
|
|
|
}
|
2013-03-14 17:29:12 +00:00
|
|
|
return renderer()->atmosphere->getSkyColor(renderer(), location).final;
|
2012-06-08 15:28:29 +00:00
|
|
|
}
|