aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llmath/v4math.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/llmath/v4math.cpp')
-rw-r--r--linden/indra/llmath/v4math.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/linden/indra/llmath/v4math.cpp b/linden/indra/llmath/v4math.cpp
new file mode 100644
index 0000000..a4af47d
--- /dev/null
+++ b/linden/indra/llmath/v4math.cpp
@@ -0,0 +1,143 @@
1/**
2 * @file v4math.cpp
3 * @brief LLVector4 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 "v3math.h"
32#include "v4math.h"
33#include "m4math.h"
34#include "m3math.h"
35#include "llquaternion.h"
36
37// LLVector4
38
39// Axis-Angle rotations
40
41/*
42const LLVector4& LLVector4::rotVec(F32 angle, const LLVector4 &vec)
43{
44 if ( !vec.isExactlyZero() && angle )
45 {
46 *this = *this * LLMatrix4(angle, vec);
47 }
48 return *this;
49}
50
51const LLVector4& LLVector4::rotVec(F32 angle, F32 x, F32 y, F32 z)
52{
53 LLVector3 vec(x, y, z);
54 if ( !vec.isExactlyZero() && angle )
55 {
56 *this = *this * LLMatrix4(angle, vec);
57 }
58 return *this;
59}
60*/
61
62const LLVector4& LLVector4::rotVec(const LLMatrix4 &mat)
63{
64 *this = *this * mat;
65 return *this;
66}
67
68const LLVector4& LLVector4::rotVec(const LLQuaternion &q)
69{
70 *this = *this * q;
71 return *this;
72}
73
74const LLVector4& LLVector4::scaleVec(const LLVector4& vec)
75{
76 mV[VX] *= vec.mV[VX];
77 mV[VY] *= vec.mV[VY];
78 mV[VZ] *= vec.mV[VZ];
79 mV[VW] *= vec.mV[VW];
80
81 return *this;
82}
83
84// Sets all values to absolute value of their original values
85// Returns TRUE if data changed
86BOOL LLVector4::abs()
87{
88 BOOL ret = FALSE;
89
90 if (mV[0] < 0.f) { mV[0] = -mV[0]; ret = TRUE; }
91 if (mV[1] < 0.f) { mV[1] = -mV[1]; ret = TRUE; }
92 if (mV[2] < 0.f) { mV[2] = -mV[2]; ret = TRUE; }
93 if (mV[3] < 0.f) { mV[3] = -mV[3]; ret = TRUE; }
94
95 return ret;
96}
97
98
99std::ostream& operator<<(std::ostream& s, const LLVector4 &a)
100{
101 s << "{ " << a.mV[VX] << ", " << a.mV[VY] << ", " << a.mV[VZ] << ", " << a.mV[VW] << " }";
102 return s;
103}
104
105
106// Non-member functions
107
108F32 angle_between( const LLVector4& a, const LLVector4& b )
109{
110 LLVector4 an = a;
111 LLVector4 bn = b;
112 an.normVec();
113 bn.normVec();
114 F32 cosine = an * bn;
115 F32 angle = (cosine >= 1.0f) ? 0.0f :
116 (cosine <= -1.0f) ? F_PI :
117 acos(cosine);
118 return angle;
119}
120
121BOOL are_parallel(const LLVector4 &a, const LLVector4 &b, F32 epsilon)
122{
123 LLVector4 an = a;
124 LLVector4 bn = b;
125 an.normVec();
126 bn.normVec();
127 F32 dot = an * bn;
128 if ( (1.0f - fabs(dot)) < epsilon)
129 return TRUE;
130 return FALSE;
131}
132
133
134LLVector3 vec4to3(const LLVector4 &vec)
135{
136 return LLVector3( vec.mV[VX], vec.mV[VY], vec.mV[VZ] );
137}
138
139LLVector4 vec3to4(const LLVector3 &vec)
140{
141 return LLVector4(vec.mV[VX], vec.mV[VY], vec.mV[VZ]);
142}
143