Files
directx-plane-game/Graphics2/Graphics2.cpp
iDunnoDev bc906064e5 Added color gradient for the terrain blend maps
Added terrainBuffer struct
Added shared methods to genereate random UV's and intensities
Added water to the terrain
Added random UV's to the shader
Removed the vector3d class since DX can deal with that stuff...
2022-05-04 14:09:59 +01:00

172 lines
5.0 KiB
C++

#include "Graphics2.h"
Graphics2 app;
void Graphics2::CreateSceneGraph()
{
_boostMultiplier = 1;
_flySpeed = 1;
_turnSpeed = 1;
_invertPitch = -1;
GetCamera()->SetCameraPosition(0.0f, 550.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", L"lovelycat");
terrainNode->SetAmbientLight(XMFLOAT4(0.7f, 0.7f, 0.7f, 1.0f));
terrainNode->SetDirectionalLight(XMVectorSet(0.5f, -1.0f, -1.0f, 0.0f), XMFLOAT4(1.0f, 1.0f, 1.0f, 1.0f));
terrainNode->SetWaterColor(XMFLOAT4(SharedMethods::RGBValueToIntensity(0xA4), SharedMethods::RGBValueToIntensity(0xC1), SharedMethods::RGBValueToIntensity(0xF9), 1.0f));
//terrainNode->SetWaterColor(XMFLOAT4(1.0f, 0.0f, 0.8f, 1.0f));
//terrainNode->SetWaterColor(XMFLOAT4(0.0f, 0.0f, 1.0f, 1.0f));
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(XMMatrixTranslation(-30.0f, 520.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();
}