Skip to content

Commit

Permalink
DirectXMath: Smaller changes in D2DEditorView, GothicAPI, more
Browse files Browse the repository at this point in the history
  • Loading branch information
kirides committed Mar 1, 2020
1 parent a5d1af5 commit c3f7b11
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 131 deletions.
24 changes: 12 additions & 12 deletions D3D11Engine/D2DEditorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "Widget_TransRot.h"
#include "WidgetContainer.h"

using namespace DirectX;

D2DEditorView::D2DEditorView(D2DView * view, D2DSubView * parent) : D2DSubView(view, parent)
{
InitControls();
Expand Down Expand Up @@ -476,15 +478,15 @@ void D2DEditorView::Update(float deltaTime)
/** Handles vegetation removing */
void D2DEditorView::DoVegetationRemove()
{
D3DXVECTOR3 wDir = Engine::GAPI->UnprojectCursor();
XMFLOAT3 wDir; XMStoreFloat3(&wDir, Engine::GAPI->UnprojectCursorXM());
D3DXVECTOR3 hit;
D3DXVECTOR3 hitTri[3];

float removeRange = 250.0f * (1.0f + MMWDelta * 0.01f);

if (Selection.SelectedVegetationBox)
{
if (Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), wDir, hit, nullptr, hitTri))
if (Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir, hit, nullptr, hitTri))
{
D3DXVECTOR4 p;
D3DXVec3Cross((D3DXVECTOR3 *)&p, &(hitTri[1] - hitTri[0]), &(hitTri[2] - hitTri[0]));
Expand Down Expand Up @@ -519,7 +521,7 @@ void D2DEditorView::DoVegetationRemove()
/** Handles vegetationbox placement */
void D2DEditorView::DoVegetationPlacement()
{
D3DXVECTOR3 wDir = Engine::GAPI->UnprojectCursor();
XMFLOAT3 wDir; XMStoreFloat3(&wDir, Engine::GAPI->UnprojectCursorXM());
D3DXVECTOR3 hit;
D3DXVECTOR3 hitTri[3];

Expand All @@ -531,7 +533,7 @@ void D2DEditorView::DoVegetationPlacement()
rtp = &TracedTexture;

// Trace the worldmesh from the cursor
if (Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), wDir, hit, rtp, hitTri))
if (Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir, hit, rtp, hitTri))
{
// Update the position if successful
DraggedBoxCenter = hit;
Expand Down Expand Up @@ -562,7 +564,7 @@ GVegetationBox* D2DEditorView::FindVegetationFromMeshInfo(MeshInfo * info)
/** Handles selection */
void D2DEditorView::DoSelection()
{
D3DXVECTOR3 wDir = Engine::GAPI->UnprojectCursor();
XMFLOAT3 wDir; XMStoreFloat3(&wDir, Engine::GAPI->UnprojectCursorXM());
D3DXVECTOR3 hitVob(FLT_MAX,FLT_MAX,FLT_MAX), hitSkel(FLT_MAX,FLT_MAX,FLT_MAX), hitWorld(FLT_MAX,FLT_MAX,FLT_MAX);
D3DXVECTOR3 hitTri[3];
MeshInfo * hitMesh;
Expand All @@ -577,19 +579,19 @@ void D2DEditorView::DoSelection()
TracedMaterial = nullptr;

// Trace mesh-less vegetationboxes
TracedVegetationBox = TraceVegetationBoxes(Engine::GAPI->GetCameraPosition(), wDir);
TracedVegetationBox = TraceVegetationBoxes(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir);
if (TracedVegetationBox)
{
TracedVegetationBox->VisualizeGrass(D3DXVECTOR4(1, 1, 1, 1));
return;
}

// Trace vobs
tVob = Engine::GAPI->TraceStaticMeshVobsBB(Engine::GAPI->GetCameraPosition(), wDir, hitVob, &hitMaterialVob);
tSkelVob = Engine::GAPI->TraceSkeletalMeshVobsBB(Engine::GAPI->GetCameraPosition(), wDir, hitSkel);
tVob = Engine::GAPI->TraceStaticMeshVobsBB(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir, hitVob, &hitMaterialVob);
tSkelVob = Engine::GAPI->TraceSkeletalMeshVobsBB(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir, hitSkel);

// Trace the worldmesh from the cursor
Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), wDir, hitWorld, &TracedTexture, hitTri, &hitMesh, &hitMaterial);
Engine::GAPI->TraceWorldMesh(Engine::GAPI->GetCameraPosition(), *(D3DXVECTOR3*)&wDir, hitWorld, &TracedTexture, hitTri, &hitMesh, &hitMaterial);

float lenVob = D3DXVec3Length(&(Engine::GAPI->GetCameraPosition()-hitVob));
float lenSkel = D3DXVec3Length(&(Engine::GAPI->GetCameraPosition()-hitSkel));
Expand Down Expand Up @@ -1026,9 +1028,7 @@ void D2DEditorView::DoEditorMovement()
zCCamera::GetCamera()->Activate();

// Update GAPI
D3DXMATRIX view;
Engine::GAPI->GetViewMatrix(&view);
Engine::GAPI->SetViewTransform(view);
Engine::GAPI->SetViewTransformXM(Engine::GAPI->GetViewMatrixXM());
}

/** Returns if the mouse is inside the editor window */
Expand Down
4 changes: 1 addition & 3 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1202,8 +1202,6 @@ XRESULT D3D11GraphicsEngine::DrawSkeletalMesh(
InfiniteRangeConstantBuffer->BindToPixelShader(3);

const auto& world = Engine::GAPI->GetRendererState()->TransformState.TransformWorld;
const auto& view = Engine::GAPI->GetRendererState()->TransformState.TransformView;
const auto& proj = Engine::GAPI->GetProjectionMatrix();

SetupVS_ExMeshDrawCall();
SetupVS_ExConstantBuffer();
Expand Down Expand Up @@ -5295,7 +5293,7 @@ void D3D11GraphicsEngine::DrawQuadMarks() {
UpdateRenderStates();
}

Engine::GAPI->SetWorldTransform(*it.first->GetConnectedVob()->GetWorldMatrixPtr());
Engine::GAPI->SetWorldTransformXM(it.first->GetConnectedVob()->GetWorldMatrixXM());
SetupVS_ExPerInstanceConstantBuffer();

Engine::GraphicsEngine->DrawVertexBuffer(it.second.Mesh,
Expand Down
11 changes: 4 additions & 7 deletions D3D11Engine/D3D11LineRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
#include "GothicAPI.h"
#include "D3D11VertexBuffer.h"

using namespace DirectX;

D3D11LineRenderer::D3D11LineRenderer()
{
LineBuffer = nullptr;
Expand Down Expand Up @@ -54,13 +56,8 @@ XRESULT D3D11LineRenderer::Flush()
XLE(LineBuffer->UpdateBuffer(&LineCache[0], LineCache.size() * sizeof(LineVertex)));
}

D3DXMATRIX world;
D3DXMatrixIdentity(&world);
Engine::GAPI->SetWorldTransform(world);

D3DXMATRIX view;
Engine::GAPI->GetViewMatrix(&view);
Engine::GAPI->SetViewTransform(view);
Engine::GAPI->SetWorldTransformXM(XMMatrixIdentity());
Engine::GAPI->SetViewTransformXM(Engine::GAPI->GetViewMatrixXM());

engine->SetActivePixelShader("PS_Lines");
engine->SetActiveVertexShader("VS_Lines");
Expand Down
2 changes: 1 addition & 1 deletion D3D11Engine/D3D11NVHBAO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ XRESULT D3D11NVHBAO::Render(ID3D11RenderTargetView* pOutputColorRTV)
GFSDK_SSAO_InputData_D3D11 Input;
Input.DepthData.DepthTextureType = GFSDK_SSAO_HARDWARE_DEPTHS;
Input.DepthData.pFullResDepthTextureSRV = engine->GetDepthBuffer()->GetShaderResView();
Input.DepthData.ProjectionMatrix.Data = GFSDK_SSAO_Float4x4((float*)&Engine::GAPI->GetProjectionMatrix());
Input.DepthData.ProjectionMatrix.Data = GFSDK_SSAO_Float4x4((float*)&Engine::GAPI->GetProjectionMatrixDX());
Input.DepthData.ProjectionMatrix.Layout = GFSDK_SSAO_COLUMN_MAJOR_ORDER;
Input.DepthData.MetersToViewSpaceUnits = settings.MetersToViewSpaceUnits;

Expand Down
6 changes: 3 additions & 3 deletions D3D11Engine/D3D11PFX_HeightFog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ XRESULT D3D11PFX_HeightFog::Render(RenderToTextureBuffer * fxbuffer)

HeightfogConstantBuffer cb;
XMMATRIX xmInvProj;
xmInvProj = XMLoadFloat4x4(&D3DXMatToDX(Engine::GAPI->GetProjectionMatrix()));
xmInvProj = XMLoadFloat4x4(&Engine::GAPI->GetProjectionMatrixDX());
xmInvProj = XMMatrixInverse(nullptr, xmInvProj);
XMStoreFloat4x4(&cb.InvProj, xmInvProj);

Expand Down Expand Up @@ -96,8 +96,8 @@ XRESULT D3D11PFX_HeightFog::Render(RenderToTextureBuffer * fxbuffer)
cb.HF_FogHeight = height;

//cb.HF_FogColorMod = Engine::GAPI->GetRendererState()->GraphicsState.FF_FogColor;
cb.HF_ProjAB = float2( Engine::GAPI->GetProjectionMatrix()._33,
Engine::GAPI->GetProjectionMatrix()._34);
cb.HF_ProjAB = float2( Engine::GAPI->GetProjectionMatrixDX()._33,
Engine::GAPI->GetProjectionMatrixDX()._34);


// Modify fog when raining
Expand Down
82 changes: 1 addition & 81 deletions D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void GothicAPI::OnWorldUpdate() {
RendererState.RendererInfo.NearPlane = zCCamera::GetCamera()->GetNearPlane();

//zCCamera::GetCamera()->Activate();
SetViewTransform(zCCamera::GetCamera()->GetTransform(zCCamera::ETransformType::TT_VIEW), false);
SetViewTransformDX(zCCamera::GetCamera()->GetTransformDX(zCCamera::ETransformType::TT_VIEW), false);
}

// Apply the hints for the sound system to fix voices in indoor locations being quiet
Expand Down Expand Up @@ -1975,38 +1975,18 @@ void GothicAPI::DrawTriangle(float3 pos = { 0.0f,0.0f,0.0f })
delete vxb;
}

/** Sets the Projection matrix */
void GothicAPI::SetProjTransform(const D3DXMATRIX & proj)
{
RendererState.TransformState.TransformProj = (XMFLOAT4X4)proj;
}

/** Sets the Projection matrix */
void GothicAPI::SetProjTransformDX(const DirectX::XMFLOAT4X4& proj)
{
RendererState.TransformState.TransformProj = proj;
}

/** Sets the Projection matrix */
D3DXMATRIX GothicAPI::GetProjTransform()
{
return *(D3DXMATRIX*)&RendererState.TransformState.TransformProj;
}

/** Sets the Projection matrix */
DirectX::XMFLOAT4X4 GothicAPI::GetProjTransformDx()
{
return RendererState.TransformState.TransformProj;
}

/** Sets the world matrix */
void GothicAPI::SetWorldTransform(const D3DXMATRIX & world, bool transpose)
{
if (transpose)
D3DXMatrixTranspose((D3DXMATRIX*)&RendererState.TransformState.TransformWorld, &world);
else
RendererState.TransformState.TransformWorld = (XMFLOAT4X4)world;
}

/** Sets the world matrix */
void __vectorcall GothicAPI::SetWorldTransformXM(XMMATRIX world, bool transpose)
Expand All @@ -2024,14 +2004,6 @@ void GothicAPI::SetWorldTransformDX(const XMFLOAT4X4& world, bool transpose)
else
RendererState.TransformState.TransformWorld = world;
}
/** Sets the world matrix */
void GothicAPI::SetViewTransform(const D3DXMATRIX & view, bool transpose)
{
if (transpose)
D3DXMatrixTranspose((D3DXMATRIX*)&RendererState.TransformState.TransformView, &view);
else
RendererState.TransformState.TransformView = (XMFLOAT4X4)view;
}

/** Sets the world matrix */
void __vectorcall GothicAPI::SetViewTransformXM(XMMATRIX view, bool transpose)
Expand Down Expand Up @@ -2291,26 +2263,6 @@ bool GothicAPI::TraceWorldMesh(const D3DXVECTOR3 & origin, const D3DXVECTOR3 & d
return true;
}

/** Unprojects a pixel-position on the screen */
void GothicAPI::Unproject(const D3DXVECTOR3 & p, D3DXVECTOR3 * worldPos, D3DXVECTOR3 * worldDir)
{
D3DXVECTOR3 u;
D3DXMATRIX proj = GetProjectionMatrix();
D3DXMATRIX invView; GetInverseViewMatrix(&invView);
D3DXMatrixTranspose(&invView, &invView);
D3DXMatrixTranspose(&proj, &proj);

// Convert to screenspace
u.x = (((2 * p.x) / Engine::GraphicsEngine->GetResolution().x) - 1) / proj(0, 0);
u.y = -(((2 * p.y) / Engine::GraphicsEngine->GetResolution().y) - 1) / proj(1, 1);
u.z = 1;

// Transform and output
D3DXVec3TransformCoord(worldPos, &u, &invView);
D3DXVec3Normalize(&u, &u);
D3DXVec3TransformNormal(worldDir, &u, &invView);
}

