-
-
Save Reputeless/35be5b1705536cab8f43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------------------- | |
// | |
// This is free and unencumbered software released into the public domain. | |
// | |
//-------------------------------------------------------------------------- | |
# include <Siv3D.hpp> // November 2014 v2 | |
class CameraManager | |
{ | |
public: | |
void freeCamera(double speed) | |
{ | |
const double move = speed * (Input::KeyControl.pressed ? 20.0 : Input::KeyShift.pressed ? 5.0 : 1.0); | |
if (Input::KeyLeft.pressed) | |
{ | |
r -= 1.0; | |
if (r < 0.0) r += 360.0; | |
} | |
if (Input::KeyRight.pressed) | |
{ | |
r += 1.0; | |
if (r > 360.0) r -= 360.0; | |
} | |
const double rad = Math::Radians(r); | |
const double xr = Math::Sin(rad); | |
const double zr = Math::Cos(rad); | |
if (Input::KeyW.pressed) | |
{ | |
state.pos.x += move * xr; | |
state.pos.z += move * zr; | |
} | |
if (Input::KeyS.pressed) | |
{ | |
state.pos.x -= move * xr; | |
state.pos.z -= move * zr; | |
} | |
if (Input::KeyA.pressed) | |
{ | |
state.pos.x -= move * zr; | |
state.pos.z += move * xr; | |
} | |
if (Input::KeyD.pressed) | |
{ | |
state.pos.x += move * zr; | |
state.pos.z -= move * xr; | |
} | |
if (Input::KeyUp.pressed) | |
{ | |
state.lookat.y += 0.5; | |
} | |
if (Input::KeyDown.pressed) | |
{ | |
state.lookat.y -= 0.5; | |
} | |
if (Input::KeyE.pressed) | |
{ | |
state.pos.y += move; | |
state.lookat.y += move; | |
} | |
if (Input::KeyX.pressed) | |
{ | |
state.pos.y -= move; | |
state.lookat.y -= move; | |
} | |
state.lookat.x = state.pos.x + 24.0 * xr; | |
state.lookat.z = state.pos.z + 24.0 * zr; | |
Graphics3D::SetCamera(state); | |
} | |
private: | |
Camera state = Graphics3D::GetCamera(); | |
double r = 0.0; | |
}; | |
void Main() | |
{ | |
CameraManager cam; | |
while (System::Update()) | |
{ | |
cam.freeCamera(0.1); | |
Plane(100).draw(); | |
Sphere(3).draw(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment