Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: Rejcx/Ursa
base: 76896f4140
...
head fork: Rejcx/Ursa
compare: ba0f66a19e
  • 3 commits
  • 8 files changed
  • 0 commit comments
  • 1 contributor
View
71 Application.cpp
@@ -0,0 +1,71 @@
+#include "Application.h"
+
+namespace ursa
+{
+
+Application::Application()
+{
+ m_quit = false;
+
+ InitSFML( "OpenGL" );
+ InitOpenGL();
+}
+
+Application::Application( const std::string& title )
+{
+ m_quit = false;
+
+ InitSFML( title );
+ InitOpenGL();
+}
+
+Application::~Application()
+{
+ m_window.Close();
+}
+
+void Application::PrepDraw()
+{
+ m_window.SetActive();
+ glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );
+
+ glMatrixMode( GL_MODELVIEW );
+ glLoadIdentity();
+}
+
+void Application::FinishDraw()
+{
+ m_window.Display();
+}
+
+void Application::InitSFML( const std::string& title )
+{
+ m_settings.DepthBits = 24;
+ m_settings.StencilBits = 8;
+ m_window.Create(
+ sf::VideoMode( 640, 480, 32 ),
+ title, sf::Style::Close, m_settings
+ );
+ m_window.SetFramerateLimit( 60 );
+}
+
+void Application::InitOpenGL()
+{
+ // Init OpenGL
+ glClearDepth( 1.0f );
+ glClearColor( 0.5f, 0.7f, 0.8f, 1.0f );
+
+ // Z-buffer read/write
+ glEnable( GL_DEPTH_TEST );
+ glDepthMask( GL_TRUE );
+ glAlphaFunc( GL_GREATER, 0.5f );
+ glEnable( GL_ALPHA_TEST );
+
+ // Perspective projection
+ glMatrixMode( GL_PROJECTION );
+ glLoadIdentity();
+ gluPerspective( 90.0f, 1.0f, 1.0f, 1500.0f );
+
+}
+
+}
View
40 Application.h
@@ -0,0 +1,40 @@
+#ifndef _APPLICATION
+#define _APPLICATION
+
+#include <SFML/Window.hpp>
+
+#include <string>
+
+namespace ursa
+{
+
+class Application
+{
+ public:
+ Application();
+ Application( const std::string& title );
+ ~Application();
+
+ void PrepDraw();
+ void FinishDraw();
+
+ bool Quit() { return m_quit; }
+ void Quit( bool val ) { m_quit = val; }
+
+ const sf::Input& GetInput() { return m_window.GetInput(); }
+ bool GetEvent( sf::Event event ) { return m_window.GetEvent( event ); }
+
+ private:
+ void InitSFML( const std::string& title );
+ void InitOpenGL();
+
+ sf::Window m_window;
+ sf::WindowSettings m_settings;
+
+ bool m_quit;
+};
+
+}
+
+#endif
+
View
56 Camera.cpp
@@ -0,0 +1,56 @@
+#include "Camera.h"
+
+namespace ursa
+{
+
+Camera::Camera()
+{
+ m_position.x = m_position.y = m_position.z = 0;
+ m_rotation.x = m_rotation.y = m_rotation.z = 0;
+
+ m_moveSpeed = 1;
+ m_rotateSpeed = 1;
+}
+
+void Camera::Setup( const sf::Vector3f& pos, const sf::Vector3f& rot )
+{
+ m_position = pos;
+ m_rotation = rot;
+}
+
+void Camera::Setup( const sf::Vector3f& pos )
+{
+ m_position = pos;
+}
+
+void Camera::MoveX( int inc )
+{
+ m_position.x += inc * m_moveSpeed;
+}
+
+void Camera::MoveY( int inc )
+{
+ m_position.y += inc * m_moveSpeed;
+}
+
+void Camera::MoveZ( int inc )
+{
+ m_position.z += inc * m_moveSpeed;
+}
+
+void Camera::RotateX( int inc )
+{
+ m_rotation.x += inc * m_moveSpeed;
+}
+
+void Camera::RotateY( int inc )
+{
+ m_rotation.y += inc * m_moveSpeed;
+}
+
+void Camera::RotateZ( int inc )
+{
+ m_rotation.z += inc * m_moveSpeed;
+}
+
+}
View
43 Camera.h
@@ -0,0 +1,43 @@
+#ifndef _CAMERA
+#define _CAMERA
+
+#include <SFML/System.hpp>
+
+namespace ursa
+{
+
+class Camera
+{
+ public:
+ Camera();
+
+ void Setup( const sf::Vector3f& pos, const sf::Vector3f& rot );
+ void Setup( const sf::Vector3f& pos );
+
+ void MoveX( int inc );
+ void MoveY( int inc );
+ void MoveZ( int inc );
+
+ void RotateX( int inc );
+ void RotateY( int inc );
+ void RotateZ( int inc );
+
+ float X() { return m_position.x; }
+ float Y() { return m_position.y; }
+ float Z() { return m_position.z; }
+
+ float RX() { return m_rotation.x; }
+ float RY() { return m_rotation.y; }
+ float RZ() { return m_rotation.z; }
+
+ private:
+ sf::Vector3f m_position;
+ sf::Vector3f m_rotation;
+
+ float m_moveSpeed;
+ float m_rotateSpeed;
+};
+
+}
+
+#endif
View
79 Input.cpp
@@ -0,0 +1,79 @@
+#include "Input.h"
+
+#include <iostream>
+
+namespace ursa
+{
+
+void Input::HandleInput( const sf::Input& input, Application& app, Camera& camera )
+{
+ /* SYSTEM KEYS */
+ if ( input.IsKeyDown( sf::Key::Q ) )
+ {
+ app.Quit( true );
+ }
+
+ /* MOVEMENT KEYS */
+ if ( input.IsKeyDown( sf::Key::A ) )
+ {
+ camera.MoveX( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::D ) )
+ {
+ camera.MoveX( -1 );
+ }
+ if ( input.IsKeyDown( sf::Key::S ) )
+ {
+ camera.MoveY( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::W ) )
+ {
+ camera.MoveY( -1 );
+ }
+ if ( input.IsKeyDown( sf::Key::Up ) )
+ {
+ camera.MoveZ( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::Down ) )
+ {
+ camera.MoveZ( -1 );
+ }
+
+ /* CAMERA ROTATION */
+ if ( input.IsKeyDown( sf::Key::J ) )
+ {
+ camera.RotateY( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::L ) )
+ {
+ camera.RotateY( -1 );
+ }
+ if ( input.IsKeyDown( sf::Key::I ) )
+ {
+ camera.RotateX( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::K ) )
+ {
+ camera.RotateX( -1 );
+ }
+ if ( input.IsKeyDown( sf::Key::U ) )
+ {
+ camera.RotateZ( 1 );
+ }
+ else if ( input.IsKeyDown( sf::Key::O ) )
+ {
+ camera.RotateZ( -1 );
+ }
+
+ /* DEBUG KEYS */
+ if ( input.IsKeyDown( sf::Key::F1 ) )
+ {
+ std::cout << std::endl;
+ std::cout << "Camera Coordinates:\t";
+ std::cout << camera.X() << ", " << camera.Y() << ", " << camera.Z() << std::endl;
+ std::cout << "Camera Rotation:\t";
+ std::cout << camera.RX() << ", " << camera.RY() << ", " << camera.RZ() << std::endl;
+ }
+}
+
+}
View
22 Input.h
@@ -0,0 +1,22 @@
+#ifndef _INPUT
+#define _INPUT
+
+#include <SFML/Window.hpp>
+
+#include "Application.h"
+#include "Camera.h"
+
+namespace ursa
+{
+
+class Input
+{
+ public:
+ void HandleInput( const sf::Input& input, Application& app, Camera& camera );
+
+ private:
+};
+
+}
+
+#endif
View
52 OglRpg.cbp
@@ -0,0 +1,52 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+ <FileVersion major="1" minor="6" />
+ <Project>
+ <Option title="OglRpg" />
+ <Option pch_mode="2" />
+ <Option compiler="gcc" />
+ <Build>
+ <Target title="Debug">
+ <Option output="bin/Debug/OglRpg" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Debug/" />
+ <Option type="1" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-g" />
+ </Compiler>
+ </Target>
+ <Target title="Release">
+ <Option output="bin/Release/OglRpg" prefix_auto="1" extension_auto="1" />
+ <Option object_output="obj/Release/" />
+ <Option type="0" />
+ <Option compiler="gcc" />
+ <Compiler>
+ <Add option="-O2" />
+ </Compiler>
+ <Linker>
+ <Add option="-s" />
+ </Linker>
+ </Target>
+ </Build>
+ <Compiler>
+ <Add option="-Wall" />
+ </Compiler>
+ <Linker>
+ <Add library="GL" />
+ <Add library="X11" />
+ <Add library="/usr/lib/libsfml-audio.so" />
+ <Add library="/usr/lib/libsfml-graphics.so" />
+ <Add library="/usr/lib/libsfml-system.so" />
+ <Add library="/usr/lib/libsfml-window.so" />
+ </Linker>
+ <Unit filename="Application.cpp" />
+ <Unit filename="Application.h" />
+ <Unit filename="Appliccation.h" />
+ <Unit filename="Camera.h" />
+ <Unit filename="main.cpp" />
+ <Extensions>
+ <code_completion />
+ <debugger />
+ </Extensions>
+ </Project>
+</CodeBlocks_project_file>
View
46 main.cpp
@@ -0,0 +1,46 @@
+#include <iostream>
+
+#include "Application.h"
+#include "Camera.h"
+#include "Input.h"
+
+using namespace std;
+
+int main()
+{
+ ursa::Application app;
+ ursa::Camera camera;
+ camera.Setup( sf::Vector3f( 0, 0, -100 ) );
+ ursa::Input input;
+
+ while ( !app.Quit() )
+ {
+ // Get Events
+ sf::Event event;
+ while ( app.GetEvent( event ) )
+ {
+ input.HandleInput( app.GetInput(), app, camera );
+ }
+
+ // Render
+ app.PrepDraw();
+
+ glTranslatef( camera.X(), camera.Y(), camera.Z() );
+ glRotatef( camera.RX(), 1.0f, 0.0f, 0.0f );
+ glRotatef( camera.RY(), 0.0f, 1.0f, 0.0f );
+ glRotatef( camera.RZ(), 0.0f, 0.0f, 1.0f );
+
+ glBegin( GL_QUADS );
+
+ glVertex3f( 0, 0, 0 );
+ glVertex3f( 100, 0, 0 );
+ glVertex3f( 100, 100, 0 );
+ glVertex3f( 0, 100, 0 );
+
+ glEnd();
+
+ app.FinishDraw();
+ }
+
+ return 0;
+}

No commit comments for this range

Something went wrong with that request. Please try again.