Fixed boats rotation

This commit is contained in:
iDunnoDev
2022-05-30 00:25:14 +01:00
committed by iDunnoDev
parent eeec232821
commit 51afdeecbd
5 changed files with 25 additions and 25 deletions

View File

@ -6,8 +6,8 @@ ControlledMeshNode::ControlledMeshNode(wstring name, wstring modelName) : MeshNo
void ControlledMeshNode::Update(FXMMATRIX& currentWorldTransformation) void ControlledMeshNode::Update(FXMMATRIX& currentWorldTransformation)
{ {
ObjectNode::Update(_worldTransformation);
MeshNode::Update(currentWorldTransformation); MeshNode::Update(currentWorldTransformation);
ObjectNode::Update(_worldTransformation);
} }
bool ControlledMeshNode::Initialise(void) bool ControlledMeshNode::Initialise(void)

View File

@ -24,7 +24,7 @@ void Graphics2::CreateSceneGraph()
DirectXFramework::GetDXFramework()->GetGlobalLighting()->SetAmbientLight(XMFLOAT4(0.7f, 0.7f, 0.7f, 1.0f)); DirectXFramework::GetDXFramework()->GetGlobalLighting()->SetAmbientLight(XMFLOAT4(0.7f, 0.7f, 0.7f, 1.0f));
DirectXFramework::GetDXFramework()->GetGlobalLighting()->SetDirectionalLight(XMVectorSet(0.5f, -1.0f, -1.0f, 0.0f), XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f)); DirectXFramework::GetDXFramework()->GetGlobalLighting()->SetDirectionalLight(XMVectorSet(0.5f, -1.0f, -1.0f, 0.0f), XMFLOAT4(0.5f, 0.5f, 0.5f, 1.0f));
shared_ptr<SkyNode> skyDome = make_shared<SkyNode>(L"SkyDome", L"Textures\\SkyWater.dds", 30.0f); shared_ptr<SkyNode> skyDome = make_shared<SkyNode>(L"SkyDome", L"Textures\\SkyWater.dds", 180.0f);
sceneGraph->Add(skyDome); sceneGraph->Add(skyDome);
//shared_ptr<HeightMapTerrainNode> terrainNode = make_shared<HeightMapTerrainNode>(L"MainTerrain", L"Textures\\Example_HeightMap.raw", L"RandomWords"); //shared_ptr<HeightMapTerrainNode> terrainNode = make_shared<HeightMapTerrainNode>(L"MainTerrain", L"Textures\\Example_HeightMap.raw", L"RandomWords");
@ -42,10 +42,10 @@ void Graphics2::CreateSceneGraph()
sceneGraph->Add(plane1Node); sceneGraph->Add(plane1Node);
shared_ptr<SceneGraph> boatGraph = make_shared<SceneGraph>(L"boatGraph"); shared_ptr<SceneGraph> boatGraph = make_shared<SceneGraph>(L"boatGraph");
boatGraph->SetWorldTransform(XMMatrixScaling(0.1f, 0.1f, 0.1f) * XMMatrixTranslation(-1840.0f, 290.0f, 699.0f)); boatGraph->SetWorldTransform(XMMatrixScaling(0.1f, 0.1f, 0.1f) * XMMatrixTranslation(-1880.0f, 290.0f, 610.0f));
shared_ptr<ControlledMeshNode> boat1Node = make_shared<ControlledMeshNode>(L"Boat1", L"Models\\Boat\\Boat.FBX"); shared_ptr<ControlledMeshNode> boat1Node = make_shared<ControlledMeshNode>(L"Boat1", L"Models\\Boat\\Boat.FBX");
boat1Node->SetStartOrientation(XMMatrixRotationAxis(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), XM_PI) * XMMatrixRotationAxis(XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f), 0.5f * XM_PI)); boat1Node->SetStartOrientation(XMMatrixRotationAxis(XMVectorSet(0.0f, 0.0f, 1.0f, 0.0f), (90.0f * XM_PI) / 180.0f) * XMMatrixRotationAxis(XMVectorSet(1.0f, 0.0f, 0.0f, 0.0f), (90.0f * XM_PI) / 180.0f));
boat1Node->SetNodePosition(0.0f, 0.0f, 0.0f); boat1Node->SetNodePosition(0.0f, 0.0f, 0.0f);
boatGraph->Add(boat1Node); boatGraph->Add(boat1Node);
@ -194,6 +194,7 @@ void Graphics2::UpdateSceneGraph()
if (_currentPlayerObject != nullptr) if (_currentPlayerObject != nullptr)
{ {
_currentPlayerObject->SetForwardBack(_flySpeed * _boostMultiplier); _currentPlayerObject->SetForwardBack(_flySpeed * _boostMultiplier);
startCameraPos = _currentPlayerObject->GetNodePosition();
} }
for (ControlInputs currentControl : _currentInputs) for (ControlInputs currentControl : _currentInputs)
@ -215,7 +216,8 @@ void Graphics2::UpdateSceneGraph()
case ControlInputs::StrafeLeft: case ControlInputs::StrafeLeft:
if (_currentPlayerObject != nullptr) if (_currentPlayerObject != nullptr)
{ {
_currentPlayerObject->SetLeftRight(-_flySpeed * _boostMultiplier); //_currentPlayerObject->SetLeftRight(-_flySpeed * _boostMultiplier);
_currentPlayerObject->SetRoll(_turnSpeed * 0.5f);
} }
else else
{ {
@ -225,7 +227,8 @@ void Graphics2::UpdateSceneGraph()
case ControlInputs::StrafeRight: case ControlInputs::StrafeRight:
if (_currentPlayerObject != nullptr) if (_currentPlayerObject != nullptr)
{ {
_currentPlayerObject->SetLeftRight(_flySpeed * _boostMultiplier); //_currentPlayerObject->SetLeftRight(_flySpeed * _boostMultiplier);
_currentPlayerObject->SetRoll(-_turnSpeed * 0.5f);
} }
else else
{ {
@ -236,7 +239,6 @@ void Graphics2::UpdateSceneGraph()
if (_currentPlayerObject != nullptr) if (_currentPlayerObject != nullptr)
{ {
_currentPlayerObject->SetYaw(-_turnSpeed); _currentPlayerObject->SetYaw(-_turnSpeed);
//_currentPlayerObject->SetTotalRoll(_turnSpeed * 0.5f);
} }
else else
{ {
@ -247,7 +249,6 @@ void Graphics2::UpdateSceneGraph()
if (_currentPlayerObject != nullptr) if (_currentPlayerObject != nullptr)
{ {
_currentPlayerObject->SetYaw(_turnSpeed); _currentPlayerObject->SetYaw(_turnSpeed);
//_currentPlayerObject->SetTotalRoll(-_turnSpeed * 0.5f);
} }
else else
{ {
@ -292,8 +293,8 @@ void Graphics2::UpdateSceneGraph()
if (boat1 != nullptr) if (boat1 != nullptr)
{ {
boat1->SetForwardBack(10.0f); boat1->SetForwardBack(-3.0f);
boat1->SetYaw(-1.0f); boat1->SetYaw(-0.2f);
} }
if (_currentRotation == 360) if (_currentRotation == 360)
@ -306,18 +307,16 @@ void Graphics2::UpdateSceneGraph()
{ {
_currentRotation += 1; _currentRotation += 1;
_currentSideRotation += 1; _currentSideRotation += 1;
if (_currentPlayerObject == nullptr || !_boosting) _currentPropRotation += 10 * _boostMultiplier;
{
_currentPropRotation += 50;
}
else
{
_currentPropRotation += 100;
}
} }
// Check the camera and our terrain boundaries // Check the camera and our terrain boundaries
XMVECTOR currentCameraPos = GetCamera()->GetCameraPosition(); XMVECTOR currentCameraPos = GetCamera()->GetCameraPosition();
if (_currentPlayerObject != nullptr)
{
currentCameraPos = _currentPlayerObject->GetNodePosition();
}
GetCamera()->Update(); GetCamera()->Update();
if (mainTerrain != nullptr) if (mainTerrain != nullptr)
{ {

Binary file not shown.

View File

@ -21,7 +21,7 @@ bool SkyNode::Initialise()
return false; return false;
} }
CreateSphere(_skyRadius, 180); CreateSphere(_skyRadius, 360);
GenerateBuffers(); GenerateBuffers();
BuildShaders(); BuildShaders();
BuildVertexLayout(); BuildVertexLayout();

View File

@ -529,6 +529,7 @@ void TerrainNode::PopulateTerrain(SceneGraphPointer currentSceneGraph, vector<Te
} }
float scale = (rand() % 100 * 0.01f) * nodesForPop[nodeIndex].scaleFactor; float scale = (rand() % 100 * 0.01f) * nodesForPop[nodeIndex].scaleFactor;
float yRotation = rand() % 360;
float xPos = x * _cellSizeX + _terrainStartX; float xPos = x * _cellSizeX + _terrainStartX;
float yPos = heightValue; float yPos = heightValue;
@ -536,7 +537,7 @@ void TerrainNode::PopulateTerrain(SceneGraphPointer currentSceneGraph, vector<Te
wstring nodeName = L"_" + to_wstring(z) + L"_" + to_wstring(x); wstring nodeName = L"_" + to_wstring(z) + L"_" + to_wstring(x);
shared_ptr<MeshNode> newNode = make_shared<MeshNode>(nodesForPop[nodeIndex].nodeBaseName + nodeName, nodesForPop[nodeIndex].modelName); shared_ptr<MeshNode> newNode = make_shared<MeshNode>(nodesForPop[nodeIndex].nodeBaseName + nodeName, nodesForPop[nodeIndex].modelName);
newNode->SetWorldTransform(XMMatrixScaling(scale, scale, scale) * XMMatrixTranslation(xPos, yPos, zPos)); newNode->SetWorldTransform(XMMatrixRotationAxis(XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f), yRotation * XM_PI / 180.0f) * XMMatrixScaling(scale, scale, scale) * XMMatrixTranslation(xPos, yPos, zPos));
currentSceneGraph->Add(newNode); currentSceneGraph->Add(newNode);
} }
} }