1 | <html> |
---|
2 | <head> |
---|
3 | <title>OgreVector2.h Source File - OGRE Documentation</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> |
---|
4 | <link type="text/css" rel="stylesheet" href="style.css"> |
---|
5 | </head> |
---|
6 | |
---|
7 | <body> |
---|
8 | <!-- Generated by Doxygen 1.3.6 --> |
---|
9 | <div class="qindex"><a class="qindex" href="index.html">Main Page</a> | <a class="qindex" href="namespaces.html">Namespace List</a> | <a class="qindex" href="hierarchy.html">Class Hierarchy</a> | <a class="qindex" href="classes.html">Alphabetical List</a> | <a class="qindex" href="annotated.html">Class List</a> | <a class="qindex" href="files.html">File List</a> | <a class="qindex" href="namespacemembers.html">Namespace Members</a> | <a class="qindex" href="functions.html">Class Members</a> | <a class="qindex" href="globals.html">File Members</a> | <a class="qindex" href="pages.html">Related Pages</a></div> |
---|
10 | <h1>OgreVector2.h</h1><a href="OgreVector2_8h.html">Go to the documentation of this file.</a><div class="fragment"><pre>00001 <span class="comment">/*</span> |
---|
11 | 00002 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
12 | 00003 <span class="comment">This source file is part of OGRE</span> |
---|
13 | 00004 <span class="comment"> (Object-oriented Graphics Rendering Engine)</span> |
---|
14 | 00005 <span class="comment">For the latest info, see http://www.ogre3d.org/</span> |
---|
15 | 00006 <span class="comment"></span> |
---|
16 | 00007 <span class="comment">Copyright (c) 2000-2005 The OGRE Team</span> |
---|
17 | 00008 <span class="comment">Also see acknowledgements in Readme.html</span> |
---|
18 | 00009 <span class="comment"></span> |
---|
19 | 00010 <span class="comment">This program is free software; you can redistribute it and/or modify it under</span> |
---|
20 | 00011 <span class="comment">the terms of the GNU Lesser General Public License as published by the Free Software</span> |
---|
21 | 00012 <span class="comment">Foundation; either version 2 of the License, or (at your option) any later</span> |
---|
22 | 00013 <span class="comment">version.</span> |
---|
23 | 00014 <span class="comment"></span> |
---|
24 | 00015 <span class="comment">This program is distributed in the hope that it will be useful, but WITHOUT</span> |
---|
25 | 00016 <span class="comment">ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS</span> |
---|
26 | 00017 <span class="comment">FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.</span> |
---|
27 | 00018 <span class="comment"></span> |
---|
28 | 00019 <span class="comment">You should have received a copy of the GNU Lesser General Public License along with</span> |
---|
29 | 00020 <span class="comment">this program; if not, write to the Free Software Foundation, Inc., 59 Temple</span> |
---|
30 | 00021 <span class="comment">Place - Suite 330, Boston, MA 02111-1307, USA, or go to</span> |
---|
31 | 00022 <span class="comment">http://www.gnu.org/copyleft/lesser.txt.</span> |
---|
32 | 00023 <span class="comment">-----------------------------------------------------------------------------</span> |
---|
33 | 00024 <span class="comment">*/</span> |
---|
34 | 00025 <span class="preprocessor">#ifndef __Vector2_H__</span> |
---|
35 | 00026 <span class="preprocessor"></span><span class="preprocessor">#define __Vector2_H__</span> |
---|
36 | 00027 <span class="preprocessor"></span> |
---|
37 | 00028 |
---|
38 | 00029 <span class="preprocessor">#include "<a class="code" href="OgrePrerequisites_8h.html">OgrePrerequisites.h</a>"</span> |
---|
39 | 00030 <span class="preprocessor">#include "<a class="code" href="OgreMath_8h.html">OgreMath.h</a>"</span> |
---|
40 | 00031 |
---|
41 | 00032 <span class="keyword">namespace </span>Ogre |
---|
42 | 00033 { |
---|
43 | 00034 |
---|
44 | <a name="l00042"></a><a class="code" href="classOgre_1_1Vector2.html">00042</a> <span class="keyword">class </span><a class="code" href="OgrePlatform_8h.html#a16">_OgreExport</a> Vector2 |
---|
45 | 00043 { |
---|
46 | 00044 <span class="keyword">public</span>: |
---|
47 | 00045 <span class="keyword">union </span>{ |
---|
48 | 00046 <span class="keyword">struct </span>{ |
---|
49 | <a name="l00047"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">00047</a> <a class="code" href="namespaceOgre.html#a420">Real</a> x, y; |
---|
50 | 00048 }; |
---|
51 | <a name="l00049"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o2">00049</a> <a class="code" href="namespaceOgre.html#a420">Real</a> val[2]; |
---|
52 | 00050 }; |
---|
53 | 00051 |
---|
54 | 00052 <span class="keyword">public</span>: |
---|
55 | <a name="l00053"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a0">00053</a> <span class="keyword">inline</span> Vector2() |
---|
56 | 00054 { |
---|
57 | 00055 } |
---|
58 | 00056 |
---|
59 | <a name="l00057"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a1">00057</a> <span class="keyword">inline</span> Vector2( <a class="code" href="namespaceOgre.html#a420">Real</a> fX, <a class="code" href="namespaceOgre.html#a420">Real</a> fY ) |
---|
60 | 00058 : x( fX ), y( fY ) |
---|
61 | 00059 { |
---|
62 | 00060 } |
---|
63 | 00061 |
---|
64 | <a name="l00062"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a2">00062</a> <span class="keyword">inline</span> Vector2( <a class="code" href="namespaceOgre.html#a420">Real</a> afCoordinate[2] ) |
---|
65 | 00063 : x( afCoordinate[0] ), |
---|
66 | 00064 y( afCoordinate[1] ) |
---|
67 | 00065 { |
---|
68 | 00066 } |
---|
69 | 00067 |
---|
70 | <a name="l00068"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a3">00068</a> <span class="keyword">inline</span> Vector2( <span class="keywordtype">int</span> afCoordinate[2] ) |
---|
71 | 00069 { |
---|
72 | 00070 x = (<a class="code" href="namespaceOgre.html#a420">Real</a>)afCoordinate[0]; |
---|
73 | 00071 y = (<a class="code" href="namespaceOgre.html#a420">Real</a>)afCoordinate[1]; |
---|
74 | 00072 } |
---|
75 | 00073 |
---|
76 | <a name="l00074"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a4">00074</a> <span class="keyword">inline</span> Vector2( <span class="keyword">const</span> <a class="code" href="namespaceOgre.html#a420">Real</a>* <span class="keyword">const</span> r ) |
---|
77 | 00075 : x( r[0] ), y( r[1] ) |
---|
78 | 00076 { |
---|
79 | 00077 } |
---|
80 | 00078 |
---|
81 | <a name="l00079"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a5">00079</a> <span class="keyword">inline</span> Vector2( <span class="keyword">const</span> Vector2& rkVector ) |
---|
82 | 00080 : x( rkVector.x ), y( rkVector.y ) |
---|
83 | 00081 { |
---|
84 | 00082 } |
---|
85 | 00083 |
---|
86 | <a name="l00084"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a6">00084</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a> operator [] ( size_t i )<span class="keyword"> const</span> |
---|
87 | 00085 <span class="keyword"> </span>{ |
---|
88 | 00086 assert( i < 2 ); |
---|
89 | 00087 |
---|
90 | 00088 <span class="keywordflow">return</span> *(&x+i); |
---|
91 | 00089 } |
---|
92 | 00090 |
---|
93 | <a name="l00091"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a7">00091</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a>& operator [] ( size_t i ) |
---|
94 | 00092 { |
---|
95 | 00093 assert( i < 2 ); |
---|
96 | 00094 |
---|
97 | 00095 <span class="keywordflow">return</span> *(&x+i); |
---|
98 | 00096 } |
---|
99 | 00097 |
---|
100 | <a name="l00102"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a8">00102</a> <span class="keyword">inline</span> Vector2& operator = ( <span class="keyword">const</span> Vector2& rkVector ) |
---|
101 | 00103 { |
---|
102 | 00104 x = rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
103 | 00105 y = rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
104 | 00106 |
---|
105 | 00107 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
106 | 00108 } |
---|
107 | 00109 |
---|
108 | <a name="l00110"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a9">00110</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceOgre.html#a618">operator == </a>( <span class="keyword">const</span> Vector2& rkVector )<span class="keyword"> const</span> |
---|
109 | 00111 <span class="keyword"> </span>{ |
---|
110 | 00112 <span class="keywordflow">return</span> ( x == rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> && y == rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> ); |
---|
111 | 00113 } |
---|
112 | 00114 |
---|
113 | <a name="l00115"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a10">00115</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> <a class="code" href="namespaceOgre.html#a619">operator != </a>( <span class="keyword">const</span> Vector2& rkVector )<span class="keyword"> const</span> |
---|
114 | 00116 <span class="keyword"> </span>{ |
---|
115 | 00117 <span class="keywordflow">return</span> ( x != rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> || y != rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> ); |
---|
116 | 00118 } |
---|
117 | 00119 |
---|
118 | 00120 <span class="comment">// arithmetic operations</span> |
---|
119 | <a name="l00121"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a11">00121</a> <span class="keyword">inline</span> Vector2 operator + ( <span class="keyword">const</span> Vector2& rkVector )<span class="keyword"> const</span> |
---|
120 | 00122 <span class="keyword"> </span>{ |
---|
121 | 00123 Vector2 kSum; |
---|
122 | 00124 |
---|
123 | 00125 kSum.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = x + rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
124 | 00126 kSum.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = y + rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
125 | 00127 |
---|
126 | 00128 <span class="keywordflow">return</span> kSum; |
---|
127 | 00129 } |
---|
128 | 00130 |
---|
129 | <a name="l00131"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a12">00131</a> <span class="keyword">inline</span> Vector2 operator - ( <span class="keyword">const</span> Vector2& rkVector )<span class="keyword"> const</span> |
---|
130 | 00132 <span class="keyword"> </span>{ |
---|
131 | 00133 Vector2 kDiff; |
---|
132 | 00134 |
---|
133 | 00135 kDiff.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = x - rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
134 | 00136 kDiff.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = y - rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
135 | 00137 |
---|
136 | 00138 <span class="keywordflow">return</span> kDiff; |
---|
137 | 00139 } |
---|
138 | 00140 |
---|
139 | <a name="l00141"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a13">00141</a> <span class="keyword">inline</span> Vector2 <a class="code" href="namespaceOgre.html#a612">operator * </a>( <a class="code" href="namespaceOgre.html#a420">Real</a> fScalar )<span class="keyword"> const</span> |
---|
140 | 00142 <span class="keyword"> </span>{ |
---|
141 | 00143 Vector2 kProd; |
---|
142 | 00144 |
---|
143 | 00145 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = fScalar*x; |
---|
144 | 00146 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = fScalar*y; |
---|
145 | 00147 |
---|
146 | 00148 <span class="keywordflow">return</span> kProd; |
---|
147 | 00149 } |
---|
148 | 00150 |
---|
149 | <a name="l00151"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a14">00151</a> <span class="keyword">inline</span> Vector2 <a class="code" href="namespaceOgre.html#a612">operator * </a>( <span class="keyword">const</span> Vector2& rhs)<span class="keyword"> const</span> |
---|
150 | 00152 <span class="keyword"> </span>{ |
---|
151 | 00153 Vector2 kProd; |
---|
152 | 00154 |
---|
153 | 00155 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> * x; |
---|
154 | 00156 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> * y; |
---|
155 | 00157 |
---|
156 | 00158 <span class="keywordflow">return</span> kProd; |
---|
157 | 00159 } |
---|
158 | 00160 |
---|
159 | <a name="l00161"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a15">00161</a> <span class="keyword">inline</span> Vector2 <a class="code" href="namespaceOgre.html#a613">operator / </a>( <a class="code" href="namespaceOgre.html#a420">Real</a> fScalar )<span class="keyword"> const</span> |
---|
160 | 00162 <span class="keyword"> </span>{ |
---|
161 | 00163 assert( fScalar != 0.0 ); |
---|
162 | 00164 |
---|
163 | 00165 Vector2 kDiv; |
---|
164 | 00166 |
---|
165 | 00167 <a class="code" href="namespaceOgre.html#a420">Real</a> fInv = 1.0 / fScalar; |
---|
166 | 00168 kDiv.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = x * fInv; |
---|
167 | 00169 kDiv.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = y * fInv; |
---|
168 | 00170 |
---|
169 | 00171 <span class="keywordflow">return</span> kDiv; |
---|
170 | 00172 } |
---|
171 | 00173 |
---|
172 | <a name="l00174"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a16">00174</a> <span class="keyword">inline</span> Vector2 operator - ()<span class="keyword"> const</span> |
---|
173 | 00175 <span class="keyword"> </span>{ |
---|
174 | 00176 Vector2 kNeg; |
---|
175 | 00177 |
---|
176 | 00178 kNeg.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = -x; |
---|
177 | 00179 kNeg.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = -y; |
---|
178 | 00180 |
---|
179 | 00181 <span class="keywordflow">return</span> kNeg; |
---|
180 | 00182 } |
---|
181 | 00183 |
---|
182 | <a name="l00184"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2n0">00184</a> <span class="keyword">inline</span> <span class="keyword">friend</span> Vector2 <a class="code" href="namespaceOgre.html#a612">operator * </a>( <a class="code" href="namespaceOgre.html#a420">Real</a> fScalar, <span class="keyword">const</span> Vector2& rkVector ) |
---|
183 | 00185 { |
---|
184 | 00186 Vector2 kProd; |
---|
185 | 00187 |
---|
186 | 00188 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> = fScalar * rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
187 | 00189 kProd.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> = fScalar * rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
188 | 00190 |
---|
189 | 00191 <span class="keywordflow">return</span> kProd; |
---|
190 | 00192 } |
---|
191 | 00193 |
---|
192 | 00194 <span class="comment">// arithmetic updates</span> |
---|
193 | <a name="l00195"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a17">00195</a> <span class="keyword">inline</span> Vector2& operator += ( <span class="keyword">const</span> Vector2& rkVector ) |
---|
194 | 00196 { |
---|
195 | 00197 x += rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
196 | 00198 y += rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
197 | 00199 |
---|
198 | 00200 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
199 | 00201 } |
---|
200 | 00202 |
---|
201 | <a name="l00203"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a18">00203</a> <span class="keyword">inline</span> Vector2& operator -= ( <span class="keyword">const</span> Vector2& rkVector ) |
---|
202 | 00204 { |
---|
203 | 00205 x -= rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
204 | 00206 y -= rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
205 | 00207 |
---|
206 | 00208 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
207 | 00209 } |
---|
208 | 00210 |
---|
209 | <a name="l00211"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a19">00211</a> <span class="keyword">inline</span> Vector2& operator *= ( <a class="code" href="namespaceOgre.html#a420">Real</a> fScalar ) |
---|
210 | 00212 { |
---|
211 | 00213 x *= fScalar; |
---|
212 | 00214 y *= fScalar; |
---|
213 | 00215 |
---|
214 | 00216 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
215 | 00217 } |
---|
216 | 00218 |
---|
217 | <a name="l00219"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a20">00219</a> <span class="keyword">inline</span> Vector2& operator /= ( <a class="code" href="namespaceOgre.html#a420">Real</a> fScalar ) |
---|
218 | 00220 { |
---|
219 | 00221 assert( fScalar != 0.0 ); |
---|
220 | 00222 |
---|
221 | 00223 <a class="code" href="namespaceOgre.html#a420">Real</a> fInv = 1.0 / fScalar; |
---|
222 | 00224 |
---|
223 | 00225 x *= fInv; |
---|
224 | 00226 y *= fInv; |
---|
225 | 00227 |
---|
226 | 00228 <span class="keywordflow">return</span> *<span class="keyword">this</span>; |
---|
227 | 00229 } |
---|
228 | 00230 |
---|
229 | <a name="l00238"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a21">00238</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a> length ()<span class="keyword"> const</span> |
---|
230 | 00239 <span class="keyword"> </span>{ |
---|
231 | 00240 <span class="keywordflow">return</span> Math::Sqrt( x * x + y * y ); |
---|
232 | 00241 } |
---|
233 | 00242 |
---|
234 | <a name="l00253"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a22">00253</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a> squaredLength ()<span class="keyword"> const</span> |
---|
235 | 00254 <span class="keyword"> </span>{ |
---|
236 | 00255 <span class="keywordflow">return</span> x * x + y * y; |
---|
237 | 00256 } |
---|
238 | 00257 |
---|
239 | <a name="l00272"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a23">00272</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a> dotProduct(<span class="keyword">const</span> Vector2& vec)<span class="keyword"> const</span> |
---|
240 | 00273 <span class="keyword"> </span>{ |
---|
241 | 00274 <span class="keywordflow">return</span> x * vec.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> + y * vec.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
242 | 00275 } |
---|
243 | 00276 |
---|
244 | <a name="l00286"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a24">00286</a> <span class="keyword">inline</span> <a class="code" href="namespaceOgre.html#a420">Real</a> normalise() |
---|
245 | 00287 { |
---|
246 | 00288 <a class="code" href="namespaceOgre.html#a420">Real</a> fLength = Math::Sqrt( x * x + y * y); |
---|
247 | 00289 |
---|
248 | 00290 <span class="comment">// Will also work for zero-sized vectors, but will change nothing</span> |
---|
249 | 00291 <span class="keywordflow">if</span> ( fLength > 1e-08 ) |
---|
250 | 00292 { |
---|
251 | 00293 <a class="code" href="namespaceOgre.html#a420">Real</a> fInvLength = 1.0 / fLength; |
---|
252 | 00294 x *= fInvLength; |
---|
253 | 00295 y *= fInvLength; |
---|
254 | 00296 } |
---|
255 | 00297 |
---|
256 | 00298 <span class="keywordflow">return</span> fLength; |
---|
257 | 00299 } |
---|
258 | 00300 |
---|
259 | 00301 |
---|
260 | 00302 |
---|
261 | <a name="l00306"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a25">00306</a> <span class="keyword">inline</span> Vector2 midPoint( <span class="keyword">const</span> Vector2& vec )<span class="keyword"> const</span> |
---|
262 | 00307 <span class="keyword"> </span>{ |
---|
263 | 00308 <span class="keywordflow">return</span> Vector2( |
---|
264 | 00309 ( x + vec.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> ) * 0.5, |
---|
265 | 00310 ( y + vec.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> ) * 0.5 ); |
---|
266 | 00311 } |
---|
267 | 00312 |
---|
268 | <a name="l00316"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a26">00316</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator < ( <span class="keyword">const</span> Vector2& rhs )<span class="keyword"> const</span> |
---|
269 | 00317 <span class="keyword"> </span>{ |
---|
270 | 00318 <span class="keywordflow">if</span>( x < rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> && y < rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> ) |
---|
271 | 00319 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
---|
272 | 00320 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
---|
273 | 00321 } |
---|
274 | 00322 |
---|
275 | <a name="l00326"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a27">00326</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> operator > ( <span class="keyword">const</span> Vector2& rhs )<span class="keyword"> const</span> |
---|
276 | 00327 <span class="keyword"> </span>{ |
---|
277 | 00328 <span class="keywordflow">if</span>( x > rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> && y > rhs.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> ) |
---|
278 | 00329 <span class="keywordflow">return</span> <span class="keyword">true</span>; |
---|
279 | 00330 <span class="keywordflow">return</span> <span class="keyword">false</span>; |
---|
280 | 00331 } |
---|
281 | 00332 |
---|
282 | <a name="l00340"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a28">00340</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> makeFloor( <span class="keyword">const</span> Vector2& cmp ) |
---|
283 | 00341 { |
---|
284 | 00342 <span class="keywordflow">if</span>( cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> < x ) x = cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
285 | 00343 <span class="keywordflow">if</span>( cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> < y ) y = cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
286 | 00344 } |
---|
287 | 00345 |
---|
288 | <a name="l00353"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a29">00353</a> <span class="keyword">inline</span> <span class="keywordtype">void</span> makeCeil( <span class="keyword">const</span> Vector2& cmp ) |
---|
289 | 00354 { |
---|
290 | 00355 <span class="keywordflow">if</span>( cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> > x ) x = cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>; |
---|
291 | 00356 <span class="keywordflow">if</span>( cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a> > y ) y = cmp.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>; |
---|
292 | 00357 } |
---|
293 | 00358 |
---|
294 | <a name="l00366"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a30">00366</a> <span class="keyword">inline</span> Vector2 perpendicular(<span class="keywordtype">void</span>)<span class="keyword"> const</span> |
---|
295 | 00367 <span class="keyword"> </span>{ |
---|
296 | 00368 <span class="keywordflow">return</span> Vector2 (-y, x); |
---|
297 | 00369 } |
---|
298 | <a name="l00397"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a31">00397</a> <span class="keyword">inline</span> Vector2 crossProduct( <span class="keyword">const</span> Vector2& rkVector )<span class="keyword"> const</span> |
---|
299 | 00398 <span class="keyword"> </span>{ |
---|
300 | 00399 <span class="keywordflow">return</span> Vector2(-rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o1">y</a>, rkVector.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a>); |
---|
301 | 00400 } |
---|
302 | <a name="l00420"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a32">00420</a> <span class="keyword">inline</span> Vector2 randomDeviant( |
---|
303 | 00421 <a class="code" href="namespaceOgre.html#a420">Real</a> angle)<span class="keyword"> const</span> |
---|
304 | 00422 <span class="keyword"> </span>{ |
---|
305 | 00423 |
---|
306 | 00424 angle *= Math::UnitRandom() * Math::TWO_PI; |
---|
307 | 00425 <a class="code" href="namespaceOgre.html#a420">Real</a> cosa = cos(angle); |
---|
308 | 00426 <a class="code" href="namespaceOgre.html#a420">Real</a> sina = sin(angle); |
---|
309 | 00427 <span class="keywordflow">return</span> Vector2(cosa * x - sina * y, |
---|
310 | 00428 sina * x + cosa * y); |
---|
311 | 00429 } |
---|
312 | 00430 |
---|
313 | <a name="l00432"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a33">00432</a> <span class="keyword">inline</span> <span class="keywordtype">bool</span> isZeroLength(<span class="keywordtype">void</span>)<span class="keyword"> const</span> |
---|
314 | 00433 <span class="keyword"> </span>{ |
---|
315 | 00434 <a class="code" href="namespaceOgre.html#a420">Real</a> sqlen = (x * x) + (y * y); |
---|
316 | 00435 <span class="keywordflow">return</span> (sqlen < (1e-06 * 1e-06)); |
---|
317 | 00436 |
---|
318 | 00437 } |
---|
319 | 00438 |
---|
320 | <a name="l00441"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a34">00441</a> <span class="keyword">inline</span> Vector2 normalisedCopy(<span class="keywordtype">void</span>)<span class="keyword"> const</span> |
---|
321 | 00442 <span class="keyword"> </span>{ |
---|
322 | 00443 Vector2 ret = *<span class="keyword">this</span>; |
---|
323 | 00444 ret.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a24">normalise</a>(); |
---|
324 | 00445 <span class="keywordflow">return</span> ret; |
---|
325 | 00446 } |
---|
326 | 00447 |
---|
327 | <a name="l00451"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2a35">00451</a> <span class="keyword">inline</span> Vector2 reflect(<span class="keyword">const</span> Vector2& normal)<span class="keyword"> const</span> |
---|
328 | 00452 <span class="keyword"> </span>{ |
---|
329 | 00453 <span class="keywordflow">return</span> Vector2( *<span class="keyword">this</span> - ( 2 * this->dotProduct(normal) * normal ) ); |
---|
330 | 00454 } |
---|
331 | 00455 |
---|
332 | 00456 <span class="comment">// special points</span> |
---|
333 | <a name="l00457"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s0">00457</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 ZERO; |
---|
334 | <a name="l00458"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s1">00458</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 UNIT_X; |
---|
335 | <a name="l00459"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s2">00459</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 UNIT_Y; |
---|
336 | <a name="l00460"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s3">00460</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 NEGATIVE_UNIT_X; |
---|
337 | <a name="l00461"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s4">00461</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 NEGATIVE_UNIT_Y; |
---|
338 | <a name="l00462"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2s5">00462</a> <span class="keyword">static</span> <span class="keyword">const</span> Vector2 UNIT_SCALE; |
---|
339 | 00463 |
---|
340 | 00466 <span class="keyword">inline</span> <a class="code" href="class__OgreExport.html">_OgreExport</a> <span class="keyword">friend</span> std::ostream& <span class="keyword">operator</span> << |
---|
341 | <a name="l00467"></a><a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2n1">00467</a> ( std::ostream& o, <span class="keyword">const</span> Vector2& v ) |
---|
342 | 00468 { |
---|
343 | 00469 o << <span class="stringliteral">"Vector2("</span> << v.<a class="code" href="classOgre_1_1Vector2.html#Ogre_1_1Vector2o0">x</a> << <span class="stringliteral">", "</span> << v.y << <span class="stringliteral">")"</span>; |
---|
344 | 00470 <span class="keywordflow">return</span> o; |
---|
345 | 00471 } |
---|
346 | 00472 }; |
---|
347 | 00473 |
---|
348 | 00474 } |
---|
349 | 00475 <span class="preprocessor">#endif</span> |
---|
350 | </pre></div><hr> |
---|
351 | <p> |
---|
352 | Copyright © 2000-2005 by The OGRE Team<br /> |
---|
353 | <!--Creative Commons License--><a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/"><img alt="Creative Commons License" border="0" src="http://creativecommons.org/images/public/somerights20.png"/></a><br/> |
---|
354 | This work is licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-sa/2.5/">Creative Commons Attribution-ShareAlike 2.5 License</a>.<br/> |
---|
355 | <!--/Creative Commons License--><!-- <rdf:RDF xmlns="http://web.resource.org/cc/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"> |
---|
356 | <Work rdf:about=""> |
---|
357 | <license rdf:resource="http://creativecommons.org/licenses/by-sa/2.5/" /> |
---|
358 | <dc:type rdf:resource="http://purl.org/dc/dcmitype/Text" /> |
---|
359 | </Work> |
---|
360 | <License rdf:about="http://creativecommons.org/licenses/by-sa/2.5/"><permits rdf:resource="http://web.resource.org/cc/Reproduction"/><permits rdf:resource="http://web.resource.org/cc/Distribution"/><requires rdf:resource="http://web.resource.org/cc/Notice"/><requires rdf:resource="http://web.resource.org/cc/Attribution"/><permits rdf:resource="http://web.resource.org/cc/DerivativeWorks"/><requires rdf:resource="http://web.resource.org/cc/ShareAlike"/></License></rdf:RDF> --> |
---|
361 | |
---|
362 | Last modified Sun Feb 12 12:59:54 2006 |
---|
363 | </p> |
---|
364 | </body> |
---|
365 | </html> |
---|