ZRect to floats.

This commit is contained in:
James Turk 2002-12-04 05:22:39 +00:00
parent e135a38e91
commit ff3c22d38e
3 changed files with 45 additions and 43 deletions

View File

@ -13,7 +13,7 @@
File: ZE_ZRect.h <br> File: ZE_ZRect.h <br>
Description: Header file for core ZEngine Rectangle Object. <br> Description: Header file for core ZEngine Rectangle Object. <br>
Author(s): James Turk <br> Author(s): James Turk <br>
$Id: ZE_ZRect.h,v 1.2 2002/12/01 08:36:39 cozman Exp $<br> $Id: ZE_ZRect.h,v 1.3 2002/12/04 05:22:40 cozman Exp $<br>
\file ZE_ZRect.h \file ZE_ZRect.h
\brief Definition file for ZRect. \brief Definition file for ZRect.
@ -38,13 +38,13 @@ class ZRect
{ {
protected: protected:
//! X Position of top left corner of rectangle. //! X Position of top left corner of rectangle.
int rX; float rX;
//! Y Position of top left corner of rectangle. //! Y Position of top left corner of rectangle.
int rY; float rY;
//! Width of Rectangle. //! Width of Rectangle.
int rWidth; float rWidth;
//! Height of Rectangle. //! Height of Rectangle.
int rHeight; float rHeight;
public: public:
@ -64,7 +64,7 @@ class ZRect
\param width Value for width. \param width Value for width.
\param height Value for height. \param height Value for height.
**/ **/
ZRect(int x, int y, int width, int height); ZRect(float x, float y, float width, float height);
/*! /*!
\brief Copy constructor for ZRect. \brief Copy constructor for ZRect.
@ -111,7 +111,7 @@ class ZRect
\param x New x position for rectangle. \param x New x position for rectangle.
\param y New y position for rectangle. \param y New y position for rectangle.
**/ **/
void Move(int x, int y); void Move(float x, float y);
/*! /*!
\brief Changes the location of the rectangle based upon the current location. \brief Changes the location of the rectangle based upon the current location.
@ -120,7 +120,7 @@ class ZRect
\param xMove Offset for new x position from current. \param xMove Offset for new x position from current.
\param yMove Offset for new y position from current. \param yMove Offset for new y position from current.
**/ **/
void MoveRel(int xMove, int yMove); void MoveRel(float xMove, float yMove);
/*! /*!
\brief Resize rectangle. \brief Resize rectangle.
@ -129,7 +129,7 @@ class ZRect
\param width New width for rectangle. \param width New width for rectangle.
\param height New height for rectangle. \param height New height for rectangle.
**/ **/
void Resize(int width, int height); void Resize(float width, float height);
/*! /*!
\brief Grows or shrinks current rectangle. \brief Grows or shrinks current rectangle.
@ -138,7 +138,7 @@ class ZRect
\param widthChange Amount to add or subtract from width. \param widthChange Amount to add or subtract from width.
\param heightChange Amount to add or subtract from height. \param heightChange Amount to add or subtract from height.
**/ **/
void ResizeRel(int widthChange, int heightChange); void ResizeRel(float widthChange, float heightChange);
/*! /*!
\brief Check if one ZRect intersects another. \brief Check if one ZRect intersects another.
@ -157,7 +157,7 @@ class ZRect
\param y Y value of poitn to check. \param y Y value of poitn to check.
\return Boolean variable, true if point is inside rectangle, false otherwise. \return Boolean variable, true if point is inside rectangle, false otherwise.
**/ **/
bool Contains(int x, int y) const; bool Contains(float x, float y) const;
/*! /*!
\brief Check if a rectangle contains a given point. \brief Check if a rectangle contains a given point.
@ -191,7 +191,7 @@ class ZRect
Access private X location member. Access private X location member.
\return Value of mX. \return Value of mX.
**/ **/
int X() const; float X() const;
/*! /*!
\brief Returns Y Location. \brief Returns Y Location.
@ -199,7 +199,7 @@ class ZRect
Access private Y location member. Access private Y location member.
\return Value of mY. \return Value of mY.
**/ **/
int Y() const; float Y() const;
/*! /*!
\brief Return position of left side. \brief Return position of left side.
@ -207,7 +207,7 @@ class ZRect
Find X position of left side of rectangle. Find X position of left side of rectangle.
\return X position of left side. \return X position of left side.
**/ **/
int Left() const; float Left() const;
/*! /*!
\brief Return position of right side. \brief Return position of right side.
@ -215,7 +215,7 @@ class ZRect
Find X position of right side of rectangle. Find X position of right side of rectangle.
\return X position of right side. \return X position of right side.
**/ **/
int Right() const; float Right() const;
/*! /*!
\brief Return position of top side. \brief Return position of top side.
@ -223,7 +223,7 @@ class ZRect
Find Y position of top side of rectangle. Find Y position of top side of rectangle.
\return Y position of top side. \return Y position of top side.
**/ **/
int Top() const; float Top() const;
/*! /*!
\brief Return position of bottom side. \brief Return position of bottom side.
@ -231,7 +231,7 @@ class ZRect
Find Y position of left side of rectangle. Find Y position of left side of rectangle.
\return Y position of bottom side. \return Y position of bottom side.
**/ **/
int Bottom() const; float Bottom() const;
/*! /*!
\brief Returns Width. \brief Returns Width.
@ -239,7 +239,7 @@ class ZRect
Access private width member. Access private width member.
\return Value of mWidth. \return Value of mWidth.
**/ **/
int Width() const; float Width() const;
/*! /*!
\brief Returns Height. \brief Returns Height.
@ -247,7 +247,7 @@ class ZRect
Access private height member. Access private height member.
\return Value of mHeight. \return Value of mHeight.
**/ **/
int Height() const; float Height() const;
}; };
} //namspace ZE } //namspace ZE

