- Cal3D 0.11 API Reference -

vector.h
1 //****************************************************************************//
2 // vector.h //
3 // Copyright (C) 2001, 2002 Bruno 'Beosil' Heidelberger //
4 //****************************************************************************//
5 // This library is free software; you can redistribute it and/or modify it //
6 // under the terms of the GNU Lesser General Public License as published by //
7 // the Free Software Foundation; either version 2.1 of the License, or (at //
8 // your option) any later version. //
9 //****************************************************************************//
10 
11 #ifndef CAL_VECTOR_H
12 #define CAL_VECTOR_H
13 
14 //****************************************************************************//
15 // Includes //
16 //****************************************************************************//
17 
18 #include "cal3d/global.h"
19 #include "cal3d/matrix.h"
20 
21 //****************************************************************************//
22 // Forward declarations //
23 //****************************************************************************//
24 
25 class CalQuaternion;
26 //class CalMatrix;
27 
28 //****************************************************************************//
29 // Class declaration //
30 //****************************************************************************//
31 
32  /*****************************************************************************/
36 class CAL3D_API CalVector
37 {
38 // member variables
39 public:
40  float x ,y ,z;
41 
42 // constructors/destructor
43 public:
44  inline CalVector(): x(0.0f), y(0.0f), z(0.0f) {};
45  inline CalVector(const CalVector& v) : x(v.x), y(v.y), z(v.z) {};
46  inline CalVector(float vx, float vy, float vz): x(vx), y(vy), z(vz) {};
47  inline ~CalVector() {};
48 
49 // member functions
50 public:
51  inline float& operator[](unsigned int i)
52  {
53  return (&x)[i];
54  }
55 
56  inline const float& operator[](unsigned int i) const
57  {
58  return (&x)[i];
59  }
60 
61  inline void operator=(const CalVector& v)
62  {
63  x = v.x;
64  y = v.y;
65  z = v.z;
66  }
67 
68  inline void operator+=(const CalVector& v)
69  {
70  x += v.x;
71  y += v.y;
72  z += v.z;
73  }
74 
75 
76  inline void operator-=(const CalVector& v)
77  {
78  x -= v.x;
79  y -= v.y;
80  z -= v.z;
81  }
82 
83  inline void operator*=(const float d)
84  {
85  x *= d;
86  y *= d;
87  z *= d;
88  }
89 
90  void operator*=(const CalQuaternion& q);
91 
92  inline void operator*=(const CalMatrix &m)
93  {
94  float ox = x;
95  float oy = y;
96  float oz = z;
97  x = m.dxdx*ox + m.dxdy*oy + m.dxdz*oz;
98  y = m.dydx*ox + m.dydy*oy + m.dydz*oz;
99  z = m.dzdx*ox + m.dzdy*oy + m.dzdz*oz;
100  }
101 
102  inline void operator/=(const float d)
103  {
104  x /= d;
105  y /= d;
106  z /= d;
107  }
108 
109  inline bool operator==(const CalVector& v) const
110  {
111  return ((x == v.x) && (y == v.y) && (z == v.z));
112  }
113 
114  inline bool operator!=(const CalVector& v) const
115  {
116  return !operator==(v);
117  }
118 
119  inline void blend(float d, const CalVector& v)
120  {
121  x += d * (v.x - x);
122  y += d * (v.y - y);
123  z += d * (v.z - z);
124  }
125 
126  inline void clear()
127  {
128  x=0.0f;
129  y=0.0f;
130  z=0.0f;
131  }
132 
133  inline float length() const
134  {
135  return (float)sqrt(x * x + y * y + z * z);
136  }
137  inline float normalize()
138  {
139  // calculate the length of the vector
140  float length;
141  length = (float) sqrt(x * x + y * y + z * z);
142 
143  float lenRecip = 1.0f / length;
144 
145  // normalize the vector
146  x *= lenRecip;
147  y *= lenRecip;
148  z *= lenRecip;
149 
150  return length;
151  }
152 
153  void set(float vx, float vy, float vz)
154  {
155  x = vx;
156  y = vy;
157  z = vz;
158  }
159 
160 };
161 
162 static inline CalVector operator+(const CalVector& v, const CalVector& u)
163 {
164  return CalVector(v.x + u.x, v.y + u.y, v.z + u.z);
165 }
166 
167 static inline CalVector operator-(const CalVector& v, const CalVector& u)
168 {
169  return CalVector(v.x - u.x, v.y - u.y, v.z - u.z);
170 }
171 
172 static inline CalVector operator*(const CalVector& v, const float d)
173 {
174  return CalVector(v.x * d, v.y * d, v.z * d);
175 }
176 
177 static inline CalVector operator*(const float d, const CalVector& v)
178 {
179  return CalVector(v.x * d, v.y * d, v.z * d);
180 }
181 
182 static inline CalVector operator/(const CalVector& v, const float d)
183 {
184  return CalVector(v.x / d, v.y / d, v.z / d);
185 }
186 
187 static inline float operator*(const CalVector& v, const CalVector& u)
188 {
189  return v.x * u.x + v.y * u.y + v.z * u.z;
190 }
191 
192 static inline CalVector operator%(const CalVector& v, const CalVector& u)
193 {
194  return CalVector(v.y * u.z - v.z * u.y, v.z * u.x - v.x * u.z, v.x * u.y - v.y * u.x);
195 }
196 
197 
198  /*****************************************************************************/
203 class CAL3D_API CalPlane
204 {
205  public:
206  float a,b,c,d;
207 
208  // These methods are made only to calculate the bounding boxes,
209  // don't use them in you program
210 
211  float eval(const CalVector &p);
212  float dist(CalVector &p);
213  void setPosition(const CalVector &p);
214  void setNormal(CalVector &p);
215 };
216 
217  /*****************************************************************************/
222 class CAL3D_API CalBoundingBox
223 {
224  public:
225  CalPlane plane[6];
226 
227  void computePoints(CalVector *p);
228 
229 };
230 
231 
232 
233 #endif
234 
235 //****************************************************************************//
The plane class.
Definition: vector.h:203
The bounding box class.
Definition: vector.h:222
The matrix class.
Definition: matrix.h:34
The vector class.
Definition: vector.h:36
The quaternion class.
Definition: quaternion.h:35

Generated by The Cal3D Team with Doxygen 1.8.14