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

camera with control window

parent 13abbb1e
...@@ -77,13 +77,13 @@ App::App() ...@@ -77,13 +77,13 @@ App::App()
std::generate_n( std::back_inserter( drawables ),nDrawables,Factory{ wnd.Gfx() } ); 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().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() void App::DoFrame()
{ {
const auto dt = timer.Mark() * speed_factor; const auto dt = timer.Mark() * speed_factor;
wnd.Gfx().BeginFrame( 0.07f,0.0f,0.12f ); wnd.Gfx().BeginFrame( 0.07f,0.0f,0.12f );
wnd.Gfx().SetCamera( cam.GetMatrix() );
for( auto& d : drawables ) for( auto& d : drawables )
{ {
...@@ -96,9 +96,11 @@ void App::DoFrame() ...@@ -96,9 +96,11 @@ void App::DoFrame()
{ {
ImGui::SliderFloat( "Speed Factor",&speed_factor,0.0f,4.0f ); 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( "%.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::End();
// imgui window to control camera
cam.SpawnControlWindow();
// present // present
wnd.Gfx().EndFrame(); wnd.Gfx().EndFrame();
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
#include "Window.h" #include "Window.h"
#include "ChiliTimer.h" #include "ChiliTimer.h"
#include "ImguiManager.h" #include "ImguiManager.h"
#include "Camera.h"
class App class App
{ {
...@@ -18,5 +19,6 @@ private: ...@@ -18,5 +19,6 @@ private:
ChiliTimer timer; ChiliTimer timer;
std::vector<std::unique_ptr<class Drawable>> drawables; std::vector<std::unique_ptr<class Drawable>> drawables;
float speed_factor = 1.0f; float speed_factor = 1.0f;
Camera cam;
static constexpr size_t nDrawables = 180; 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 #pragma once
#include "DrawableBase.h" #include "DrawableBase.h"
......
...@@ -150,6 +150,7 @@ ...@@ -150,6 +150,7 @@
<ClCompile Include="App.cpp" /> <ClCompile Include="App.cpp" />
<ClCompile Include="Bindable.cpp" /> <ClCompile Include="Bindable.cpp" />
<ClCompile Include="Box.cpp" /> <ClCompile Include="Box.cpp" />
<ClCompile Include="Camera.cpp" />
<ClCompile Include="ChiliException.cpp" /> <ClCompile Include="ChiliException.cpp" />
<ClCompile Include="ChiliTimer.cpp" /> <ClCompile Include="ChiliTimer.cpp" />
<ClCompile Include="Drawable.cpp" /> <ClCompile Include="Drawable.cpp" />
...@@ -189,6 +190,7 @@ ...@@ -189,6 +190,7 @@
<ClInclude Include="Bindable.h" /> <ClInclude Include="Bindable.h" />
<ClInclude Include="BindableBase.h" /> <ClInclude Include="BindableBase.h" />
<ClInclude Include="Box.h" /> <ClInclude Include="Box.h" />
<ClInclude Include="Camera.h" />
<ClInclude Include="ChiliException.h" /> <ClInclude Include="ChiliException.h" />
<ClInclude Include="ChiliMath.h" /> <ClInclude Include="ChiliMath.h" />
<ClInclude Include="ChiliTimer.h" /> <ClInclude Include="ChiliTimer.h" />
......
...@@ -150,6 +150,9 @@ ...@@ -150,6 +150,9 @@
<ClCompile Include="ImguiManager.cpp"> <ClCompile Include="ImguiManager.cpp">
<Filter>Source Files</Filter> <Filter>Source Files</Filter>
</ClCompile> </ClCompile>
<ClCompile Include="Camera.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ClInclude Include="WindowsMessageMap.h"> <ClInclude Include="WindowsMessageMap.h">
...@@ -305,6 +308,9 @@ ...@@ -305,6 +308,9 @@
<ClInclude Include="ImguiManager.h"> <ClInclude Include="ImguiManager.h">
<Filter>Header Files</Filter> <Filter>Header Files</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="Camera.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<ResourceCompile Include="hw3d.rc"> <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