1 /*************************************************************************
2  *                                                                       *
3  * Tokamak Physics Engine, Copyright (C) 2002-2007 David Lam.            *
4  * All rights reserved.  Email: david@tokamakphysics.com                 *
5  *                       Web: www.tokamakphysics.com                     *
6  *                                                                       *
7  * This library is distributed in the hope that it will be useful,       *
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files    *
10  * LICENSE.TXT for more details.                                         *
11  *                                                                       *
12  *************************************************************************/
13 
14 ///////////////////////////////////////////////////////////////////////////
15 // VECTOR4 MEMBER FUNCTIONS
16 ///////////////////////////////////////////////////////////////////////////
17 
18 //=========================================================================
19 
neV4(void)20 NEINLINE neV4::neV4( void ){}
21 
22 //=========================================================================
23 
neV4(f32 x,f32 y,f32 z,f32 w)24 NEINLINE neV4::neV4( f32 x, f32 y, f32 z, f32 w )
25 {
26     X = x; Y = y; Z = z; W = w;
27 }
28 
29 //=========================================================================
30 
neV4(const neV4 & V)31 NEINLINE neV4::neV4( const neV4& V )
32 {
33     (*this) = V;
34 }
35 
36 //=========================================================================
37 
neV4(const neV3 & V,f32 w)38 NEINLINE neV4::neV4( const neV3& V, f32 w )
39 {
40     X = V.X(); Y = V.Y(); Z = V.Z(); W = w;
41 }
42 
43 //=========================================================================
44 
Length(void)45 NEINLINE f32 neV4::Length( void ) const
46 {
47     return (f32)sqrt( this->Dot( *this ) );
48 }
49 
50 //=========================================================================
51 
Normalize(void)52 NEINLINE neV4& neV4::Normalize( void )
53 {
54     *this *= 1 / Length();
55     return *this;
56 }
57 
58 //=========================================================================
59 
SetZero(void)60 NEINLINE void neV4::SetZero( void )
61 {
62     X = Y = Z = W = 0;
63 }
64 
65 //=========================================================================
66 
Set(f32 x,f32 y,f32 z,f32 w)67 NEINLINE void neV4::Set( f32 x, f32 y, f32 z, f32 w )
68 {
69     X = x; Y = y; Z = z; W = w;
70 }
71 
72 //=========================================================================
73 
Dot(const neV4 & V)74 NEINLINE f32 neV4::Dot( const neV4& V ) const
75 {
76     return  X * V.X + Y * V.Y + Z * V.Z + W * V.W;
77 }
78 
79 //=========================================================================
80 
81 NEINLINE f32& neV4::operator[]( s32 I )
82 {
83     ASSERT( I >= 0 );
84     ASSERT( I <= 3 );
85     return ((f32*)this)[I];
86 }
87 
88 //=========================================================================
89 
90 NEINLINE neV4& neV4::operator += ( const neV4& V )
91 {
92     X += V.X; Y += V.Y; Z += V.Z; W += V.W;
93     return *this;
94 }
95 
96 //=========================================================================
97 
98 NEINLINE neV4& neV4::operator -= ( const neV4& V )
99 {
100     X -= V.X; Y -= V.Y; Z -= V.Z;  W -= V.W;
101     return *this;
102 }
103 
104 //=========================================================================
105 
106 NEINLINE neV4& neV4::operator /= ( f32 S )
107 {
108     *this = *this / S;
109     return *this;
110 }
111 
112 //=========================================================================
113 
114 NEINLINE neV4& neV4::operator *= ( f32 S )
115 {
116     *this = *this * S;
117     return *this;
118 }
119 
120 
121 ///////////////////////////////////////////////////////////////////////////
122 // VECTOR4 FRIEND FUNCTIONS
123 ///////////////////////////////////////////////////////////////////////////
124 
125 //=========================================================================
126 
127 NEINLINE neV4 operator - ( const neV4& V )
128 {
129     return neV4( -V.X, -V.Y, -V.Z, -V.W );
130 }
131 
132 //=========================================================================
133 
134 NEINLINE neV4 operator + ( const neV4& V1, const neV4& V2 )
135 {
136     return neV4( V1.X + V2.X, V1.Y + V2.Y, V1.Z + V2.Z, V1.W + V2.W );
137 }
138 
139 //=========================================================================
140 
141 NEINLINE neV4 operator - ( const neV4& V1, const neV4& V2 )
142 {
143     return neV4( V1.X - V2.X, V1.Y - V2.Y, V1.Z - V2.Z, V1.W - V2.W );
144 }
145 
146 //=========================================================================
147 
148 NEINLINE neV4 operator / ( const neV4& V, f32 S )
149 {
150     return V * (1/S);
151 }
152 
153 //=========================================================================
154 
155 NEINLINE neV4 operator * ( const neV4& V, const f32 S )
156 {
157     return neV4( V.X * S, V.Y * S, V.Z * S, V.W * S );
158 }
159 
160 //=========================================================================
161 
162 NEINLINE neV4 operator * ( f32 S,  const neV4& V )
163 {
164     return V * S;
165 }
166 
167 ///////////////////////////////////////////////////////////////////////////
168 // END
169 ///////////////////////////////////////////////////////////////////////////
170 
171