/** Unprojects a pixel-position on the screen */
void __vectorcall GothicAPI::UnprojectXM(FXMVECTOR p, XMVECTOR& worldPos, XMVECTOR& worldDir)
{
Expand All @@ -2336,17 +2288,6 @@ void __vectorcall GothicAPI::UnprojectXM(FXMVECTOR p, XMVECTOR& worldPos, XMVECT
worldDir = XMVector3TransformCoord(u, invView);
}

/** Unprojects the current cursor */
D3DXVECTOR3 GothicAPI::UnprojectCursor()
{
D3DXVECTOR3 mPos, mDir;
POINT p = GetCursorPosition();

Engine::GAPI->Unproject(D3DXVECTOR3((float)p.x, (float)p.y, 0), &mPos, &mDir);

return mDir;
}

/** Unprojects the current cursor */
XMVECTOR GothicAPI::UnprojectCursorXM()
{
Expand Down Expand Up @@ -2404,17 +2345,6 @@ DirectX::XMMATRIX GothicAPI::GetViewMatrixXM()
return XMLoadFloat4x4(&zCCamera::GetCamera()->GetTransformDX(zCCamera::ETransformType::TT_VIEW));
}

/** Returns the view matrix */
void GothicAPI::GetInverseViewMatrix(D3DXMATRIX * invView)
{
if (CameraReplacementPtr)
{
D3DXMatrixInverse(invView, nullptr, (D3DXMATRIX*)&CameraReplacementPtr->ViewReplacement);
return;
}

*invView = zCCamera::GetCamera()->GetTransform(zCCamera::ETransformType::TT_VIEW_INV);
}
/** Returns the view matrix */
void GothicAPI::GetInverseViewMatrixDX(DirectX::XMFLOAT4X4 * invView)
{
Expand All @@ -2426,16 +2356,6 @@ void GothicAPI::GetInverseViewMatrixDX(DirectX::XMFLOAT4X4 * invView)

*invView = zCCamera::GetCamera()->GetTransformDX(zCCamera::ETransformType::TT_VIEW_INV);
}
/** Returns the projection-matrix */
D3DXMATRIX& GothicAPI::GetProjectionMatrix()
{
if (CameraReplacementPtr)
{
return (D3DXMATRIX&)CameraReplacementPtr->ProjectionReplacement;
}

return (D3DXMATRIX&)RendererState.TransformState.TransformProj;
}

/** Returns the projection-matrix */
DirectX::XMFLOAT4X4& GothicAPI::GetProjectionMatrixDX()
Expand Down
24 changes: 0 additions & 24 deletions D3D11Engine/GothicAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -276,30 +276,18 @@ class GothicAPI {
/** Returns a list of visible particle-effects */
void GetVisibleParticleEffectsList(std::vector<zCVob *> & pfxList);

/** Sets the Projection matrix */
void SetProjTransform(const D3DXMATRIX & proj);

/** Sets the Projection matrix */
void SetProjTransformDX(const DirectX::XMFLOAT4X4& proj);

/** Gets the Projection matrix */
D3DXMATRIX GetProjTransform();

/** Gets the Projection matrix */
DirectX::XMFLOAT4X4 GetProjTransformDx();

/** Sets the world matrix */
void SetWorldTransform(const D3DXMATRIX & world, bool transpose = false);

/** Sets the world matrix */
void __vectorcall SetWorldTransformXM(DirectX::XMMATRIX world, bool transpose = false);

/** Sets the world matrix */
void SetWorldTransformDX(const DirectX::XMFLOAT4X4& world, bool transpose = false);

/** Sets the world matrix */
void SetViewTransform(const D3DXMATRIX & view, bool transpose = false);

/** Sets the world matrix */
void __vectorcall SetViewTransformXM(DirectX::XMMATRIX view, bool transpose = false);

Expand Down Expand Up @@ -357,27 +345,15 @@ class GothicAPI {
void GetViewMatrix(D3DXMATRIX * view);
DirectX::XMMATRIX GetViewMatrixXM();

/** Returns the view matrix */
void GetInverseViewMatrix(D3DXMATRIX * invView);

/** Returns the view matrix */
void GetInverseViewMatrixDX(DirectX::XMFLOAT4X4 * invView);

/** Returns the projection-matrix */
D3DXMATRIX& GetProjectionMatrix();

/** Returns the projection-matrix */
DirectX::XMFLOAT4X4& GetProjectionMatrixDX();

/** Unprojects a pixel-position on the screen */
void Unproject(const D3DXVECTOR3 & p, D3DXVECTOR3 * worldPos, D3DXVECTOR3 * worldDir);

/** Unprojects a pixel-position on the screen */
void __vectorcall UnprojectXM(DirectX::FXMVECTOR p, DirectX::XMVECTOR& worldPos, DirectX::XMVECTOR& worldDir);

/** Unprojects the current cursor, returns it's direction in world-space */
D3DXVECTOR3 UnprojectCursor();

/** Unprojects the current cursor, returns it's direction in world-space */
DirectX::XMVECTOR UnprojectCursorXM();

Expand Down

0 comments on commit c3f7b11

Please sign in to comment.