diff --git a/.gitignore b/.gitignore index 4f77648..60be968 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ Bin/VC10/Debug Bin/VC10/Release Bin/VC10/ipch Bin/*.exe +Bin/*.dll diff --git a/src/Main/Game.cpp b/src/Main/Game.cpp index f637b37..4eda02b 100644 --- a/src/Main/Game.cpp +++ b/src/Main/Game.cpp @@ -22,10 +22,12 @@ bool Game::Init(void) { glDepthFunc(GL_LEQUAL); Texture* testTexture = new Texture(); - testTexture->Load("../../Data/Img/test.png"); + testTexture->Load("../Data/Img/test.png"); _testSprite = new Sprite(); _testSprite->SetTexture(testTexture); + _testSprite->SetHandle(Vec2(800/2, 600/2)); + _testSprite->SetScale(Vec2(1.0f, 1.0f)); // Return success. return true; @@ -49,6 +51,7 @@ void Game::Render(void) { glMatrixMode(GL_MODELVIEW); glLoadIdentity(); + _testSprite->SetRotation(_rotationAngle); _testSprite->Draw(); } diff --git a/src/Sprite/Sprite.cpp b/src/Sprite/Sprite.cpp index 24378c4..66fc349 100644 --- a/src/Sprite/Sprite.cpp +++ b/src/Sprite/Sprite.cpp @@ -22,11 +22,13 @@ void Sprite::Draw() const { // . . // 3---------2 + Vec2 scaledSize(size.x*scale.x, size.y*scale.y); + Vec2 vertices[4] = { - Vec2(handle.x, handle.y), - Vec2(handle.x + size.x, handle.y), - Vec2(handle.x + size.x, handle.y + size.y), - Vec2(handle.x, handle.y + size.y), + Vec2(0.0f, 0.0f), + Vec2(scaledSize.x, 0.0f), + Vec2(scaledSize.x, scaledSize.y), + Vec2(0.0f, scaledSize.y), }; Vec2 texCoords[4] = { @@ -36,14 +38,18 @@ void Sprite::Draw() const { Vec2(0.0f, 1.0f), }; - for(int i = 0; i < 4; i++){ - vertices[i].x *= scale.x; - vertices[i].y *= scale.y; - } - glEnable(GL_TEXTURE_2D); BindTexture(texture->GetTexID()); + glMatrixMode(GL_MODELVIEW); + glPushMatrix(); + + // Temporary solution. + Vec2 halfScaledSize = scaledSize / 2.0f; + glTranslatef(handle.x + halfScaledSize.x, handle.y + halfScaledSize.y, 0.0f); + glRotatef(rotation, 0.0f, 0.0f, 1.0f); + glTranslatef(-halfScaledSize.x, -halfScaledSize.y, 0.0f); + glBegin(GL_QUADS); glTexCoord2fv((const GLfloat*)&texCoords[0]); glVertex2fv((const GLfloat*)&vertices[0]); @@ -54,9 +60,11 @@ void Sprite::Draw() const { glTexCoord2fv((const GLfloat*)&texCoords[3]); glVertex2fv((const GLfloat*)&vertices[3]); glEnd(); + + glPopMatrix(); } void Sprite::SetTexture(Texture* texture) { this->texture = texture; - this->size = Vec2(texture->GetWidth(), texture->GetHeight()); + this->size = Vec2((float)texture->GetWidth(), (float)texture->GetHeight()); } diff --git a/src/Sprite/Sprite.h b/src/Sprite/Sprite.h index 67dff99..ab4ecf8 100644 --- a/src/Sprite/Sprite.h +++ b/src/Sprite/Sprite.h @@ -24,7 +24,7 @@ public: void SetRotation(float rotation) { this->rotation = rotation; } void SetTexture(Texture* texture); -private: +protected: Vec2 handle; Vec2 size; Vec2 scale;