Permalink
Browse files

Selection cursor added

  • Loading branch information...
1 parent c9c40f3 commit 1190a806bc78ffdb317ac4cef5f8c4fe8a5b1fdd @RachelJMorris committed Mar 16, 2013
Showing with 178 additions and 21 deletions.
  1. +109 −10 Geometry.cpp
  2. +6 −2 Geometry.h
  3. +23 −1 Input.cpp
  4. +1 −1 Input.h
  5. +39 −7 main.cpp
View
119 Geometry.cpp
@@ -1,19 +1,25 @@
#include "Geometry.h"
+#include <iostream>
+using namespace std;
+
namespace ursa
{
Geometry::Geometry()
{
}
-Geometry::Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim )
+Geometry::Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& index )
{
- Setup( pos, dim );
+ Setup( pos, dim, index );
}
-void Geometry::Setup( const sf::Vector3f& pos, const sf::Vector3f& dim )
+void Geometry::Setup( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& index )
{
+ m_cursorOn = false;
+ m_index = index;
+
m_lstPoints.push_back( sf::Vector3f( pos.x, pos.y, pos.z ) );
m_lstPoints.push_back( sf::Vector3f( pos.x + dim.x, pos.y, pos.z ) );
m_lstPoints.push_back( sf::Vector3f( pos.x + dim.x, pos.y + dim.y, pos.z ) );
@@ -27,6 +33,7 @@ void Geometry::Setup( const sf::Vector3f& pos, const sf::Vector3f& dim )
void Geometry::Draw( const GLuint& texture )
{
+ glEnable( GL_TEXTURE_2D );
glBegin( GL_QUADS );
glBindTexture( GL_TEXTURE_2D, texture );
@@ -36,11 +43,38 @@ void Geometry::Draw( const GLuint& texture )
DrawYZ();
glEnd();
+ glDisable(GL_TEXTURE_2D);
+
+ DrawLines();
+}
+
+void Geometry::CheckCursor( const sf::Vector3f& cursor )
+{
+// cout << "Compare: " << endl;
+// cout << m_index.x << ", " << m_index.y << ", " << m_index.z << endl;
+// cout << cursor.x << ", " << cursor.y << ", " << cursor.z << endl;
+ if ( cursor.x == (int)(m_index.x) &&
+ cursor.y == (int)(m_index.y) &&
+ cursor.z == (int)(m_index.z) )
+ {
+ m_cursorOn = true;
+ }
+ else
+ {
+ m_cursorOn = false;
+ }
}
void Geometry::DrawXY()
{
- glColor3f( 1.0f, 1.0f, 1.0f );
+ if ( m_cursorOn )
+ {
+ glColor3f( 1.0f, 1.0f, 0.0f );
+ }
+ else
+ {
+ glColor3f( 1.0f, 1.0f, 1.0f );
+ }
glTexCoord2f(0.0f, 1.0f);
glVertex3f( m_lstPoints[0].x,
@@ -86,7 +120,14 @@ void Geometry::DrawXY()
void Geometry::DrawXZ()
{
- glColor3f( 0.6f, 0.6f, 0.6f );
+ if ( m_cursorOn )
+ {
+ glColor3f( 1.0f, 1.0f, 0.0f );
+ }
+ else
+ {
+ glColor3f( 0.6f, 0.6f, 0.6f );
+ }
glTexCoord2f(0.0f, 0.0f);
glVertex3f( m_lstPoints[0].x,
@@ -109,30 +150,37 @@ void Geometry::DrawXZ()
m_lstPoints[4].z );
- glTexCoord2f(0.0f, 1.0f);
+ glTexCoord2f(1.0f, 0.0f);
glVertex3f( m_lstPoints[3].x,
m_lstPoints[3].y,
m_lstPoints[3].z );
- glTexCoord2f(1.0f, 1.0f);
+ glTexCoord2f(0.0f, 0.0f);
glVertex3f( m_lstPoints[2].x,
m_lstPoints[2].y,
m_lstPoints[2].z );
- glTexCoord2f(1.0f, 0.0f);
+ glTexCoord2f(0.0f, 1.0f);
glVertex3f( m_lstPoints[6].x,
m_lstPoints[6].y,
m_lstPoints[6].z );
- glTexCoord2f(0.0f, 0.0f);
+ glTexCoord2f(1.0f, 1.0f);
glVertex3f( m_lstPoints[7].x,
m_lstPoints[7].y,
m_lstPoints[7].z );
}
void Geometry::DrawYZ()
{
- glColor3f( 0.4f, 0.4f, 0.4f );
+ if ( m_cursorOn )
+ {
+ glColor3f( 1.0f, 1.0f, 0.0f );
+ }
+ else
+ {
+ glColor3f( 0.4f, 0.4f, 0.4f );
+ }
glTexCoord2f(0.0f, 1.0f);
glVertex3f( m_lstPoints[0].x,
@@ -176,4 +224,55 @@ void Geometry::DrawYZ()
m_lstPoints[2].z );
}
+void Geometry::DrawLines()
+{
+// if ( m_cursorOn )
+// {
+// glColor3f( 1.0f, 1.0f, 0.0f );
+// }
+// else
+// {
+// glColor3f( 1.0f, 1.0f, 1.0f );
+// }
+//
+// // XZ bottom
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[0].x, m_lstPoints[0].y, m_lstPoints[0].z );
+// glVertex3f( m_lstPoints[1].x, m_lstPoints[1].y, m_lstPoints[1].z );
+// glVertex3f( m_lstPoints[5].x, m_lstPoints[5].y, m_lstPoints[5].z );
+// glVertex3f( m_lstPoints[4].x, m_lstPoints[4].y, m_lstPoints[4].z );
+// glVertex3f( m_lstPoints[0].x, m_lstPoints[0].y, m_lstPoints[0].z );
+// glEnd();
+//
+// // XZ top
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[3].x, m_lstPoints[3].y + 0.1, m_lstPoints[3].z );
+// glVertex3f( m_lstPoints[2].x, m_lstPoints[2].y + 0.1, m_lstPoints[2].z );
+// glVertex3f( m_lstPoints[6].x, m_lstPoints[6].y + 0.1, m_lstPoints[6].z );
+// glVertex3f( m_lstPoints[7].x, m_lstPoints[7].y + 0.1, m_lstPoints[7].z );
+// glVertex3f( m_lstPoints[3].x, m_lstPoints[3].y + 0.1, m_lstPoints[3].z );
+// glEnd();
+//
+// // ZY Lines
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[0].x, m_lstPoints[0].y, m_lstPoints[0].z );
+// glVertex3f( m_lstPoints[3].x, m_lstPoints[3].y, m_lstPoints[3].z );
+// glEnd();
+//
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[1].x, m_lstPoints[1].y, m_lstPoints[1].z );
+// glVertex3f( m_lstPoints[2].x, m_lstPoints[2].y, m_lstPoints[2].z );
+// glEnd();
+//
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[5].x, m_lstPoints[5].y, m_lstPoints[5].z );
+// glVertex3f( m_lstPoints[6].x, m_lstPoints[6].y, m_lstPoints[6].z );
+// glEnd();
+//
+// glBegin( GL_LINES );
+// glVertex3f( m_lstPoints[4].x, m_lstPoints[4].y, m_lstPoints[4].z );
+// glVertex3f( m_lstPoints[7].x, m_lstPoints[7].y, m_lstPoints[7].z );
+// glEnd();
+}
+
}
View
8 Geometry.h
@@ -12,16 +12,20 @@ class Geometry
{
public:
Geometry();
- Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim );
- void Setup( const sf::Vector3f& pos, const sf::Vector3f& dim );
+ Geometry( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& );
+ void Setup( const sf::Vector3f& pos, const sf::Vector3f& dim, const sf::Vector3i& );
void Draw( const GLuint& texture );
+ void CheckCursor( const sf::Vector3f& cursor );
private:
std::vector<sf::Vector3f> m_lstPoints;
+ sf::Vector3i m_index;
+ bool m_cursorOn;
void DrawXY();
void DrawXZ();
void DrawYZ();
+ void DrawLines();
};
}
View
24 Input.cpp
@@ -1,11 +1,12 @@
#include "Input.h"
#include <iostream>
+using namespace std;
namespace ursa
{
-void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks )
+void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks, sf::Vector3f& cursor )
{
sf::Event event;
@@ -17,6 +18,23 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
HandleCameraControls( input, app, camera );
HandleMouseControls( input, app, lstBlocks );
+ if ( input.IsKeyDown( sf::Key::Numpad8 ) )
+ {
+ cursor.z -= 0.5;
+ }
+ else if ( input.IsKeyDown( sf::Key::Numpad2 ) )
+ {
+ cursor.z += 0.5;
+ }
+ if ( input.IsKeyDown( sf::Key::Numpad4 ) )
+ {
+ cursor.x -= 0.5;
+ }
+ else if ( input.IsKeyDown( sf::Key::Numpad6 ) )
+ {
+ cursor.x += 0.5;
+ }
+
/* DEBUG KEYS */
if ( input.IsKeyDown( sf::Key::F1 ) )
{
@@ -29,6 +47,10 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
std::cout << std::endl;
std::cout << "Mouse Coordinates:\t" << std::endl;
std::cout << input.GetMouseX() << ", " << input.GetMouseY() << std::endl;
+
+ std::cout << std::endl;
+ std::cout << "Cursor:" << std::endl;
+ std::cout << cursor.x << ", " << cursor.y << ", " << cursor.z << std::endl;
}
}
View
2 Input.h
@@ -15,7 +15,7 @@ namespace ursa
class Input
{
public:
- void HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks );
+ void HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBlocks, sf::Vector3f& cursor );
private:
void HandleCameraControls( const sf::Input& input, Application& app, Camera& camera );
View
46 main.cpp
@@ -14,15 +14,26 @@ int main()
{
ursa::Application app;
ursa::Camera camera;
- camera.Setup( sf::Vector3f( 0, 0, -50 ) );
+ camera.Setup( sf::Vector3f( -50, 30, -115 ), sf::Vector3f( 52, 0, 0 ) );
ursa::Input input;
+ const int mapWidth = 10;
+ const int mapDepth = 10;
+
vector<ursa::Geometry> lstBoxes;
- lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 0, 0, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
- lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 10, 0, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
- lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 10, 10, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
- lstBoxes.push_back( ursa::Geometry( sf::Vector3f( 0, 10, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
- lstBoxes.push_back( ursa::Geometry( sf::Vector3f( -10, -10, 0 ), sf::Vector3f( 10, 10, 10 ) ) );
+ for ( int z = 0; z < mapDepth; z++ )
+ {
+ for ( int x = 0; x < mapWidth; x++ )
+ {
+ lstBoxes.push_back( ursa::Geometry( sf::Vector3f( x * 10, 0, z * 10 ),
+ sf::Vector3f( 10, 10, 10 ), sf::Vector3i( x, 0, z ) ) );
+ }
+ }
+
+ sf::Vector3f cursor;
+ cursor.x = 0;
+ cursor.y = 0;
+ cursor.z = 0;
sf::Image imgTxt;
imgTxt.LoadFromFile( "assets/brick.png" );
@@ -41,7 +52,28 @@ int main()
while ( !app.Quit() )
{
// Get Events
- input.HandleInput( app, camera, lstBoxes );
+ input.HandleInput( app, camera, lstBoxes, cursor );
+ if ( cursor.x >= mapWidth )
+ {
+ cursor.x = 0;
+ }
+ else if ( cursor.x < 0 )
+ {
+ cursor.x = mapWidth - 1;
+ }
+ if ( cursor.z >= mapDepth )
+ {
+ cursor.z = 0;
+ }
+ else if ( cursor.z < 0 )
+ {
+ cursor.z = mapDepth - 1;
+ }
+
+ for ( int i = 0; i < lstBoxes.size(); i++ )
+ {
+ lstBoxes[i].CheckCursor( cursor );
+ }
// Render
app.PrepDraw();

0 comments on commit 1190a80

Please sign in to comment.