前田稔(Maeda Minoru)の超初心者のプログラム入門
void MyCamera::View(float dx, float dy, float dz) { XMMATRIX view, mat; view = XMMatrixTranspose(XMMatrixLookAtRH(m_eye, m_at, m_up)); mat = XMMatrixRotationView(dx, dy, dz); XMStoreFloat4x4(&m_view, mat * view); } |
#include "MyCamera.h" MyCamera *my_camera = nullptr; float m_x, m_y, m_z; |
Sample3DSceneRenderer::Sample3DSceneRenderer(const std::shared_ptr<DX::DeviceResources>& deviceResources, Windows::UI::Core::CoreWindow^ window) : m_loadingComplete(false), m_degreesPerSecond(45), m_indexCount(0), m_tracking(false), m_deviceResources(deviceResources), m_window(window) { CreateDeviceDependentResources(); CreateWindowSizeDependentResources(); my_camera = new MyCamera(m_deviceResources); m_x = 0; m_y = 0; m_z = 0; my_camera->Camera(XMVECTORF32{ 0.0f, 0.7f, 5.0f, 0.0f }, XMVECTORF32{ -1.0f, -0.1f, 0.0f, 0.0f }, XMVECTORF32{ 0.0f, 1.0f, 0.0f, 0.0f }); } |
void Sample3DSceneRenderer::CreateWindowSizeDependentResources() { if (my_camera!=nullptr) my_camera->Projection(); } |
void Sample3DSceneRenderer::Update(DX::StepTimer const& timer) { Windows::UI::Core::CoreVirtualKeyStates KeyState; KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Left); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_x -= 0.01f; } KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Right); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_x += 0.01f; } KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Up); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_y -= 0.01f; } KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Down); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_y += 0.01f; } KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Space); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_z -= 0.01f; } KeyState = m_window->GetAsyncKeyState(Windows::System::VirtualKey::Enter); if (bool(KeyState & Windows::UI::Core::CoreVirtualKeyStates::Down)) { m_z += 0.01f; } //my_camera->Trans(m_x, m_y, m_z); // View に代えて Trans を試します my_camera->View(m_y, m_x, m_z); } |
// 定数バッファーを準備して、グラフィックス デバイスに送信します。 m_constantBufferData.projection = my_camera->m_projection; m_constantBufferData.view = my_camera->m_view; m_constantBufferData.model = my_camera->m_model; |
void MyCamera::Trans(float tx, float ty, float tz) { XMMATRIX mat; mat = XMMatrixTranslation(tx, ty, tz); XMStoreFloat4x4(&m_model, mat); } |