Colobot
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
geometry.h
Go to the documentation of this file.
1 // * This file is part of the COLOBOT source code
2 // * Copyright (C) 2001-2008, Daniel ROUX & EPSITEC SA, www.epsitec.ch
3 // * Copyright (C) 2012, Polish Portal of Colobot (PPC)
4 // *
5 // * This program is free software: you can redistribute it and/or modify
6 // * it under the terms of the GNU General Public License as published by
7 // * the Free Software Foundation, either version 3 of the License, or
8 // * (at your option) any later version.
9 // *
10 // * This program is distributed in the hope that it will be useful,
11 // * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // * GNU General Public License for more details.
14 // *
15 // * You should have received a copy of the GNU General Public License
16 // * along with this program. If not, see http://www.gnu.org/licenses/.
17 
23 #pragma once
24 
25 
26 #include "math/const.h"
27 #include "math/func.h"
28 #include "math/point.h"
29 #include "math/matrix.h"
30 #include "math/vector.h"
31 
32 
33 #include <cmath>
34 #include <cstdlib>
35 
36 
37 // Math module namespace
38 namespace Math {
39 
40 
42 inline float MidPoint(const Math::Point &a, const Math::Point &b, float px)
43 {
44  if (IsEqual(a.x, b.x))
45  {
46  if (a.y < b.y)
47  return Math::HUGE_NUM;
48  else
49  return -Math::HUGE_NUM;
50  }
51  return (b.y-a.y) * (px-a.x) / (b.x-a.x) + a.y;
52 }
53 
56 {
57  float n, m;
58 
59  if ( p.x < a.x && p.x < b.x && p.x < c.x ) return false;
60  if ( p.x > a.x && p.x > b.x && p.x > c.x ) return false;
61  if ( p.y < a.y && p.y < b.y && p.y < c.y ) return false;
62  if ( p.y > a.y && p.y > b.y && p.y > c.y ) return false;
63 
64  if ( a.x > b.x ) Swap(a,b);
65  if ( a.x > c.x ) Swap(a,c);
66  if ( c.x < a.x ) Swap(c,a);
67  if ( c.x < b.x ) Swap(c,b);
68 
69  n = MidPoint(a, b, p.x);
70  m = MidPoint(a, c, p.x);
71  if ( (n>p.y||p.y>m) && (n<p.y||p.y<m) ) return false;
72 
73  n = MidPoint(c, b, p.x);
74  m = MidPoint(c, a, p.x);
75  if ( (n>p.y||p.y>m) && (n<p.y||p.y<m) ) return false;
76 
77  return true;
78 }
79 
81 
86 inline Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
87 {
88  Math::Point a;
89  a.x = p.x-center.x;
90  a.y = p.y-center.y;
91 
92  Math::Point b;
93  b.x = a.x*cosf(angle) - a.y*sinf(angle);
94  b.y = a.x*sinf(angle) + a.y*cosf(angle);
95 
96  b.x += center.x;
97  b.y += center.y;
98 
99  return b;
100 }
101 
103 
107 inline Math::Point RotatePoint(float angle, const Math::Point &p)
108 {
109  float x = p.x*cosf(angle) - p.y*sinf(angle);
110  float y = p.x*sinf(angle) + p.y*cosf(angle);
111 
112  return Math::Point(x, y);
113 }
114 
116 
120 inline Math::Point RotatePoint(float angle, float dist)
121 {
122  float x = dist*cosf(angle);
123  float y = dist*sinf(angle);
124 
125  return Math::Point(x, y);
126 }
127 
129 
134 inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
135 {
136  float ax, ay;
137 
138  px -= cx;
139  py -= cy;
140 
141  ax = px*cosf(angle) - py*sinf(angle);
142  ay = px*sinf(angle) + py*cosf(angle);
143 
144  px = cx+ax;
145  py = cy+ay;
146 }
147 
149 
156 inline void RotatePoint(const Math::Vector &center, float angleH, float angleV, Math::Vector &p)
157 {
158  p.x -= center.x;
159  p.y -= center.y;
160  p.z -= center.z;
161 
162  Math::Vector b;
163  b.x = p.x*cosf(angleH) - p.z*sinf(angleH);
164  b.y = p.z*sinf(angleV) + p.y*cosf(angleV);
165  b.z = p.x*sinf(angleH) + p.z*cosf(angleH);
166 
167  p = center + b;
168 }
169 
171 
178 inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
179 {
180  p.x -= center.x;
181  p.y -= center.y;
182  p.z -= center.z;
183 
184  Math::Vector a;
185  a.x = p.x*cosf(angleH) - p.z*sinf(angleH);
186  a.y = p.y;
187  a.z = p.x*sinf(angleH) + p.z*cosf(angleH);
188 
189  Math::Vector b;
190  b.x = a.x;
191  b.y = a.z*sinf(angleV) + a.y*cosf(angleV);
192  b.z = a.z*cosf(angleV) - a.y*sinf(angleV);
193 
194  p = center + b;
195 }
196 
198 inline float RotateAngle(float x, float y)
199 {
200  if (x == 0.0f && y == 0.0f) return 0.0f;
201 
202  if (x >= 0.0f)
203  {
204  if (y >= 0.0f)
205  {
206  if (x > y) return atanf(y/x);
207  else return PI*0.5f - atanf(x/y);
208  }
209  else
210  {
211  if (x > -y) return PI*2.0f + atanf(y/x);
212  else return PI*1.5f - atanf(x/y);
213  }
214  }
215  else
216  {
217  if (y >= 0.0f)
218  {
219  if (-x > y) return PI*1.0f + atanf(y/x);
220  else return PI*0.5f - atanf(x/y);
221  }
222  else
223  {
224  if (-x > -y) return PI*1.0f + atanf(y/x);
225  else return PI*1.5f - atanf(x/y);
226  }
227  }
228 }
229 
231 
236 inline float RotateAngle(const Math::Point &center, const Math::Point &p1, const Math::Point &p2)
237 {
238  if (PointsEqual(p1, center))
239  return 0;
240 
241  if (PointsEqual(p2, center))
242  return 0;
243 
244  float a1 = asinf((p1.y - center.y) / Distance(p1, center));
245  float a2 = asinf((p2.y - center.y) / Distance(p2, center));
246 
247  if (p1.x < center.x) a1 = PI - a1;
248  if (p2.x < center.x) a2 = PI - a2;
249 
250  float a = a2 - a1;
251  if (a < 0)
252  a += 2.0f*PI;
253 
254  return a;
255 }
256 
258 
264 inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
265  const Math::Vector &at, const Math::Vector &worldUp)
266 {
267  // Get the z basis vector, which points straight ahead. This is the
268  // difference from the eyepoint to the lookat point.
269  Math::Vector view = at - from;
270 
271  float length = view.Length();
272  assert(! IsZero(length) );
273 
274  // Normalize the z basis vector
275  view /= length;
276 
277  // Get the dot product, and calculate the projection of the z basis
278  // vector onto the up vector. The projection is the y basis vector.
279  float dotProduct = DotProduct(worldUp, view);
280 
281  Math::Vector up = worldUp - dotProduct * view;
282 
283  // If this vector has near-zero length because the input specified a
284  // bogus up vector, let's try a default up vector
285  if ( IsZero(length = up.Length()) )
286  {
287  up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view;
288 
289  // If we still have near-zero length, resort to a different axis.
290  if ( IsZero(length = up.Length()) )
291  {
292  up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view;
293 
294  assert(! IsZero(up.Length()) );
295  }
296  }
297 
298  // Normalize the y basis vector
299  up /= length;
300 
301  // The x basis vector is found simply with the cross product of the y
302  // and z basis vectors
303  Math::Vector right = CrossProduct(up, view);
304 
305  // Start building the matrix. The first three rows contains the basis
306  // vectors used to rotate the view to point at the lookat point
307  mat.LoadIdentity();
308 
309  /* (1,1) */ mat.m[0 ] = right.x;
310  /* (2,1) */ mat.m[1 ] = up.x;
311  /* (3,1) */ mat.m[2 ] = view.x;
312  /* (1,2) */ mat.m[4 ] = right.y;
313  /* (2,2) */ mat.m[5 ] = up.y;
314  /* (3,2) */ mat.m[6 ] = view.y;
315  /* (1,3) */ mat.m[8 ] = right.z;
316  /* (2,3) */ mat.m[9 ] = up.z;
317  /* (3,3) */ mat.m[10] = view.z;
318 
319  // Do the translation values (rotations are still about the eyepoint)
320  /* (1,4) */ mat.m[12] = -DotProduct(from, right);
321  /* (2,4) */ mat.m[13] = -DotProduct(from, up);
322  /* (3,4) */ mat.m[14] = -DotProduct(from, view);
323 }
324 
326 
333 inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f, float aspect = 1.0f,
334  float nearPlane = 1.0f, float farPlane = 1000.0f)
335 {
336  assert(fabs(farPlane - nearPlane) >= 0.01f);
337  assert(fabs(sin(fov / 2)) >= 0.01f);
338 
339  float f = cosf(fov / 2.0f) / sinf(fov / 2.0f);
340 
341  mat.LoadZero();
342 
343  /* (1,1) */ mat.m[0 ] = f / aspect;
344  /* (2,2) */ mat.m[5 ] = f;
345  /* (3,3) */ mat.m[10] = (nearPlane + farPlane) / (nearPlane - farPlane);
346  /* (4,3) */ mat.m[11] = -1.0f;
347  /* (3,4) */ mat.m[14] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
348 }
349 
351 
357 inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top,
358  float zNear = -1.0f, float zFar = 1.0f)
359 {
360  mat.LoadIdentity();
361 
362  /* (1,1) */ mat.m[0 ] = 2.0f / (right - left);
363  /* (2,2) */ mat.m[5 ] = 2.0f / (top - bottom);
364  /* (3,3) */ mat.m[10] = -2.0f / (zFar - zNear);
365 
366  /* (1,4) */ mat.m[12] = - (right + left) / (right - left);
367  /* (2,4) */ mat.m[13] = - (top + bottom) / (top - bottom);
368  /* (3,4) */ mat.m[14] = - (zFar + zNear) / (zFar - zNear);
369 }
370 
372 
376 inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
377 {
378  mat.LoadIdentity();
379  /* (1,4) */ mat.m[12] = trans.x;
380  /* (2,4) */ mat.m[13] = trans.y;
381  /* (3,4) */ mat.m[14] = trans.z;
382 }
383 
385 
389 inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
390 {
391  mat.LoadIdentity();
392  /* (1,1) */ mat.m[0 ] = scale.x;
393  /* (2,2) */ mat.m[5 ] = scale.y;
394  /* (3,3) */ mat.m[10] = scale.z;
395 }
396 
398 
402 inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
403 {
404  mat.LoadIdentity();
405  /* (2,2) */ mat.m[5 ] = cosf(angle);
406  /* (3,2) */ mat.m[6 ] = sinf(angle);
407  /* (2,3) */ mat.m[9 ] = -sinf(angle);
408  /* (3,3) */ mat.m[10] = cosf(angle);
409 }
410 
412 
416 inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
417 {
418  mat.LoadIdentity();
419  /* (1,1) */ mat.m[0 ] = cosf(angle);
420  /* (3,1) */ mat.m[2 ] = -sinf(angle);
421  /* (1,3) */ mat.m[8 ] = sinf(angle);
422  /* (3,3) */ mat.m[10] = cosf(angle);
423 }
424 
426 
430 inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
431 {
432  mat.LoadIdentity();
433  /* (1,1) */ mat.m[0 ] = cosf(angle);
434  /* (2,1) */ mat.m[1 ] = sinf(angle);
435  /* (1,2) */ mat.m[4 ] = -sinf(angle);
436  /* (2,2) */ mat.m[5 ] = cosf(angle);
437 }
438 
440 
445 inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
446 {
447  float cos = cosf(angle);
448  float sin = sinf(angle);
449  Math::Vector v = Normalize(dir);
450 
451  mat.LoadIdentity();
452 
453  /* (1,1) */ mat.m[0 ] = (v.x * v.x) * (1.0f - cos) + cos;
454  /* (2,1) */ mat.m[1 ] = (v.x * v.y) * (1.0f - cos) - (v.z * sin);
455  /* (3,1) */ mat.m[2 ] = (v.x * v.z) * (1.0f - cos) + (v.y * sin);
456 
457  /* (1,2) */ mat.m[4 ] = (v.y * v.x) * (1.0f - cos) + (v.z * sin);
458  /* (2,2) */ mat.m[5 ] = (v.y * v.y) * (1.0f - cos) + cos ;
459  /* (3,2) */ mat.m[6 ] = (v.y * v.z) * (1.0f - cos) - (v.x * sin);
460 
461  /* (1,3) */ mat.m[8 ] = (v.z * v.x) * (1.0f - cos) - (v.y * sin);
462  /* (2,3) */ mat.m[9 ] = (v.z * v.y) * (1.0f - cos) + (v.x * sin);
463  /* (3,3) */ mat.m[10] = (v.z * v.z) * (1.0f - cos) + cos;
464 }
465 
467 inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles)
468 {
469  Math::Matrix temp;
470  LoadRotationXMatrix(temp, angles.x);
471 
472  LoadRotationZMatrix(mat, angles.z);
473  mat = Math::MultiplyMatrices(temp, mat);
474 
475  LoadRotationYMatrix(temp, angles.y);
476  mat = Math::MultiplyMatrices(temp, mat);
477 }
478 
480 inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles)
481 {
482  Math::Matrix temp;
483  LoadRotationZMatrix(temp, angles.z);
484 
485  LoadRotationXMatrix(mat, angles.x);
486  mat = Math::MultiplyMatrices(temp, mat);
487 
488  LoadRotationYMatrix(temp, angles.y);
489  mat = Math::MultiplyMatrices(temp, mat);
490 }
491 
493 inline float DistanceProjected(const Math::Vector &a, const Math::Vector &b)
494 {
495  return sqrtf( (a.x-b.x)*(a.x-b.x) +
496  (a.z-b.z)*(a.z-b.z) );
497 }
498 
500 
503 inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3)
504 {
505  Math::Vector u = p3 - p1;
506  Math::Vector v = p2 - p1;
507 
508  return Normalize(CrossProduct(u, v));
509 }
510 
512 
516 inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
517 {
518  return p1 + (p2 - p1) * dist;
519 }
520 
522 
526 inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b,
527  const Math::Vector &c, const Math::Vector &p)
528 {
529  Math::Vector n = NormalToPlane(a, b, c);
530  float d = -(n.x*a.x + n.y*a.y + n.z*a.z);
531 
532  return fabs(n.x*p.x + n.y*p.y + n.z*p.z + d);
533 }
534 
536 
540 inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&plane2)[3])
541 {
542  Math::Vector n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]);
543  Math::Vector n2 = NormalToPlane(plane2[0], plane2[1], plane2[2]);
544 
545  if ( fabs(n1.x-n2.x) > 0.1f ||
546  fabs(n1.y-n2.y) > 0.1f ||
547  fabs(n1.z-n2.z) > 0.1f )
548  return false;
549 
550  float dist = DistanceToPlane(plane1[0], plane1[1], plane1[2], plane2[0]);
551  if ( dist > 0.1f )
552  return false;
553 
554  return true;
555 }
556 
558 inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c,
559  const Math::Vector &d, const Math::Vector &e, Math::Vector &i)
560 {
561  float d1 = (d.x-a.x)*((b.y-a.y)*(c.z-a.z)-(c.y-a.y)*(b.z-a.z)) -
562  (d.y-a.y)*((b.x-a.x)*(c.z-a.z)-(c.x-a.x)*(b.z-a.z)) +
563  (d.z-a.z)*((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
564 
565  float d2 = (d.x-e.x)*((b.y-a.y)*(c.z-a.z)-(c.y-a.y)*(b.z-a.z)) -
566  (d.y-e.y)*((b.x-a.x)*(c.z-a.z)-(c.x-a.x)*(b.z-a.z)) +
567  (d.z-e.z)*((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
568 
569  if (d2 == 0)
570  return false;
571 
572  i.x = d.x + d1/d2*(e.x-d.x);
573  i.y = d.y + d1/d2*(e.y-d.y);
574  i.z = d.z + d1/d2*(e.z-d.z);
575 
576  return true;
577 }
578 
580 
581 inline bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, Math::Vector &p)
582 {
583  float d = (b.x-a.x)*(c.z-a.z) - (c.x-a.x)*(b.z-a.z);
584  float d1 = (p.x-a.x)*(c.z-a.z) - (c.x-a.x)*(p.z-a.z);
585  float d2 = (b.x-a.x)*(p.z-a.z) - (p.x-a.x)*(b.z-a.z);
586 
587  if (d == 0.0f)
588  return false;
589 
590  p.y = a.y + d1/d*(b.y-a.y) + d2/d*(c.y-a.y);
591 
592  return true;
593 }
594 
596 inline Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float angleV, float length)
597 {
598  Math::Vector lookat = eye;
599  lookat.z += length;
600 
601  RotatePoint(eye, angleH, angleV, lookat);
602 
603  return lookat;
604 }
605 
607 
609 {
610  return MatrixVectorMultiply(m, p);
611 }
612 
614 
618 inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p)
619 {
620  float k = DotProduct(b - a, p - a);
621  k /= DotProduct(b - a, b - a);
622 
623  return a + k*(b-a);
624 }
625 
627 inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV, float dist)
628 {
629  Math::Matrix mat1, mat2;
630  LoadRotationZMatrix(mat1, -angleV);
631  LoadRotationYMatrix(mat2, -angleH);
632 
633  Math::Matrix mat = MultiplyMatrices(mat2, mat1);
634 
635  Math::Vector eye;
636  eye.x = 0.0f+dist;
637  eye.y = 0.0f;
638  eye.z = 0.0f;
639  eye = Transform(mat, eye);
640 
641  return eye+center;
642 }
643 
644 
645 } // namespace Math
646 
void LoadRotationXMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the X axis.
Definition: geometry.h:402
void LoadIdentity()
Loads the identity matrix.
Definition: matrix.h:128
float DistanceToPlane(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, const Math::Vector &p)
Returns the distance between given point and a plane.
Definition: geometry.h:526
void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
Loads a scaling matrix fom given vector.
Definition: geometry.h:389
void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top, float zNear=-1.0f, float zFar=1.0f)
Loads an othogonal projection matrix.
Definition: geometry.h:357
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:44
void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles)
Calculates the matrix to make three rotations in the order Z, X and Y.
Definition: geometry.h:480
void LoadZero()
Loads the zero matrix.
Definition: matrix.h:121
float x
X coord.
Definition: point.h:49
Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p)
Transforms the point p by matrix m.
Definition: geometry.h:608
float MidPoint(const Math::Point &a, const Math::Point &b, float px)
Returns py up on the line a - b.
Definition: geometry.h:42
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:186
Point struct and related functions.
4x4 matrix
Definition: matrix.h:63
Vector Normalize(const Math::Vector &v)
Convenience function for getting normalized vector.
Definition: vector.h:239
bool IsInsideTriangle(Math::Point a, Math::Point b, Math::Point c, Math::Point p)
Tests whether the point p is inside the triangle (a,b,c)
Definition: geometry.h:55
float x
X - 1st coord.
Definition: vector.h:52
Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3)
Returns the normal vector to a plane.
Definition: geometry.h:503
Math::Matrix MultiplyMatrices(const Math::Matrix &left, const Math::Matrix &right)
Convenience function for multiplying a matrix.
Definition: matrix.h:424
void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
Loads a rotation matrix along the given axis.
Definition: geometry.h:445
float y
Y coord.
Definition: point.h:51
float DotProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating dot product.
Definition: vector.h:247
const float PI
PI.
Definition: const.h:44
bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, Math::Vector &p)
Calculates the intersection of the straight line passing through p (x, z)
Definition: geometry.h:581
void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from, const Math::Vector &at, const Math::Vector &worldUp)
Loads view matrix from the given vectors.
Definition: geometry.h:264
bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, const Math::Vector &d, const Math::Vector &e, Math::Vector &i)
Calculates the intersection "i" right "of" the plane "abc" (TODO: ?)
Definition: geometry.h:558
const float HUGE_NUM
Huge number.
Definition: const.h:41
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:38
float RotateAngle(float x, float y)
Returns the angle between point (x,y) and (0,0)
Definition: geometry.h:198
Math::Vector MatrixVectorMultiply(const Math::Matrix &m, const Math::Vector &v, bool wDivide=false)
Calculates the result of multiplying m * v.
Definition: matrix.h:442
void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles)
Calculates the matrix to make three rotations in the order X, Z and Y.
Definition: geometry.h:467
void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
Loads a translation matrix from given vector.
Definition: geometry.h:376
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:102
Matrix struct and related functions.
2D point
Definition: point.h:46
void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
Rotates a point around a center in space.
Definition: geometry.h:178
Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
Rotates a point around a center.
Definition: geometry.h:86
float z
Z - 3rd coord.
Definition: vector.h:56
Math::Vector RotateView(Math::Vector center, float angleH, float angleV, float dist)
Calculates point of view to look at a center two angles and a distance.
Definition: geometry.h:627
float Length() const
Returns the vector length.
Definition: vector.h:91
void LoadRotationZMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the Z axis.
Definition: geometry.h:430
void LoadRotationYMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the Y axis.
Definition: geometry.h:416
Constants used in math functions.
Vector struct and related functions.
Common math functions.
bool PointsEqual(const Point &a, const Point &b, float tolerance=TOLERANCE)
Checks if two vectors are equal within given tolerance.
Definition: point.h:170
Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
Returns a point on the line p1 - p2, in dist distance from p1.
Definition: geometry.h:516
Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float angleV, float length)
Calculates the end point.
Definition: geometry.h:596
Vector CrossProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating cross product.
Definition: vector.h:253
3D (3x1) vector
Definition: vector.h:49
Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p)
Calculates the projection of the point p on a straight line a to b.
Definition: geometry.h:618
bool IsSamePlane(const Math::Vector(&plane1)[3], const Math::Vector(&plane2)[3])
Checks if two planes defined by three points are the same.
Definition: geometry.h:540
float y
Y - 2nd coord.
Definition: vector.h:54
float m[16]
Matrix values in column-major order.
Definition: matrix.h:66
float DistanceProjected(const Math::Vector &a, const Math::Vector &b)
Returns the distance between projections on XZ plane of two vectors.
Definition: geometry.h:493
void LoadProjectionMatrix(Math::Matrix &mat, float fov=Math::PI/2.0f, float aspect=1.0f, float nearPlane=1.0f, float farPlane=1000.0f)
Loads a perspective projection matrix.
Definition: geometry.h:333