[Fix] Temporary fix to sprite scaling & rotation.
This commit is contained in:
parent
f8a67600ae
commit
38efab7bfc
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,4 +14,5 @@ Bin/VC10/Debug
|
|||||||
Bin/VC10/Release
|
Bin/VC10/Release
|
||||||
Bin/VC10/ipch
|
Bin/VC10/ipch
|
||||||
Bin/*.exe
|
Bin/*.exe
|
||||||
|
Bin/*.dll
|
||||||
|
|
||||||
|
@ -22,10 +22,12 @@ bool Game::Init(void) {
|
|||||||
glDepthFunc(GL_LEQUAL);
|
glDepthFunc(GL_LEQUAL);
|
||||||
|
|
||||||
Texture* testTexture = new Texture();
|
Texture* testTexture = new Texture();
|
||||||
testTexture->Load("../../Data/Img/test.png");
|
testTexture->Load("../Data/Img/test.png");
|
||||||
|
|
||||||
_testSprite = new Sprite();
|
_testSprite = new Sprite();
|
||||||
_testSprite->SetTexture(testTexture);
|
_testSprite->SetTexture(testTexture);
|
||||||
|
_testSprite->SetHandle(Vec2(800/2, 600/2));
|
||||||
|
_testSprite->SetScale(Vec2(1.0f, 1.0f));
|
||||||
|
|
||||||
// Return success.
|
// Return success.
|
||||||
return true;
|
return true;
|
||||||
@ -49,6 +51,7 @@ void Game::Render(void) {
|
|||||||
glMatrixMode(GL_MODELVIEW);
|
glMatrixMode(GL_MODELVIEW);
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
|
|
||||||
|
_testSprite->SetRotation(_rotationAngle);
|
||||||
_testSprite->Draw();
|
_testSprite->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,11 +22,13 @@ void Sprite::Draw() const {
|
|||||||
// . .
|
// . .
|
||||||
// 3---------2
|
// 3---------2
|
||||||
|
|
||||||
|
Vec2 scaledSize(size.x*scale.x, size.y*scale.y);
|
||||||
|
|
||||||
Vec2 vertices[4] = {
|
Vec2 vertices[4] = {
|
||||||
Vec2(handle.x, handle.y),
|
Vec2(0.0f, 0.0f),
|
||||||
Vec2(handle.x + size.x, handle.y),
|
Vec2(scaledSize.x, 0.0f),
|
||||||
Vec2(handle.x + size.x, handle.y + size.y),
|
Vec2(scaledSize.x, scaledSize.y),
|
||||||
Vec2(handle.x, handle.y + size.y),
|
Vec2(0.0f, scaledSize.y),
|
||||||
};
|
};
|
||||||
|
|
||||||
Vec2 texCoords[4] = {
|
Vec2 texCoords[4] = {
|
||||||
@ -36,14 +38,18 @@ void Sprite::Draw() const {
|
|||||||
Vec2(0.0f, 1.0f),
|
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);
|
glEnable(GL_TEXTURE_2D);
|
||||||
BindTexture(texture->GetTexID());
|
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);
|
glBegin(GL_QUADS);
|
||||||
glTexCoord2fv((const GLfloat*)&texCoords[0]);
|
glTexCoord2fv((const GLfloat*)&texCoords[0]);
|
||||||
glVertex2fv((const GLfloat*)&vertices[0]);
|
glVertex2fv((const GLfloat*)&vertices[0]);
|
||||||
@ -54,9 +60,11 @@ void Sprite::Draw() const {
|
|||||||
glTexCoord2fv((const GLfloat*)&texCoords[3]);
|
glTexCoord2fv((const GLfloat*)&texCoords[3]);
|
||||||
glVertex2fv((const GLfloat*)&vertices[3]);
|
glVertex2fv((const GLfloat*)&vertices[3]);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
|
glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Sprite::SetTexture(Texture* texture) {
|
void Sprite::SetTexture(Texture* texture) {
|
||||||
this->texture = texture;
|
this->texture = texture;
|
||||||
this->size = Vec2(texture->GetWidth(), texture->GetHeight());
|
this->size = Vec2((float)texture->GetWidth(), (float)texture->GetHeight());
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@ public:
|
|||||||
void SetRotation(float rotation) { this->rotation = rotation; }
|
void SetRotation(float rotation) { this->rotation = rotation; }
|
||||||
void SetTexture(Texture* texture);
|
void SetTexture(Texture* texture);
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
Vec2 handle;
|
Vec2 handle;
|
||||||
Vec2 size;
|
Vec2 size;
|
||||||
Vec2 scale;
|
Vec2 scale;
|
||||||
|
Loading…
Reference in New Issue
Block a user