Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef GFX_CAMERA_H
- #define GFX_CAMERA_H
- #include <SFML/System.hpp>
- namespace gfx
- {
- class Camera
- {
- public:
- Camera();
- Camera( sf::Vector3f thePos );
- Camera( float thePosX, float thePosY, float thePosZ );
- Camera( sf::Vector3f thePos, sf::Vector3f theRot );
- Camera( float thePosX, float thePosY, float thePosZ, float theRotX, float theRotY, float theRotZ );
- void SetPosition( sf::Vector3f thePos );
- void SetPosition( float thePosX, float thePosY, float thePosZ );
- void Move( sf::Vector3f thePos );
- void Move( float thePosX, float thePosY, float thePosZ );
- sf::Vector3f GetPosition();
- void SetRotation( sf::Vector3f theRot );
- void SetRotation( float theRotX, float theRotY, float theRotZ );
- void Rotate( sf::Vector3f theRot );
- void Rotate( float theRotX, float theRotY, float theRotZ );
- sf::Vector3f GetRotation();
- void Render();
- void MoveForward( float amount );
- void MoveSideways( float amount );
- void RotateUp( float amount );
- void RotateLeft( float amount );
- private:
- sf::Vector3f pos;
- sf::Vector3f rot;
- };
- }
- #endif // GFX_CAMERA_H
- #include "gfx/Camera.h"
- #include <SFML/OpenGL.hpp>
- #include <cmath>
- #include "util/Math.h"
- namespace gfx
- {
- Camera::Camera()
- : pos( 0, 0, 0 ),
- rot( 0, 0, 0 )
- {
- }
- Camera::Camera( sf::Vector3f thePos )
- : pos( thePos ),
- rot( 0, 0, 0 )
- {
- }
- Camera::Camera( float thePosX, float thePosY, float thePosZ )
- : pos( thePosX, thePosY, thePosZ ),
- rot( 0, 0, 0 )
- {
- }
- Camera::Camera( sf::Vector3f thePos, sf::Vector3f theRot )
- : pos( thePos ),
- rot( theRot )
- {
- }
- Camera::Camera( float thePosX, float thePosY, float thePosZ, float theRotX, float theRotY, float theRotZ )
- : pos( thePosX, thePosY, thePosZ ),
- rot( theRotX, theRotY, theRotZ )
- {
- }
- void Camera::SetPosition( sf::Vector3f thePos )
- {
- SetPosition( thePos.x, thePos.y, thePos.z );
- }
- void Camera::SetPosition( float thePosX, float thePosY, float thePosZ )
- {
- pos.x = thePosX;
- pos.y = thePosY;
- pos.z = thePosZ;
- }
- void Camera::Move( sf::Vector3f thePos )
- {
- pos += thePos;
- }
- void Camera::Move( float thePosX, float thePosY, float thePosZ )
- {
- pos.x += thePosX;
- pos.y += thePosY;
- pos.z += thePosZ;
- }
- sf::Vector3f Camera::GetPosition()
- {
- return pos;
- }
- void Camera::SetRotation( sf::Vector3f theRot )
- {
- SetRotation( theRot.x, theRot.y, theRot.z );
- }
- void Camera::SetRotation( float theRotX, float theRotY, float theRotZ )
- {
- rot.x = theRotX;
- rot.y = theRotY;
- rot.z = theRotZ;
- }
- void Camera::Rotate( sf::Vector3f theRot )
- {
- rot += theRot;
- }
- void Camera::Rotate( float theRotX, float theRotY, float theRotZ )
- {
- rot.x += theRotX;
- rot.y += theRotY;
- rot.z += theRotZ;
- }
- sf::Vector3f Camera::GetRotation()
- {
- return rot;
- }
- void Camera::Render()
- {
- glRotatef( rot.x, 1.f, 0.f, 0.f );
- glRotatef( rot.y, 0.f, 1.f, 0.f );
- glRotatef( rot.z, 0.f, 0.f, 1.f );
- glTranslatef( -pos.x, -pos.y, -pos.z );
- }
- void Camera::MoveForward( float amount )
- {
- pos.x += std::sin( util::DegreesToRadians( rot.z ) ) * amount;
- pos.y += std::cos( util::DegreesToRadians( rot.z ) ) * amount;
- }
- void Camera::MoveSideways( float amount )
- {
- pos.x += -std::cos( util::DegreesToRadians( rot.z ) ) * amount;
- pos.y += std::sin( util::DegreesToRadians( rot.z ) ) * amount;
- }
- void Camera::RotateUp( float amount )
- {
- rot.z += amount;
- // Wrap all of the rotation
- for ( ; rot.x >= 360.f; rot.x -= 360.f );
- for ( ; rot.x <= -360.f; rot.x += 360.f );
- for ( ; rot.y >= 360.f; rot.y -= 360.f );
- for ( ; rot.y <= -360.f; rot.y += 360.f );
- for ( ; rot.z >= 360.f; rot.z -= 360.f );
- for ( ; rot.z <= -360.f; rot.z += 360.f );
- }
- void Camera::RotateLeft( float amount )
- {
- rot.x += amount;
- // Wrap all of the rotation
- for ( ; rot.x >= 360.f; rot.x -= 360.f );
- for ( ; rot.x <= -360.f; rot.x += 360.f );
- for ( ; rot.y >= 360.f; rot.y -= 360.f );
- for ( ; rot.y <= -360.f; rot.y += 360.f );
- for ( ; rot.z >= 360.f; rot.z -= 360.f );
- for ( ; rot.z <= -360.f; rot.z += 360.f );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement