00001 00002 // 00003 // SFML - Simple and Fast Multimedia Library 00004 // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) 00005 // 00006 // This software is provided 'as-is', without any express or implied warranty. 00007 // In no event will the authors be held liable for any damages arising from the use of this software. 00008 // 00009 // Permission is granted to anyone to use this software for any purpose, 00010 // including commercial applications, and to alter it and redistribute it freely, 00011 // subject to the following restrictions: 00012 // 00013 // 1. The origin of this software must not be misrepresented; 00014 // you must not claim that you wrote the original software. 00015 // If you use this software in a product, an acknowledgment 00016 // in the product documentation would be appreciated but is not required. 00017 // 00018 // 2. Altered source versions must be plainly marked as such, 00019 // and must not be misrepresented as being the original software. 00020 // 00021 // 3. This notice may not be removed or altered from any source distribution. 00022 // 00024 00026 // Headers 00028 #include <SFML/Graphics/View.hpp> 00029 00030 00031 namespace sf 00032 { 00034 View::View() : 00035 myCenter (), 00036 mySize (), 00037 myRotation (0), 00038 myViewport (0, 0, 1, 1), 00039 myMatrixUpdated (false), 00040 myInvMatrixUpdated(false) 00041 { 00042 Reset(FloatRect(0, 0, 1000, 1000)); 00043 } 00044 00045 00047 View::View(const FloatRect& rectangle) : 00048 myCenter (), 00049 mySize (), 00050 myRotation (0), 00051 myViewport (0, 0, 1, 1), 00052 myMatrixUpdated (false), 00053 myInvMatrixUpdated(false) 00054 { 00055 Reset(rectangle); 00056 } 00057 00058 00060 View::View(const Vector2f& center, const Vector2f& size) : 00061 myCenter (center), 00062 mySize (size), 00063 myRotation (0), 00064 myViewport (0, 0, 1, 1), 00065 myMatrixUpdated (false), 00066 myInvMatrixUpdated(false) 00067 { 00068 00069 } 00070 00072 void View::SetCenter(float x, float y) 00073 { 00074 myCenter.x = x; 00075 myCenter.y = y; 00076 00077 myMatrixUpdated = false; 00078 myInvMatrixUpdated = false; 00079 } 00080 00081 00083 void View::SetCenter(const Vector2f& center) 00084 { 00085 SetCenter(center.x, center.y); 00086 } 00087 00088 00090 void View::SetSize(float width, float height) 00091 { 00092 mySize.x = width; 00093 mySize.y = height; 00094 00095 myMatrixUpdated = false; 00096 myInvMatrixUpdated = false; 00097 } 00098 00099 00101 void View::SetSize(const Vector2f& size) 00102 { 00103 SetSize(size.x, size.y); 00104 } 00105 00106 00108 void View::SetRotation(float angle) 00109 { 00110 myRotation = static_cast<float>(fmod(angle, 360)); 00111 if (myRotation < 0) 00112 myRotation += 360.f; 00113 00114 myMatrixUpdated = false; 00115 myInvMatrixUpdated = false; 00116 } 00117 00118 00120 void View::SetViewport(const FloatRect& viewport) 00121 { 00122 myViewport = viewport; 00123 } 00124 00125 00127 void View::Reset(const FloatRect& rectangle) 00128 { 00129 myCenter = rectangle.GetCenter(); 00130 mySize = rectangle.GetSize(); 00131 myRotation = 0; 00132 00133 myMatrixUpdated = false; 00134 myInvMatrixUpdated = false; 00135 } 00136 00137 00139 const Vector2f& View::GetCenter() const 00140 { 00141 return myCenter; 00142 } 00143 00144 00146 const Vector2f& View::GetSize() const 00147 { 00148 return mySize; 00149 } 00150 00151 00153 float View::GetRotation() const 00154 { 00155 return myRotation; 00156 } 00157 00158 00160 const FloatRect& View::GetViewport() const 00161 { 00162 return myViewport; 00163 } 00164 00165 00167 void View::Move(float offsetX, float offsetY) 00168 { 00169 SetCenter(myCenter.x + offsetX, myCenter.y + offsetY); 00170 } 00171 00172 00174 void View::Move(const Vector2f& offset) 00175 { 00176 SetCenter(myCenter + offset); 00177 } 00178 00179 00181 void View::Rotate(float angle) 00182 { 00183 SetRotation(myRotation + angle); 00184 } 00185 00186 00188 void View::Zoom(float factor) 00189 { 00190 SetSize(mySize.x * factor, mySize.y * factor); 00191 } 00192 00193 00195 const Matrix3& View::GetMatrix() const 00196 { 00197 // Recompute the matrix if needed 00198 if (!myMatrixUpdated) 00199 { 00200 myMatrix.SetFromProjection(myCenter, mySize, myRotation); 00201 myMatrixUpdated = true; 00202 } 00203 00204 return myMatrix; 00205 } 00206 00207 00209 const Matrix3& View::GetInverseMatrix() const 00210 { 00211 // Recompute the matrix if needed 00212 if (!myInvMatrixUpdated) 00213 { 00214 myInverseMatrix = GetMatrix().GetInverse(); 00215 myInvMatrixUpdated = true; 00216 } 00217 00218 return myInverseMatrix; 00219 } 00220 00221 } // namespace sf
:: Copyright © 2007-2008 Laurent Gomila, all rights reserved :: Documentation generated by doxygen 1.5.2 ::