1 //////////////////////////////////////////////////////////////////////////////// 2 // Copyright (C) 2004-2010 by The Allacrost Project 3 // All Rights Reserved 4 // 5 // This code is licensed under the GNU GPL version 2. It is free software 6 // and you may modify it and/or redistribute it under the terms of this license. 7 // See http://www.gnu.org/copyleft/gpl.html for details. 8 //////////////////////////////////////////////////////////////////////////////// 9 10 /** **************************************************************************** 11 *** \file coord_sys.h 12 *** \author Raj Sharma, roos@allacrost.org 13 *** \brief Header file for the CoordSys class. 14 *** ***************************************************************************/ 15 16 #ifndef __COORD_SYS_HEADER__ 17 #define __COORD_SYS_HEADER__ 18 19 #include "defs.h" 20 #include "utils.h" 21 22 namespace hoa_video { 23 24 /** **************************************************************************** 25 *** \brief Determines the drawing coordinates 26 *** 27 *** The CoordSys structure holds a "coordinate system" defined by a rectangle 28 *** (left, right, bottom, and top) which determines how drawing coordinates 29 *** are mapped to the screen. 30 *** 31 *** \note The default coordinate system is (0, 1024, 0, 768), which is the same 32 *** as the game's default 1024x768 resolution. 33 *** ***************************************************************************/ 34 class CoordSys { 35 public: CoordSys()36 CoordSys() 37 {} 38 CoordSys(float left,float right,float bottom,float top)39 CoordSys(float left, float right, float bottom, float top) 40 { 41 _left = left; _right = right; _bottom = bottom; _top = top; 42 if (_right > _left) _horizontal_direction = 1.0f; else _horizontal_direction = -1.0f; 43 if (_top > _bottom) _vertical_direction = 1.0f; else _vertical_direction = -1.0f; 44 } 45 46 //! \brief Class member access functions 47 //@{ GetVerticalDirection()48 float GetVerticalDirection() const 49 { return _vertical_direction; } 50 GetHorizontalDirection()51 float GetHorizontalDirection() const 52 { return _horizontal_direction; } 53 GetLeft()54 float GetLeft() const 55 { return _left; } 56 GetRight()57 float GetRight() const 58 { return _right; } 59 GetBottom()60 float GetBottom() const 61 { return _bottom; } 62 GetTop()63 float GetTop() const 64 { return _top; } 65 GetWidth()66 float GetWidth() const 67 { return fabs(_left - _right); } 68 GetHeight()69 float GetHeight() const 70 { return fabs(_top - _bottom); } 71 //@} 72 73 //! \brief Normalisation functions 74 //@{ ConvertNormalisedToLocal(float & localX,float & localY,float normalisedX,float normalisedY)75 void ConvertNormalisedToLocal(float& localX, float& localY, float normalisedX, float normalisedY) const 76 { localX = _left + normalisedX * (_right - _left); 77 localY = _bottom + normalisedY * (_top - _bottom); } ConvertLocalToNormalised(float & normalisedX,float & normalisedY,float localX,float localY)78 void ConvertLocalToNormalised(float& normalisedX, float& normalisedY, float localX, float localY) const 79 { normalisedX = (_left - localX) / (_right - _left); 80 normalisedY = (_bottom - localY) / (_top - _bottom); } 81 //@} 82 83 private: 84 //! \brief If the y-coordinates increase from bottom to top, this is 1.0f. Otherwise it is -1.0f. 85 float _vertical_direction; 86 87 //! \brief If the y-coordinates increase from left to right, this is 1.0f. Otherwise it is -1.0f. 88 float _horizontal_direction; 89 90 //! \brief The values of the four sides of the screen that determine the drawing coordinates. 91 float _left, _right, _bottom, _top; 92 }; // class CoordSys 93 94 } // namespace hoa_video 95 96 #endif // __COORD_SYS_HEADER__ 97