From 7fa309c4af1f61cbe64ca4c88b55bbeafc7e5b25 Mon Sep 17 00:00:00 2001 From: James Turk Date: Mon, 2 Dec 2002 00:36:35 +0000 Subject: [PATCH] OpenGL Rotation and Zooming. --- include/ZE_ZImage.h | 32 ++++++++++++++++++++++++++++++-- include/ZEngine.h | 15 ++++++++------- src/ZE_ZImage.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ test/ZImageTest.cpp | 10 +++++++--- 4 files changed, 83 insertions(+), 18 deletions(-) diff --git a/include/ZE_ZImage.h b/include/ZE_ZImage.h index 805b7a3..e93bcb9 100644 --- a/include/ZE_ZImage.h +++ b/include/ZE_ZImage.h @@ -13,7 +13,7 @@ File: ZE_ZImage.h
Description: Header file for core ZEngine Image and Texture Object.
Author(s): James Turk, Gamer Tazar
-$Id: ZE_ZImage.h,v 1.2 2002/12/01 07:56:17 cozman Exp $
+$Id: ZE_ZImage.h,v 1.3 2002/12/02 00:36:35 cozman Exp $
\file ZE_ZImage.h \brief Definition file for ZImage. @@ -149,6 +149,24 @@ class ZImage : public ZObject **/ 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. @@ -164,7 +182,17 @@ class ZImage : public ZObject \param x X 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// diff --git a/include/ZEngine.h b/include/ZEngine.h index 54d3241..c18f125 100644 --- a/include/ZEngine.h +++ b/include/ZEngine.h @@ -3,7 +3,7 @@ File: ZEngine.h
Description: Public Header File for ZEngine.
Author(s): James Turk
-$Id: ZEngine.h,v 1.3 2002/12/01 07:56:17 cozman Exp $
+$Id: ZEngine.h,v 1.4 2002/12/02 00:36:35 cozman Exp $
\file ZEngine.h \brief Header file for ZEngine. @@ -16,16 +16,17 @@ $Id: ZEngine.h,v 1.3 2002/12/01 07:56:17 cozman Exp $
\mainpage ZEngine Documentation \author James Turk - \version 0.7.7 + \version 0.7.8 \date 1 December, 2002 \section ZEngine About ZEngine
- ZEngine is designed to wrap common interfaces of the SDL API in an Object Oriented manner. 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 - ZEngine hopes to provide a core engine which can be used to develop a game without having to rewrite large amounts - 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 - and making the engine much faster in most test cases. + ZEngine is designed to wrap common interfaces of the SDL API in an Object Oriented manner.
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 ZEngine aims to provide a core engine which can be used to develop a game without having to + rewrite large amounts of code.
+ 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.
\section Licensing Licensing
diff --git a/src/ZE_ZImage.cpp b/src/ZE_ZImage.cpp
index fb6d16f..0ba382c 100644
--- a/src/ZE_ZImage.cpp
+++ b/src/ZE_ZImage.cpp
@@ -13,7 +13,7 @@
 File: ZE_ZImage.cpp 
Description: Implementation source file for core ZEngine Image or Texture Object.
Author(s): James Turk, Gamer Tazar
-$Id: ZE_ZImage.cpp,v 1.3 2002/12/01 07:56:17 cozman Exp $
+$Id: ZE_ZImage.cpp,v 1.4 2002/12/02 00:36:35 cozman Exp $
\file ZE_ZImage.cpp \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."); } +void ZImage::Stretch(float xFactor, float yFactor) +{ + rWidth = static_cast(xFactor*rWidth); + rHeight = static_cast(yFactor*rHeight); +} + +void ZImage::Resize(unsigned int width, unsigned int height) +{ + rWidth = width; + rHeight = height; +} + void ZImage::Bind() { glBindTexture(GL_TEXTURE_2D, rTexID); } -void ZImage::Draw(int x, int y) +void ZImage::Draw(float x, float y) { Bind(); glBegin(GL_TRIANGLE_STRIP); - glTexCoord2f(0.0f,0.0f); glVertex2i(x, y); - glTexCoord2f(rTexMaxX,0.0f); glVertex2i(x+rWidth, y); - glTexCoord2f(0.0f,rTexMaxY); glVertex2i(x, y+rHeight); - glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2i(x+rWidth, y+rHeight); + glTexCoord2f(0.0f,0.0f); glVertex2f(x, y); + glTexCoord2f(rTexMaxX,0.0f); glVertex2f(x+rWidth, y); + glTexCoord2f(0.0f,rTexMaxY); glVertex2f(x, y+rHeight); + glTexCoord2f(rTexMaxX,rTexMaxY); glVertex2f(x+rWidth, y+rHeight); 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() { return glIsTexture(rTexID) == GL_TRUE; diff --git a/test/ZImageTest.cpp b/test/ZImageTest.cpp index 0301c6b..6361303 100644 --- a/test/ZImageTest.cpp +++ b/test/ZImageTest.cpp @@ -34,17 +34,17 @@ void Initialize() void Test() { ZEngine *engine = ZEngine::GetInstance(); + float angle=0.0f; //Open and Setup all the Images// 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); temp = SDL_LoadBMP("data/test02.bmp"); //this is a separate surface image1.Attach(temp); //this attaches the surface into itself temp = NULL; //and temp will now be controlled and freed by image1 image1.SetColorKey(255,0,255); -// image2.SetAlpha(75); image2.SetColorKey(255,0,255); font.SetColor(0,255,0); font.SetBGColor(0,0,255); @@ -66,7 +66,11 @@ void Test() engine->Clear(); //clear screen //draw the images// image1.Draw(0,0); - image2.Draw(100,0); + + image2.DrawRotated(100,0,angle); + if(++angle > 360) + angle = 0.0f; + image3.Draw(200,0); textImage.Draw(0,100); engine->UpdateScreen(); //update the screen