// TestScene.cpp: implementation of the CTestScene class.
//
//////////////////////////////////////////////////////////////////////
#include <math.h>
#include "application.h"
#include "TestScene.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CTestScene::CTestScene()
: pText(NULL),
pHelpText(NULL),
pCube(NULL),
pPyramid(NULL),
pDisk(NULL),
bShowHelp(true)
{
}
CTestScene::~CTestScene()
{
OutputDebugString("CTestScene destructor\n");
}
bool CTestScene::Init()
{
pApp->pLog->Log("CTestScene::Init");
glShadeModel(GL_SMOOTH); // Enable Smooth Shading
glClearColor(0.0f, 0.0f, 0.0f, 0.5f); // Black Background
glClearDepth(1.0f); // Depth Buffer Setup
glEnable(GL_DEPTH_TEST); // Enables Depth Testing
glDepthFunc(GL_LEQUAL); // The Type Of Depth Testing To Do
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
// add some light
pLight = new CLight();
// init text-output, font is set in construtor
pText = new CFloatingText();
// help text
pHelpText = new CTextHelp();
// a nice cube
pCube = new CTexturedCube("data/mud.bmp");
pCube->SetPosition(1.5, 1.0, -7.0);
// modify the width, height and depth as wished
// default is 1.0 for all sides
//pCube->SetSize(1.0, 0.5, 1.0);
// a prisma
pPyramid = new CPyramid();
pPyramid->SetPosition(-1.2f, 1.0f, -6.0f);
// the floor
pFloor = new CFloor();
pFloor->SetPosition(0.0, -1.0, 0.0);
// a disk
pDisk = new CDisk();
pDisk->SetPosition(0.0f, -.2f, 0.0);
return TRUE; // Initialization Went OK
}
void CTestScene::Update()
{
static GLfloat rtri=0.0, rquad=0.0;
Clear();
pCamera->Draw();
// draw the floating text
pText->Draw();
// draw the help text
if (bShowHelp)
pHelpText->Draw();
// set new rotation value
pCube->SetRotation(rquad);
//update
pCube->Draw();
pPyramid->SetRotation(rtri, -0.2f, 1.0f, 0.0f);
pPyramid->Draw();
pFloor->Draw();
pDisk->Draw();
// update variables
rtri+=0.2f; // Increase The Rotation Variable For The Triangle ( NEW )
rquad-=0.15f; // Decrease The Rotation Variable For The Quad ( NEW )
}
void CTestScene::ProcessInput()
{
if (pApp->pInput->IsKeyDown(VK_ESCAPE)) // Was ESC Pressed?
{
pApp->pInput->SetKey(VK_ESCAPE, false);
pApp->pLog->Log("Got ESC - finishing");
// application should end
pApp->ShouldEnd();
}
else if (pApp->pInput->IsKeyDown(VK_SPACE))
{
// toggle textured mode on and off
pCube->ToggleTextures();
pPyramid->ToggleTextures();
pFloor->ToggleTextures();
}
else if (pApp->pInput->IsKeyDown('h') || pApp->pInput->IsKeyDown('H'))
{
Toggle(bShowHelp);
}
else if (pApp->pInput->IsKeyDown(VK_LEFT))
pCamera->Move(-0.05f, .0f, .0f);
else if (pApp->pInput->IsKeyDown(VK_RIGHT))
pCamera->Move(0.05f, .0f, .0f);
else if (pApp->pInput->IsKeyDown(VK_UP))
pCamera->Move(.0f, .05f, .0f);
else if (pApp->pInput->IsKeyDown(VK_DOWN))
pCamera->Move(.0f, -.05f, .0f);
else if (pApp->pInput->IsKeyDown(VK_END))
pCamera->Move(.0f, .0f, -.05f);
else if (pApp->pInput->IsKeyDown(VK_HOME))
pCamera->Move(.0f, .0f, .05f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD1))
pCamera->Look(-.05f, .0f, .0f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD2))
pCamera->Look(.05f, .0f, .0f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD3))
pCamera->Look(.0f, -.05f, .0f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD6))
pCamera->Look(.0f, .05f, .0f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD4))
pCamera->Look(.0f, .0f, -.05f);
else if (pApp->pInput->IsKeyDown(VK_NUMPAD5))
pCamera->Look(.0f, .0f, .05f);
pApp->pInput->Reset();
}