Commit 18dd6edb authored by chili's avatar chili
Browse files

camera with control window

parent 13abbb1e
......@@ -77,13 +77,13 @@ App::App()
std::generate_n( std::back_inserter( drawables ),nDrawables,Factory{ wnd.Gfx() } );
wnd.Gfx().SetProjection( dx::XMMatrixPerspectiveLH( 1.0f,3.0f / 4.0f,0.5f,40.0f ) );
wnd.Gfx().SetCamera( dx::XMMatrixTranslation( 0.0f,0.0f,20.0f ) );
}
void App::DoFrame()
{
const auto dt = timer.Mark() * speed_factor;
wnd.Gfx().BeginFrame( 0.07f,0.0f,0.12f );
wnd.Gfx().SetCamera( cam.GetMatrix() );
for( auto& d : drawables )
{
......@@ -96,9 +96,11 @@ void App::DoFrame()
{
ImGui::SliderFloat( "Speed Factor",&speed_factor,0.0f,4.0f );
ImGui::Text( "%.3f ms/frame (%.1f FPS)",1000.0f / ImGui::GetIO().Framerate,ImGui::GetIO().Framerate );
ImGui::Text( "Status: %s",wnd.kbd.KeyIsPressed( VK_SPACE ) ? "PAUSED" : "RUNNING" );
ImGui::Text( "Status: %s",wnd.kbd.KeyIsPressed( VK_SPACE ) ? "PAUSED" : "RUNNING (hold spacebar to pause)" );
}
ImGui::End();
// imgui window to control camera
cam.SpawnControlWindow();
// present
wnd.Gfx().EndFrame();
......
......@@ -2,6 +2,7 @@
#include "Window.h"
#include "ChiliTimer.h"
#include "ImguiManager.h"
#include "Camera.h"
class App
{
......@@ -18,5 +19,6 @@ private:
ChiliTimer timer;
std::vector<std::unique_ptr<class Drawable>> drawables;
float speed_factor = 1.0f;
Camera cam;
static constexpr size_t nDrawables = 180;
};
\ No newline at end of file
#include "Camera.h"
#include "imgui/imgui.h"
namespace dx = DirectX;
DirectX::XMMATRIX Camera::GetMatrix() const noexcept
{
const auto pos = dx::XMVector3Transform(
dx::XMVectorSet( 0.0f,0.0f,-r,0.0f ),
dx::XMMatrixRotationRollPitchYaw( phi,-theta,0.0f )
);
return dx::XMMatrixLookAtLH(
pos,dx::XMVectorZero(),
dx::XMVectorSet( 0.0f,1.0f,0.0f,0.0f )
) * dx::XMMatrixRotationRollPitchYaw(
pitch,-yaw,roll
);
}
void Camera::SpawnControlWindow() noexcept
{
if( ImGui::Begin( "Camera" ) )
{
ImGui::Text( "Position" );
ImGui::SliderFloat( "R",&r,0.0f,80.0f,"%.1f" );
ImGui::SliderAngle( "Theta",&theta,-180.0f,180.0f );
ImGui::SliderAngle( "Phi",&phi,-89.0f,89.0f );
ImGui::Text( "Orientation" );
ImGui::SliderAngle( "Roll",&roll,-180.0f,180.0f );
ImGui::SliderAngle( "Pitch",&pitch,-180.0f,180.0f );
ImGui::SliderAngle( "Yaw",&yaw,-180.0f,180.0f );
if( ImGui::Button( "Reset" ) )
{
Reset();
}
}
ImGui::End();
}
void Camera::Reset() noexcept
{
r = 20.0f;
theta = 0.0f;
phi = 0.0f;
pitch = 0.0f;
yaw = 0.0f;
roll = 0.0f;
}
#pragma once
#include "Graphics.h"
class Camera
{
public:
DirectX::XMMATRIX GetMatrix() const noexcept;
void SpawnControlWindow() noexcept;
void Reset() noexcept;
private:
float r = 20.0f;
float theta = 0.0f;
float phi = 0.0f;
float pitch = 0.0f;
float yaw = 0.0f;
float roll = 0.0f;
};
\ No newline at end of file
#pragma once
#pragma once
#include "DrawableBase.h"
......
......@@ -150,6 +150,7 @@
<ClCompile Include="App.cpp" />
<ClCompile Include="Bindable.cpp" />
<ClCompile Include="Box.cpp" />
<ClCompile Include="Camera.cpp" />
<ClCompile Include="ChiliException.cpp" />
<ClCompile Include="ChiliTimer.cpp" />
<ClCompile Include="Drawable.cpp" />
......@@ -189,6 +190,7 @@
<ClInclude Include="Bindable.h" />
<ClInclude Include="BindableBase.h" />
<ClInclude Include="Box.h" />
<ClInclude Include="Camera.h" />
<ClInclude Include="ChiliException.h" />
<ClInclude Include="ChiliMath.h" />
<ClInclude Include="ChiliTimer.h" />
......
......@@ -150,6 +150,9 @@
<ClCompile Include="ImguiManager.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="WindowsMessageMap.h">
......@@ -305,6 +308,9 @@
<ClInclude Include="ImguiManager.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Camera.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="hw3d.rc">
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment