OpenGL Rotation and Zooming.

This commit is contained in:
James Turk 2002-12-02 00:36:35 +00:00
parent d2dcd9f396
commit 7fa309c4af
4 changed files with 83 additions and 18 deletions

View File

@ -13,7 +13,7 @@
File: ZE_ZImage.h <br> File: ZE_ZImage.h <br>
Description: Header file for core ZEngine Image and Texture Object. <br> Description: Header file for core ZEngine Image and Texture Object. <br>
Author(s): James Turk, Gamer Tazar <br> Author(s): James Turk, Gamer Tazar <br>
$Id: ZE_ZImage.h,v 1.2 2002/12/01 07:56:17 cozman Exp $<br> $Id: ZE_ZImage.h,v 1.3 2002/12/02 00:36:35 cozman Exp $<br>
\file ZE_ZImage.h \file ZE_ZImage.h
\brief Definition file for ZImage. \brief Definition file for ZImage.
@ -149,6 +149,24 @@ class ZImage : public ZObject
**/ **/
void SetColorKey(Uint8 red, Uint8 green, Uint8 blue); void SetColorKey(Uint8 red, Uint8 green, Uint8 blue);
/*!
\brief Stretch the image by a certain X and Y factor.
Stretch image using a factor to multiply width and height by.
\param xFactor Stretch factor for width. [newWidth = oldWidth * xStretch]
\param yFactor Stretch factor for height. [newHeight = oldHeight * yStretch]
**/
void Stretch(float xFactor, float yFactor);
/*!
\brief Resizes an image, stretching to new size.
Stretch image to new width and height.
\param width New width to stretch image to.
\param height New height to stretch image to.
**/
void Resize(unsigned int width, unsigned int height);
/*! /*!
\brief OpenGL related bind call. \brief OpenGL related bind call.
@ -164,7 +182,17 @@ class ZImage : public ZObject
\param x X coord to draw Image to. \param x X coord to draw Image to.
\param y Y coord to draw Image to. \param y Y coord to draw Image to.
**/ **/
void Draw(int x, int y); void Draw(float x, float y);
/*!
\brief Draw Image rotated to screen.
Image is rotated about it's own center by specified angle, then drawn to screen.
\param x X coord to draw Image to.
\param y Y coord to draw Image to.
\param angle Angle in degrees to rotate image.
**/
void DrawRotated(int x, int y, float angle);
///////////// /////////////
//Accessors// //Accessors//

View File

@ -3,7 +3,7 @@
File: ZEngine.h <br> File: ZEngine.h <br>
Description: Public Header File for ZEngine. <br> Description: Public Header File for ZEngine. <br>
Author(s): James Turk <br> Author(s): James Turk <br>
$Id: ZEngine.h,v 1.3 2002/12/01 07:56:17 cozman Exp $<br> $Id: ZEngine.h,v 1.4 2002/12/02 00:36:35 cozman Exp $<br>
\file ZEngine.h \file ZEngine.h
\brief Header file for ZEngine. \brief Header file for ZEngine.
@ -16,16 +16,17 @@ $Id: ZEngine.h,v 1.3 2002/12/01 07:56:17 cozman Exp $<br>
\mainpage ZEngine Documentation \mainpage ZEngine Documentation
\author James Turk \author James Turk
\version 0.7.7 \version 0.7.8
\date 1 December, 2002 \date 1 December, 2002
\section ZEngine About ZEngine \section ZEngine About ZEngine
<br> <br>
ZEngine is designed to wrap common interfaces of the SDL API in an Object Oriented manner. It is licensed under ZEngine is designed to wrap common interfaces of the SDL API in an Object Oriented manner. <br> It is licensed under
a very liberal BSD-style license, and anyone is free to suggest or implement changes to be added to the Engine. In addition a very liberal BSD-style license, and anyone is free to suggest or implement changes to be added to the Engine.<br>
ZEngine hopes to provide a core engine which can be used to develop a game without having to rewrite large amounts In addition ZEngine aims to provide a core engine which can be used to develop a game without having to
of code. As of version 0.7.7 ZEngine uses OpenGL rather than SDL to do 2D drawing, thus increasing the use of the engine rewrite large amounts of code.<br>
and making the engine much faster in most test cases. As of version 0.7.7 ZEngine uses OpenGL rather than SDL to do 2D drawing, thus increasing the uses of the engine
and making the engine much faster in most test cases.<br>
\section Licensing Licensing \section Licensing Licensing
<br><pre> <br><pre>

View File

@ -13,7 +13,7 @@
File: ZE_ZImage.cpp <br> File: ZE_ZImage.cpp <br>
Description: Implementation source file for core ZEngine Image or Texture Object. <br> Description: Implementation source file for core ZEngine Image or Texture Object. <br>
Author(s): James Turk, Gamer Tazar <br> Author(s): James Turk, Gamer Tazar <br>
$Id: ZE_ZImage.cpp,v 1.3 2002/12/01 07:56:17 cozman Exp $<br> $Id: ZE_ZImage.cpp,v 1.4 2002/12/02 00:36:35 cozman Exp $<br>
\file ZE_ZImage.cpp \file ZE_ZImage.cpp
\brief Source file for ZImage. \brief Source file for ZImage.
@ -151,23 +151,55 @@ void ZImage::SetColorKey(Uint8 red, Uint8 green, Uint8 blue)
LogError("ZImage not initialized in ZImage::SetColorKey."); LogError("ZImage not initialized in ZImage::SetColorKey.");
} }
void ZImage::Stretch(float xFactor, float yFactor)
{
rWidth = static_cast<unsigned int>(xFactor*rWidth);
rHeight = static_cast<unsigned int>(yFactor*rHeight);
}
void ZImage::Resize(unsigned int width, unsigned int height)
{
rWidth = width;
rHeight = height;
}
void ZImage::Bind() void ZImage::Bind()
{ {
glBindTexture(GL_TEXTURE_2D, rTexID); glBindTexture(GL_TEXTURE_2D, rTexID);
} }
void ZImage::Draw(int x, int y) void ZImage::Draw(float x, float y)
{ {
Bind(); Bind();
glBegin(GL_TRIANGLE_STRIP); glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f,0.0f); glVertex2i(x, y); glTexCoord2f(0.0f,0.0f); glVertex2f(x, y);
glTexCoord2f(rTexMaxX,0.0f); glVertex2i(x+rWidth, y); glTexCoord2f(rTexMaxX,0.0f); glVertex2f(x+rWidth, y);
glTexCoord2f(0.0f,rTexMaxY); glVertex2i(x, y+rHeight); glTexCoord2f(0.0f,rTexMaxY); glVertex2f(x, y+rHeight);
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2i(x+rWidth, y+rHeight); glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth, y+rHeight);
glEnd(); glEnd();
} }
void ZImage::DrawRotated(int x, int y, float angle)
{
float cX,cY; //center variables
cX = rWidth/2.0f;
cY = rHeight/2.0f;
glPushMatrix();
glTranslatef(x+cX,y+cY,0);
glRotatef(angle,0,0,1.0f);
Bind();
glBegin(GL_TRIANGLE_STRIP);
glTexCoord2f(0.0f,0.0f); glVertex2f(-cX, -cY);
glTexCoord2f(rTexMaxX,0.0f); glVertex2f(-cX+rWidth, -cY);
glTexCoord2f(0.0f,rTexMaxY); glVertex2f(-cX, -cY+rHeight);
glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(-cX+rWidth, -cY+rHeight);
glEnd();
glPopMatrix();
}
bool ZImage::IsLoaded() bool ZImage::IsLoaded()
{ {
return glIsTexture(rTexID) == GL_TRUE; return glIsTexture(rTexID) == GL_TRUE;

View File

@ -34,17 +34,17 @@ void Initialize()
void Test() void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
float angle=0.0f;
//Open and Setup all the Images// //Open and Setup all the Images//
SDL_Surface *temp; SDL_Surface *temp;
ZImage image1, image2("data/test01.bmp"), image3(image2.Surface(),20,20,20,20), textImage; ZImage image1, image2("data/test01.bmp"), image3(image2.Surface(),5,5,20,20), textImage;
ZFont font("data/almontew.ttf",30); ZFont font("data/almontew.ttf",30);
temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface
image1.Attach(temp); //this attaches the surface into itself image1.Attach(temp); //this attaches the surface into itself
temp = NULL; //and temp will now be controlled and freed by image1 temp = NULL; //and temp will now be controlled and freed by image1
image1.SetColorKey(255,0,255); image1.SetColorKey(255,0,255);
// image2.SetAlpha(75);
image2.SetColorKey(255,0,255); image2.SetColorKey(255,0,255);
font.SetColor(0,255,0); font.SetColor(0,255,0);
font.SetBGColor(0,0,255); font.SetBGColor(0,0,255);
@ -66,7 +66,11 @@ void Test()
engine->Clear(); //clear screen engine->Clear(); //clear screen
//draw the images// //draw the images//
image1.Draw(0,0); image1.Draw(0,0);
image2.Draw(100,0);
image2.DrawRotated(100,0,angle);
if(++angle > 360)
angle = 0.0f;
image3.Draw(200,0); image3.Draw(200,0);
textImage.Draw(0,100); textImage.Draw(0,100);
engine->UpdateScreen(); //update the screen engine->UpdateScreen(); //update the screen