2012-03-20 01:57:42 +01:00
|
|
|
#include "lc_global.h"
|
2011-09-07 23:06:51 +02:00
|
|
|
#include "LeoCAD.h"
|
|
|
|
#include "TerrWnd.h"
|
|
|
|
#include "Terrain.h"
|
|
|
|
|
|
|
|
#include "camera.h"
|
|
|
|
#include "Tools.h"
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
lcTerrainView::lcTerrainView(GLWindow* Share, Terrain* pTerrain)
|
|
|
|
: GLWindow(Share)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-08-22 03:13:32 +02:00
|
|
|
mCamera = new Camera(20, 20, 20, 0, 0, 0);
|
2012-06-23 02:14:09 +02:00
|
|
|
mTerrain = pTerrain;
|
|
|
|
mAction = TERRAIN_ZOOM;
|
|
|
|
mMouseDown = false;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
lcTerrainView::~lcTerrainView()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
delete mCamera;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::OnInitialUpdate()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
MakeCurrent();
|
2011-09-07 23:06:51 +02:00
|
|
|
|
|
|
|
float ambient [] = {0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
float diffuse [] = {0.8f, 0.9f, 0.6f, 1.0f};
|
|
|
|
float specular[] = {0.0f, 0.0f, 0.0f, 1.0f};
|
|
|
|
float position[] = {0.0f, 5.0f,15.0f, 0.0f};
|
|
|
|
|
|
|
|
glShadeModel(GL_SMOOTH);
|
|
|
|
|
|
|
|
glEnable(GL_LIGHTING);
|
|
|
|
glEnable(GL_LIGHT0);
|
|
|
|
|
|
|
|
glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);
|
|
|
|
glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);
|
|
|
|
glLightfv(GL_LIGHT0, GL_SPECULAR, specular);
|
|
|
|
glLightfv(GL_LIGHT0, GL_POSITION, position);
|
|
|
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
|
|
|
glEnable(GL_COLOR_MATERIAL);
|
|
|
|
glEnable(GL_CULL_FACE);
|
2012-06-23 02:14:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void lcTerrainView::OnDraw()
|
|
|
|
{
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
|
float aspect = (float)m_nWidth/(float)m_nHeight;
|
|
|
|
glViewport(0, 0, m_nWidth, m_nHeight);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
mCamera->LoadProjection(aspect);
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
mTerrain->Render(mCamera, aspect);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::OnLeftButtonDown(int x, int y, bool Control, bool Shift)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
mMouseX = x;
|
|
|
|
mMouseY = y;
|
|
|
|
mMouseDown = true;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
CaptureMouse();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::OnLeftButtonUp(int x, int y, bool Control, bool Shift)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
mMouseDown = false;
|
|
|
|
|
|
|
|
ReleaseCapture();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::OnMouseMove(int x, int y, bool Control, bool Shift)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
if (!mMouseDown)
|
|
|
|
return;
|
2011-09-07 23:06:51 +02:00
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
switch (mAction)
|
|
|
|
{
|
|
|
|
case TERRAIN_ZOOM:
|
|
|
|
mCamera->DoZoom(y - mMouseY, 11, 1, false, false);
|
|
|
|
Redraw();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TERRAIN_PAN:
|
|
|
|
mCamera->DoPan(x - mMouseX, y - mMouseY, 11, 1, false, false);
|
|
|
|
Redraw();
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TERRAIN_ROTATE:
|
|
|
|
if (mMouseX != x || mMouseY != y)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
|
|
|
float center[3] = { 0,0,0 };
|
2012-06-23 02:14:09 +02:00
|
|
|
mCamera->DoRotate(x - mMouseX, y - mMouseY, 11, 1, false, false, center);
|
|
|
|
Redraw();
|
|
|
|
}
|
|
|
|
break;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
mMouseX = x;
|
|
|
|
mMouseY = y;
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-10-12 20:21:45 +02:00
|
|
|
void lcTerrainView::LoadTexture()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
MakeCurrent();
|
2012-10-12 20:21:45 +02:00
|
|
|
mTerrain->LoadTexture();
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::ResetCamera()
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
delete mCamera;
|
2012-08-22 03:13:32 +02:00
|
|
|
mCamera = new Camera(20, 20, 20, 0, 0, 0);
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|
|
|
|
|
2012-06-23 02:14:09 +02:00
|
|
|
void lcTerrainView::SetAction(int Action)
|
2011-09-07 23:06:51 +02:00
|
|
|
{
|
2012-06-23 02:14:09 +02:00
|
|
|
mAction = Action;
|
|
|
|
|
|
|
|
switch (mAction)
|
|
|
|
{
|
|
|
|
case TERRAIN_ZOOM:
|
|
|
|
SetCursor(LC_CURSOR_ZOOM);
|
|
|
|
break;
|
|
|
|
case TERRAIN_PAN:
|
|
|
|
SetCursor(LC_CURSOR_PAN);
|
|
|
|
break;
|
|
|
|
case TERRAIN_ROTATE:
|
|
|
|
SetCursor(LC_CURSOR_ROTATE_VIEW);
|
|
|
|
break;
|
|
|
|
}
|
2011-09-07 23:06:51 +02:00
|
|
|
}
|