diff options
author | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
---|---|---|
committer | Jacek Antonelli | 2008-08-15 23:44:46 -0500 |
commit | 38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch) | |
tree | adca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llmath/v2math.cpp | |
parent | README.txt (diff) | |
download | meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2 meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz |
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llmath/v2math.cpp')
-rw-r--r-- | linden/indra/llmath/v2math.cpp | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/linden/indra/llmath/v2math.cpp b/linden/indra/llmath/v2math.cpp new file mode 100644 index 0000000..cee0f73 --- /dev/null +++ b/linden/indra/llmath/v2math.cpp | |||
@@ -0,0 +1,111 @@ | |||
1 | /** | ||
2 | * @file v2math.cpp | ||
3 | * @brief LLVector2 class implementation. | ||
4 | * | ||
5 | * Copyright (c) 2000-2007, Linden Research, Inc. | ||
6 | * | ||
7 | * The source code in this file ("Source Code") is provided by Linden Lab | ||
8 | * to you under the terms of the GNU General Public License, version 2.0 | ||
9 | * ("GPL"), unless you have obtained a separate licensing agreement | ||
10 | * ("Other License"), formally executed by you and Linden Lab. Terms of | ||
11 | * the GPL can be found in doc/GPL-license.txt in this distribution, or | ||
12 | * online at http://secondlife.com/developers/opensource/gplv2 | ||
13 | * | ||
14 | * There are special exceptions to the terms and conditions of the GPL as | ||
15 | * it is applied to this Source Code. View the full text of the exception | ||
16 | * in the file doc/FLOSS-exception.txt in this software distribution, or | ||
17 | * online at http://secondlife.com/developers/opensource/flossexception | ||
18 | * | ||
19 | * By copying, modifying or distributing this software, you acknowledge | ||
20 | * that you have read and understood your obligations described above, | ||
21 | * and agree to abide by those obligations. | ||
22 | * | ||
23 | * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO | ||
24 | * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY, | ||
25 | * COMPLETENESS OR PERFORMANCE. | ||
26 | */ | ||
27 | |||
28 | #include "linden_common.h" | ||
29 | |||
30 | //#include "vmath.h" | ||
31 | #include "v2math.h" | ||
32 | #include "v4math.h" | ||
33 | #include "m4math.h" | ||
34 | #include "m3math.h" | ||
35 | #include "llquaternion.h" | ||
36 | |||
37 | // LLVector2 | ||
38 | |||
39 | LLVector2 LLVector2::zero(0,0); | ||
40 | |||
41 | |||
42 | // Non-member functions | ||
43 | |||
44 | // Sets all values to absolute value of their original values | ||
45 | // Returns TRUE if data changed | ||
46 | BOOL LLVector2::abs() | ||
47 | { | ||
48 | BOOL ret = FALSE; | ||
49 | |||
50 | if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = TRUE; } | ||
51 | if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = TRUE; } | ||
52 | |||
53 | return ret; | ||
54 | } | ||
55 | |||
56 | |||
57 | F32 angle_between(const LLVector2& a, const LLVector2& b) | ||
58 | { | ||
59 | LLVector2 an = a; | ||
60 | LLVector2 bn = b; | ||
61 | an.normVec(); | ||
62 | bn.normVec(); | ||
63 | F32 cosine = an * bn; | ||
64 | F32 angle = (cosine >= 1.0f) ? 0.0f : | ||
65 | (cosine <= -1.0f) ? F_PI : | ||
66 | acos(cosine); | ||
67 | return angle; | ||
68 | } | ||
69 | |||
70 | BOOL are_parallel(const LLVector2 &a, const LLVector2 &b, float epsilon) | ||
71 | { | ||
72 | LLVector2 an = a; | ||
73 | LLVector2 bn = b; | ||
74 | an.normVec(); | ||
75 | bn.normVec(); | ||
76 | F32 dot = an * bn; | ||
77 | if ( (1.0f - fabs(dot)) < epsilon) | ||
78 | { | ||
79 | return TRUE; | ||
80 | } | ||
81 | return FALSE; | ||
82 | } | ||
83 | |||
84 | |||
85 | F32 dist_vec(const LLVector2 &a, const LLVector2 &b) | ||
86 | { | ||
87 | F32 x = a.mV[0] - b.mV[0]; | ||
88 | F32 y = a.mV[1] - b.mV[1]; | ||
89 | return fsqrtf( x*x + y*y ); | ||
90 | } | ||
91 | |||
92 | F32 dist_vec_squared(const LLVector2 &a, const LLVector2 &b) | ||
93 | { | ||
94 | F32 x = a.mV[0] - b.mV[0]; | ||
95 | F32 y = a.mV[1] - b.mV[1]; | ||
96 | return x*x + y*y; | ||
97 | } | ||
98 | |||
99 | F32 dist_vec_squared2D(const LLVector2 &a, const LLVector2 &b) | ||
100 | { | ||
101 | F32 x = a.mV[0] - b.mV[0]; | ||
102 | F32 y = a.mV[1] - b.mV[1]; | ||
103 | return x*x + y*y; | ||
104 | } | ||
105 | |||
106 | LLVector2 lerp(const LLVector2 &a, const LLVector2 &b, F32 u) | ||
107 | { | ||
108 | return LLVector2( | ||
109 | a.mV[VX] + (b.mV[VX] - a.mV[VX]) * u, | ||
110 | a.mV[VY] + (b.mV[VY] - a.mV[VY]) * u ); | ||
111 | } | ||