View File

@ -13,7 +13,7 @@
File: ZE_ZRect.cpp <br> File: ZE_ZRect.cpp <br>
Description: Implementation source file for core ZEngine Rectangle Object. <br> Description: Implementation source file for core ZEngine Rectangle Object. <br>
Author(s): James Turk <br> Author(s): James Turk <br>
$Id: ZE_ZRect.cpp,v 1.2 2002/12/01 08:36:39 cozman Exp $<br> $Id: ZE_ZRect.cpp,v 1.3 2002/12/04 05:22:39 cozman Exp $<br>
\file ZE_ZRect.cpp \file ZE_ZRect.cpp
\brief Source file for ZRect. \brief Source file for ZRect.
@ -31,7 +31,7 @@ ZRect::ZRect() :
{ {
} }
ZRect::ZRect(int x, int y, int width, int height) : ZRect::ZRect(float x, float y, float width, float height) :
rX(x),rY(y),rWidth(width),rHeight(height) rX(x),rY(y),rWidth(width),rHeight(height)
{ {
} }
@ -90,32 +90,32 @@ void ZRect::Draw(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha)
{ {
glColor4ub(red,green,blue,alpha); glColor4ub(red,green,blue,alpha);
glBegin(GL_QUADS); glBegin(GL_QUADS);
glVertex2i(rX, rY); glVertex2f(rX, rY);
glVertex2i(rX+rWidth, rY); glVertex2f(rX+rWidth, rY);
glVertex2i(rX+rWidth, rY+rHeight); glVertex2f(rX+rWidth, rY+rHeight);
glVertex2i(rX, rY+rHeight); glVertex2f(rX, rY+rHeight);
glEnd(); glEnd();
} }
void ZRect::Move(int x, int y) void ZRect::Move(float x, float y)
{ {
rX = x; rX = x;
rY = y; rY = y;
} }
void ZRect::MoveRel(int xMove, int yMove) void ZRect::MoveRel(float xMove, float yMove)
{ {
rX += xMove; rX += xMove;
rY += yMove; rY += yMove;
} }
void ZRect::Resize(int width, int height) void ZRect::Resize(float width, float height)
{ {
rWidth = width; rWidth = width;
rHeight = height; rHeight = height;
} }
void ZRect::ResizeRel(int widthChange, int heightChange) void ZRect::ResizeRel(float widthChange, float heightChange)
{ {
rWidth += widthChange; rWidth += widthChange;
rHeight += heightChange; rHeight += heightChange;
@ -127,7 +127,7 @@ bool ZRect::Intersects(const ZRect &rect) const
rY > rect.Bottom() || rect.Top() > rY+rHeight); rY > rect.Bottom() || rect.Top() > rY+rHeight);
} }
bool ZRect::Contains(int x, int y) const bool ZRect::Contains(float x, float y) const
{ {
return x > rX && x < rX+rWidth && y > rY && y < rY+rHeight; return x > rX && x < rX+rWidth && y > rY && y < rY+rHeight;
} }
@ -141,7 +141,7 @@ bool ZRect::Contains(const ZRect &rect) const
ZRect ZRect::Intersection(const ZRect &rect) const ZRect ZRect::Intersection(const ZRect &rect) const
{ {
int tempX=0,tempY=0,tempW=0,tempH=0; float tempX=0,tempY=0,tempW=0,tempH=0;
if(Intersects(rect)) if(Intersects(rect))
{ {
@ -169,42 +169,42 @@ SDL_Rect ZRect::SDLrect() const
return ret; return ret;
} }
int ZRect::X() const float ZRect::X() const
{ {
return rX; return rX;
} }
int ZRect::Y() const float ZRect::Y() const
{ {
return rY; return rY;
} }
int ZRect::Left() const float ZRect::Left() const
{ {
return rX; return rX;
} }
int ZRect::Right() const float ZRect::Right() const
{ {
return rX+rWidth; return rX+rWidth;
} }
int ZRect::Top() const float ZRect::Top() const
{ {
return rY; return rY;
} }
int ZRect::Bottom() const float ZRect::Bottom() const
{ {
return rY+rHeight; return rY+rHeight;
} }
int ZRect::Width() const float ZRect::Width() const
{ {
return rWidth; return rWidth;
} }
int ZRect::Height() const float ZRect::Height() const
{ {
return rHeight; return rHeight;
} }

View File

@ -35,6 +35,7 @@ void Test()
{ {
ZEngine *engine = ZEngine::GetInstance(); ZEngine *engine = ZEngine::GetInstance();
ZRect moveRect(0,0,25,25),stillRect(100,100,100,100); ZRect moveRect(0,0,25,25),stillRect(100,100,100,100);
double movDelta;
do do
{ {
@ -49,14 +50,15 @@ void Test()
if(engine->KeyIsPressed(SDLK_ESCAPE)) if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit(); engine->RequestQuit();
//movement// //movement//
movDelta = engine->GetFrameTime()*30;
if(engine->KeyPress(SDLK_LEFT)) if(engine->KeyPress(SDLK_LEFT))
moveRect.MoveRel(-3,0); moveRect.MoveRel(-movDelta,0);
if(engine->KeyPress(SDLK_RIGHT)) if(engine->KeyPress(SDLK_RIGHT))
moveRect.MoveRel(3,0); moveRect.MoveRel(movDelta,0);
if(engine->KeyPress(SDLK_UP)) if(engine->KeyPress(SDLK_UP))
moveRect.MoveRel(0,-3); moveRect.MoveRel(0,-movDelta);
if(engine->KeyPress(SDLK_DOWN)) if(engine->KeyPress(SDLK_DOWN))
moveRect.MoveRel(0,3); moveRect.MoveRel(0,movDelta);
if(engine->KeyIsPressed(SDLK_EQUALS)) if(engine->KeyIsPressed(SDLK_EQUALS))
{ {
moveRect.MoveRel(-1,-1); moveRect.MoveRel(-1,-1);