
Added the DDS Texture Loading for future use Added the gamepad class for future use Added first child method to the scenegraph Added RGB to intensity and lerp methods to the shared methods class Added the terrain node class with normals Fixed issue with submeshnode not passing the world transform to the actual meshes
167 lines
4.6 KiB
C++
167 lines
4.6 KiB
C++
#include "Graphics2.h"
|
|
|
|
Graphics2 app;
|
|
|
|
void Graphics2::CreateSceneGraph()
|
|
{
|
|
_boostMultiplier = 1;
|
|
_flySpeed = 1;
|
|
_turnSpeed = 1;
|
|
_invertPitch = -1;
|
|
|
|
GetCamera()->SetCameraPosition(0.0f, 320.0f, -80.0f);
|
|
|
|
SceneGraphPointer sceneGraph = GetSceneGraph();
|
|
|
|
// This is where you add nodes to the scene graph
|
|
//shared_ptr<TexturedCubeNode> cube = make_shared<TexturedCubeNode>(L"Body", L"Textures\\woodbox.bmp");
|
|
//cube->SetWorldTransform(XMMatrixScaling(5.0f, 8.0f, 2.5f) * XMMatrixTranslation(0, 23.0f, 0));
|
|
//sceneGraph->Add(cube);
|
|
|
|
shared_ptr<TerrainNode> terrainNode = make_shared<TerrainNode>(L"MainTerrain", L"Textures\\Example_HeightMap.raw", 1023, 1023, 10, 10);
|
|
sceneGraph->Add(terrainNode);
|
|
|
|
shared_ptr<SplitMeshNode> node = make_shared<SplitMeshNode>(L"Plane1", L"Models\\Plane\\Bonanza.3DS");
|
|
//shared_ptr<MeshNode> node = make_shared<MeshNode>(L"Plane1", L"Models\\Plane\\Bonanza.3DS");
|
|
node->SetWorldTransform(XMMatrixScaling(0.5f, 0.5f, 0.5f) * XMMatrixTranslation(-30.0f, 320.0f, 0));
|
|
sceneGraph->Add(node);
|
|
|
|
//SetBackgroundColour(XMFLOAT4(0.29f, 0.38f, 0.72f, 1.0f));
|
|
//SetBackgroundColour(XMFLOAT4(SharedMethods::RGBValueToIntensity(0x89), 0, 1, 1));
|
|
|
|
_currentRotation = 0;
|
|
_currentSideRotation = 0;
|
|
_currentPropRotation = 0;
|
|
}
|
|
|
|
void Graphics2::UpdateSceneGraph()
|
|
{
|
|
GetCurrentControlInputs();
|
|
|
|
SceneGraphPointer sceneGraph = GetSceneGraph();
|
|
|
|
for (ControlInputs currentControl : _currentInputs)
|
|
{
|
|
switch (currentControl)
|
|
{
|
|
case ControlInputs::Forward:
|
|
GetCamera()->SetForwardBack(_flySpeed * _boostMultiplier);
|
|
break;
|
|
case ControlInputs::Back:
|
|
GetCamera()->SetForwardBack(-_flySpeed * _boostMultiplier);
|
|
break;
|
|
case ControlInputs::StrafeLeft:
|
|
GetCamera()->SetLeftRight(-_flySpeed * _boostMultiplier);
|
|
break;
|
|
case ControlInputs::StrafeRight:
|
|
GetCamera()->SetLeftRight(_flySpeed * _boostMultiplier);
|
|
break;
|
|
case ControlInputs::TurnLeft:
|
|
GetCamera()->SetYaw(-_turnSpeed);
|
|
break;
|
|
case ControlInputs::TurnRight:
|
|
GetCamera()->SetYaw(_turnSpeed);
|
|
break;
|
|
case ControlInputs::Up:
|
|
GetCamera()->SetPitch(_turnSpeed * _invertPitch);
|
|
break;
|
|
case ControlInputs::Down:
|
|
GetCamera()->SetPitch(-_turnSpeed * _invertPitch);
|
|
break;
|
|
}
|
|
}
|
|
|
|
SceneNodePointer plane1 = sceneGraph->Find(L"Plane1");
|
|
|
|
plane1->GetFirstChild()->SetWorldTransform(SharedMethods::RotateFromPoint(-60.0f, 0, 0, XMMatrixRotationAxis(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), _currentRotation * XM_PI / 180.0f)));
|
|
plane1 ->GetFirstChild()->AddToWorldTransform(XMMatrixRotationAxis(XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f), 90.0f * XM_PI / 180.0f));
|
|
//sceneGraph->Find(L"Plane1")->GetFirstChild()->GetFirstChild()->SetWorldTransform(XMMatrixRotationAxis(XMVectorSet(0.0f, -1.0f, -1.0f, 0.0f), _currentSideRotation * XM_PI / 180.0f));
|
|
|
|
//sceneGraph->Find(L"Plane1")->Update((SharedMethods::RotateFromPoint(30.0f, -20.0f, 0, XMMatrixRotationAxis(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), _currentSideRotation * XM_PI / 180.0f))) * XMMatrixRotationAxis(XMVectorSet(0.0f, -1.0f, 0.0f, 0.0f), _currentRotation * XM_PI / 180.0f));
|
|
|
|
plane1->Find(L"airscrew")->SetWorldTransform(SharedMethods::RotateFromPoint(0.0f, 15.471f, 14.5f, XMMatrixRotationAxis(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), _currentPropRotation * XM_PI / 180.0f)));
|
|
|
|
if (_currentRotation == 360)
|
|
{
|
|
_currentRotation = 0;
|
|
_currentSideRotation = 0;
|
|
_currentPropRotation = 0;
|
|
}
|
|
else
|
|
{
|
|
_currentRotation += 1;
|
|
_currentSideRotation += 1;
|
|
_currentPropRotation += 100;
|
|
}
|
|
|
|
ResetCurrentControlInputs();
|
|
}
|
|
|
|
void Graphics2::GetCurrentControlInputs()
|
|
{
|
|
// Check if the window has focus before accepting any keypresses
|
|
if (GetForegroundWindow() == Framework::GetHWnd())
|
|
{
|
|
if (GetAsyncKeyState(VK_SHIFT))
|
|
{
|
|
_boostMultiplier = 2;
|
|
}
|
|
else
|
|
{
|
|
_boostMultiplier = 1;
|
|
}
|
|
|
|
// Forward
|
|
if (GetAsyncKeyState(0x57))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::Forward);
|
|
}
|
|
|
|
// Back
|
|
if (GetAsyncKeyState(0x53))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::Back);
|
|
}
|
|
|
|
// Turn Left
|
|
if (GetAsyncKeyState(0x41))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::TurnLeft);
|
|
}
|
|
|
|
// Turn Right
|
|
if (GetAsyncKeyState(0x44))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::TurnRight);
|
|
}
|
|
|
|
// Strafe Left
|
|
if (GetAsyncKeyState(0x51))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::StrafeLeft);
|
|
}
|
|
|
|
// Strafe Right
|
|
if (GetAsyncKeyState(0x45))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::StrafeRight);
|
|
}
|
|
|
|
// "Jump"
|
|
if (GetAsyncKeyState(VK_SPACE))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::Up);
|
|
}
|
|
|
|
// "Crouch"
|
|
if (GetAsyncKeyState(VK_CONTROL))
|
|
{
|
|
_currentInputs.push_back(ControlInputs::Down);
|
|
}
|
|
}
|
|
}
|
|
|
|
void Graphics2::ResetCurrentControlInputs()
|
|
{
|
|
_currentInputs.clear();
|
|
} |