Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

I think I fixed the segfault

  • Loading branch information...
commit 49ef3545b91d6a15beef1a2b597653e537800632 1 parent b72998e
@Rejcx authored
Showing with 44 additions and 26 deletions.
  1. +0 −1  Geometry.cpp
  2. +43 −24 Input.cpp
  3. +1 −1  Input.h
View
1  Geometry.cpp
@@ -39,7 +39,6 @@ void Geometry::Draw()
glEnable( GL_TEXTURE_2D );
glBegin( GL_QUADS );
-
DrawXY();
DrawXZ();
DrawYZ();
View
67 Input.cpp
@@ -12,23 +12,27 @@ Input::Input() : m_timeoutMax( 5.0 )
m_cursorTimeout = 0.0;
}
-void Input::CreateNewBox( std::vector<Geometry>& lstBoxes )
+void Input::CreateNewBox( std::vector<Geometry>& lstBoxes, GLuint& texture )
{
// Create a new one!
// Position, Dimensions, Index
- lstBoxes.push_back( Geometry(
- sf::Vector3f(
- m_cursorPosition.x,
- m_cursorPosition.y,
- m_cursorPosition.z
- ),
- sf::Vector3f( 10, 10, 10 ),
- sf::Vector3i(
- m_cursorPosition.x / 10,
- m_cursorPosition.y / 10,
- m_cursorPosition.z / 10
- )
- ) );
+ Geometry newg(
+ sf::Vector3f(
+ m_cursorPosition.x,
+ m_cursorPosition.y,
+ m_cursorPosition.z
+ ),
+ sf::Vector3f( 10, 10, 10 ),
+ sf::Vector3i(
+ m_cursorPosition.x / 10,
+ m_cursorPosition.y / 10,
+ m_cursorPosition.z / 10
+ )
+ );
+
+ newg.SetTexture( texture );
+
+ lstBoxes.push_back( newg );
}
void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>& lstBoxes, GLuint lstTextures[5], float mapWidth, float mapDepth )
@@ -61,41 +65,56 @@ void Input::HandleInput( Application& app, Camera& camera, std::vector<Geometry>
{
if ( activeBox == -1 )
{
- CreateNewBox( lstBoxes );
+ CreateNewBox( lstBoxes, lstTextures[0] );
+ }
+ else
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[0] );
}
- lstBoxes[activeBox].SetTexture( lstTextures[0] );
}
else if ( input.IsKeyDown( sf::Key::Num1 ) )
{
if ( activeBox == -1 )
{
- CreateNewBox( lstBoxes );
+ CreateNewBox( lstBoxes, lstTextures[1] );
+ }
+ else
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[1] );
}
- lstBoxes[activeBox].SetTexture( lstTextures[1] );
}
else if ( input.IsKeyDown( sf::Key::Num2 ) )
{
if ( activeBox == -1 )
{
- CreateNewBox( lstBoxes );
+ CreateNewBox( lstBoxes, lstTextures[2] );
+ }
+ else
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[2] );
}
- lstBoxes[activeBox].SetTexture( lstTextures[2] );
}
else if ( input.IsKeyDown( sf::Key::Num3 ) )
{
if ( activeBox == -1 )
{
- CreateNewBox( lstBoxes );
+ CreateNewBox( lstBoxes, lstTextures[3] );
+ }
+ else
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[3] );
}
- lstBoxes[activeBox].SetTexture( lstTextures[3] );
}
else if ( input.IsKeyDown( sf::Key::Num4 ) )
{
if ( activeBox == -1 )
{
- CreateNewBox( lstBoxes );
+ CreateNewBox( lstBoxes, lstTextures[4] );
+ }
+ else
+ {
+ lstBoxes[activeBox].SetTexture( lstTextures[4] );
}
- lstBoxes[activeBox].SetTexture( lstTextures[4] );
}
if ( m_cursorTimeout <= 0 )
View
2  Input.h
@@ -21,7 +21,7 @@ class Input
GLuint lstTextures[5], float mapWidth, float mapDepth );
void DrawCursor();
- void CreateNewBox( std::vector<Geometry>& lstBlocks );
+ void CreateNewBox( std::vector<Geometry>& lstBlocks, GLuint& texture );
sf::Vector3f CursorPosition() { return m_cursorPosition; }
Please sign in to comment.
Something went wrong with that request. Please try again.