Colobot
geometry.h
Go to the documentation of this file.
1 /*
2  * This file is part of the Colobot: Gold Edition source code
3  * Copyright (C) 2001-2016, Daniel Roux, EPSITEC SA & TerranovaTeam
4  * http://epsitec.ch; http://colobot.info; http://github.com/colobot
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14  * See the GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see http://gnu.org/licenses
18  */
19 
25 #pragma once
26 
27 
28 #include "math/const.h"
29 #include "math/func.h"
30 #include "math/matrix.h"
31 #include "math/point.h"
32 #include "math/vector.h"
33 
34 
35 #include <cmath>
36 #include <cstdlib>
37 
38 
39 // Math module namespace
40 namespace Math
41 {
42 
43 
45 inline float MidPoint(const Math::Point &a, const Math::Point &b, float px)
46 {
47  if (IsEqual(a.x, b.x))
48  {
49  if (a.y < b.y)
50  return Math::HUGE_NUM;
51  else
52  return -Math::HUGE_NUM;
53  }
54  return (b.y-a.y) * (px-a.x) / (b.x-a.x) + a.y;
55 }
56 
59 {
60  float n, m;
61 
62  if ( p.x < a.x && p.x < b.x && p.x < c.x ) return false;
63  if ( p.x > a.x && p.x > b.x && p.x > c.x ) return false;
64  if ( p.y < a.y && p.y < b.y && p.y < c.y ) return false;
65  if ( p.y > a.y && p.y > b.y && p.y > c.y ) return false;
66 
67  if ( a.x > b.x ) Swap(a,b);
68  if ( a.x > c.x ) Swap(a,c);
69  if ( c.x < a.x ) Swap(c,a);
70  if ( c.x < b.x ) Swap(c,b);
71 
72  n = MidPoint(a, b, p.x);
73  m = MidPoint(a, c, p.x);
74  if ( (n>p.y||p.y>m) && (n<p.y||p.y<m) ) return false;
75 
76  n = MidPoint(c, b, p.x);
77  m = MidPoint(c, a, p.x);
78  if ( (n>p.y||p.y>m) && (n<p.y||p.y<m) ) return false;
79 
80  return true;
81 }
82 
84 
89 inline Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
90 {
91  Math::Point a;
92  a.x = p.x-center.x;
93  a.y = p.y-center.y;
94 
95  Math::Point b;
96  b.x = a.x*cosf(angle) - a.y*sinf(angle);
97  b.y = a.x*sinf(angle) + a.y*cosf(angle);
98 
99  b.x += center.x;
100  b.y += center.y;
101 
102  return b;
103 }
104 
106 
110 inline Math::Point RotatePoint(float angle, const Math::Point &p)
111 {
112  float x = p.x*cosf(angle) - p.y*sinf(angle);
113  float y = p.x*sinf(angle) + p.y*cosf(angle);
114 
115  return Math::Point(x, y);
116 }
117 
119 
123 inline Math::Point RotatePoint(float angle, float dist)
124 {
125  float x = dist*cosf(angle);
126  float y = dist*sinf(angle);
127 
128  return Math::Point(x, y);
129 }
130 
132 
137 inline void RotatePoint(float cx, float cy, float angle, float &px, float &py)
138 {
139  float ax, ay;
140 
141  px -= cx;
142  py -= cy;
143 
144  ax = px*cosf(angle) - py*sinf(angle);
145  ay = px*sinf(angle) + py*cosf(angle);
146 
147  px = cx+ax;
148  py = cy+ay;
149 }
150 
152 
159 inline void RotatePoint(const Math::Vector &center, float angleH, float angleV, Math::Vector &p)
160 {
161  p.x -= center.x;
162  p.y -= center.y;
163  p.z -= center.z;
164 
165  Math::Vector b;
166  b.x = p.x*cosf(angleH) - p.z*sinf(angleH);
167  b.y = p.z*sinf(angleV) + p.y*cosf(angleV);
168  b.z = p.x*sinf(angleH) + p.z*cosf(angleH);
169 
170  p = center + b;
171 }
172 
174 
181 inline void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
182 {
183  p.x -= center.x;
184  p.y -= center.y;
185  p.z -= center.z;
186 
187  Math::Vector a;
188  a.x = p.x*cosf(angleH) - p.z*sinf(angleH);
189  a.y = p.y;
190  a.z = p.x*sinf(angleH) + p.z*cosf(angleH);
191 
192  Math::Vector b;
193  b.x = a.x;
194  b.y = a.z*sinf(angleV) + a.y*cosf(angleV);
195  b.z = a.z*cosf(angleV) - a.y*sinf(angleV);
196 
197  p = center + b;
198 }
199 
201 inline float RotateAngle(float x, float y)
202 {
203  if (x == 0.0f && y == 0.0f) return 0.0f;
204 
205  if (x >= 0.0f)
206  {
207  if (y >= 0.0f)
208  {
209  if (x > y) return atanf(y/x);
210  else return PI*0.5f - atanf(x/y);
211  }
212  else
213  {
214  if (x > -y) return PI*2.0f + atanf(y/x);
215  else return PI*1.5f - atanf(x/y);
216  }
217  }
218  else
219  {
220  if (y >= 0.0f)
221  {
222  if (-x > y) return PI*1.0f + atanf(y/x);
223  else return PI*0.5f - atanf(x/y);
224  }
225  else
226  {
227  if (-x > -y) return PI*1.0f + atanf(y/x);
228  else return PI*1.5f - atanf(x/y);
229  }
230  }
231 }
232 
234 
239 inline float RotateAngle(const Math::Point &center, const Math::Point &p1, const Math::Point &p2)
240 {
241  if (PointsEqual(p1, center))
242  return 0;
243 
244  if (PointsEqual(p2, center))
245  return 0;
246 
247  float a1 = asinf((p1.y - center.y) / Distance(p1, center));
248  float a2 = asinf((p2.y - center.y) / Distance(p2, center));
249 
250  if (p1.x < center.x) a1 = PI - a1;
251  if (p2.x < center.x) a2 = PI - a2;
252 
253  float a = a2 - a1;
254  if (a < 0)
255  a += 2.0f*PI;
256 
257  return a;
258 }
259 
261 
267 inline void LoadViewMatrix(Math::Matrix &mat, const Math::Vector &from,
268  const Math::Vector &at, const Math::Vector &worldUp)
269 {
270  // Get the z basis vector, which points straight ahead. This is the
271  // difference from the eyepoint to the lookat point.
272  Math::Vector view = at - from;
273 
274  float length = view.Length();
275  assert(! IsZero(length) );
276 
277  // Normalize the z basis vector
278  view /= length;
279 
280  // Get the dot product, and calculate the projection of the z basis
281  // vector onto the up vector. The projection is the y basis vector.
282  float dotProduct = DotProduct(worldUp, view);
283 
284  Math::Vector up = worldUp - dotProduct * view;
285 
286  // If this vector has near-zero length because the input specified a
287  // bogus up vector, let's try a default up vector
288  if ( IsZero(length = up.Length()) )
289  {
290  up = Math::Vector(0.0f, 1.0f, 0.0f) - view.y * view;
291 
292  // If we still have near-zero length, resort to a different axis.
293  if ( IsZero(length = up.Length()) )
294  {
295  up = Math::Vector(0.0f, 0.0f, 1.0f) - view.z * view;
296 
297  assert(! IsZero(up.Length()) );
298  }
299  }
300 
301  // Normalize the y basis vector
302  up /= length;
303 
304  // The x basis vector is found simply with the cross product of the y
305  // and z basis vectors
306  Math::Vector right = CrossProduct(up, view);
307 
308  // Start building the matrix. The first three rows contains the basis
309  // vectors used to rotate the view to point at the lookat point
310  mat.LoadIdentity();
311 
312  /* (1,1) */ mat.m[0 ] = right.x;
313  /* (2,1) */ mat.m[1 ] = up.x;
314  /* (3,1) */ mat.m[2 ] = view.x;
315  /* (1,2) */ mat.m[4 ] = right.y;
316  /* (2,2) */ mat.m[5 ] = up.y;
317  /* (3,2) */ mat.m[6 ] = view.y;
318  /* (1,3) */ mat.m[8 ] = right.z;
319  /* (2,3) */ mat.m[9 ] = up.z;
320  /* (3,3) */ mat.m[10] = view.z;
321 
322  // Do the translation values (rotations are still about the eyepoint)
323  /* (1,4) */ mat.m[12] = -DotProduct(from, right);
324  /* (2,4) */ mat.m[13] = -DotProduct(from, up);
325  /* (3,4) */ mat.m[14] = -DotProduct(from, view);
326 }
327 
329 
336 inline void LoadProjectionMatrix(Math::Matrix &mat, float fov = Math::PI / 2.0f, float aspect = 1.0f,
337  float nearPlane = 1.0f, float farPlane = 1000.0f)
338 {
339  assert(fabs(farPlane - nearPlane) >= 0.01f);
340  assert(fabs(sin(fov / 2)) >= 0.01f);
341 
342  float f = cosf(fov / 2.0f) / sinf(fov / 2.0f);
343 
344  mat.LoadZero();
345 
346  /* (1,1) */ mat.m[0 ] = f / aspect;
347  /* (2,2) */ mat.m[5 ] = f;
348  /* (3,3) */ mat.m[10] = (nearPlane + farPlane) / (nearPlane - farPlane);
349  /* (4,3) */ mat.m[11] = -1.0f;
350  /* (3,4) */ mat.m[14] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
351 }
352 
354 
360 inline void LoadOrthoProjectionMatrix(Math::Matrix &mat, float left, float right, float bottom, float top,
361  float zNear = -1.0f, float zFar = 1.0f)
362 {
363  mat.LoadIdentity();
364 
365  /* (1,1) */ mat.m[0 ] = 2.0f / (right - left);
366  /* (2,2) */ mat.m[5 ] = 2.0f / (top - bottom);
367  /* (3,3) */ mat.m[10] = -2.0f / (zFar - zNear);
368 
369  /* (1,4) */ mat.m[12] = - (right + left) / (right - left);
370  /* (2,4) */ mat.m[13] = - (top + bottom) / (top - bottom);
371  /* (3,4) */ mat.m[14] = - (zFar + zNear) / (zFar - zNear);
372 }
373 
375 
379 inline void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
380 {
381  mat.LoadIdentity();
382  /* (1,4) */ mat.m[12] = trans.x;
383  /* (2,4) */ mat.m[13] = trans.y;
384  /* (3,4) */ mat.m[14] = trans.z;
385 }
386 
388 
392 inline void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
393 {
394  mat.LoadIdentity();
395  /* (1,1) */ mat.m[0 ] = scale.x;
396  /* (2,2) */ mat.m[5 ] = scale.y;
397  /* (3,3) */ mat.m[10] = scale.z;
398 }
399 
401 
405 inline void LoadRotationXMatrix(Math::Matrix &mat, float angle)
406 {
407  mat.LoadIdentity();
408  /* (2,2) */ mat.m[5 ] = cosf(angle);
409  /* (3,2) */ mat.m[6 ] = sinf(angle);
410  /* (2,3) */ mat.m[9 ] = -sinf(angle);
411  /* (3,3) */ mat.m[10] = cosf(angle);
412 }
413 
415 
419 inline void LoadRotationYMatrix(Math::Matrix &mat, float angle)
420 {
421  mat.LoadIdentity();
422  /* (1,1) */ mat.m[0 ] = cosf(angle);
423  /* (3,1) */ mat.m[2 ] = -sinf(angle);
424  /* (1,3) */ mat.m[8 ] = sinf(angle);
425  /* (3,3) */ mat.m[10] = cosf(angle);
426 }
427 
429 
433 inline void LoadRotationZMatrix(Math::Matrix &mat, float angle)
434 {
435  mat.LoadIdentity();
436  /* (1,1) */ mat.m[0 ] = cosf(angle);
437  /* (2,1) */ mat.m[1 ] = sinf(angle);
438  /* (1,2) */ mat.m[4 ] = -sinf(angle);
439  /* (2,2) */ mat.m[5 ] = cosf(angle);
440 }
441 
443 
448 inline void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
449 {
450  float cos = cosf(angle);
451  float sin = sinf(angle);
452  Math::Vector v = Normalize(dir);
453 
454  mat.LoadIdentity();
455 
456  /* (1,1) */ mat.m[0 ] = (v.x * v.x) * (1.0f - cos) + cos;
457  /* (2,1) */ mat.m[1 ] = (v.x * v.y) * (1.0f - cos) - (v.z * sin);
458  /* (3,1) */ mat.m[2 ] = (v.x * v.z) * (1.0f - cos) + (v.y * sin);
459 
460  /* (1,2) */ mat.m[4 ] = (v.y * v.x) * (1.0f - cos) + (v.z * sin);
461  /* (2,2) */ mat.m[5 ] = (v.y * v.y) * (1.0f - cos) + cos ;
462  /* (3,2) */ mat.m[6 ] = (v.y * v.z) * (1.0f - cos) - (v.x * sin);
463 
464  /* (1,3) */ mat.m[8 ] = (v.z * v.x) * (1.0f - cos) - (v.y * sin);
465  /* (2,3) */ mat.m[9 ] = (v.z * v.y) * (1.0f - cos) + (v.x * sin);
466  /* (3,3) */ mat.m[10] = (v.z * v.z) * (1.0f - cos) + cos;
467 }
468 
470 inline void LoadRotationXZYMatrix(Math::Matrix &mat, const Math::Vector &angles)
471 {
472  Math::Matrix temp;
473  LoadRotationXMatrix(temp, angles.x);
474 
475  LoadRotationZMatrix(mat, angles.z);
476  mat = Math::MultiplyMatrices(temp, mat);
477 
478  LoadRotationYMatrix(temp, angles.y);
479  mat = Math::MultiplyMatrices(temp, mat);
480 }
481 
483 inline void LoadRotationZXYMatrix(Math::Matrix &mat, const Math::Vector &angles)
484 {
485  Math::Matrix temp;
486  LoadRotationZMatrix(temp, angles.z);
487 
488  LoadRotationXMatrix(mat, angles.x);
489  mat = Math::MultiplyMatrices(temp, mat);
490 
491  LoadRotationYMatrix(temp, angles.y);
492  mat = Math::MultiplyMatrices(temp, mat);
493 }
494 
496 inline float DistanceProjected(const Math::Vector &a, const Math::Vector &b)
497 {
498  return sqrtf( (a.x-b.x)*(a.x-b.x) +
499  (a.z-b.z)*(a.z-b.z) );
500 }
501 
503 
506 inline Math::Vector NormalToPlane(const Math::Vector &p1, const Math::Vector &p2, const Math::Vector &p3)
507 {
508  Math::Vector u = p3 - p1;
509  Math::Vector v = p2 - p1;
510 
511  return Normalize(CrossProduct(u, v));
512 }
513 
515 
519 inline Math::Vector SegmentPoint(const Math::Vector &p1, const Math::Vector &p2, float dist)
520 {
521  Math::Vector direction = p2 - p1;
522 
523  direction.Normalize();
524 
525  return p1 + direction * dist;
526 }
527 
529 
533 inline float DistanceToPlane(const Math::Vector &a, const Math::Vector &b,
534  const Math::Vector &c, const Math::Vector &p)
535 {
536  Math::Vector n = NormalToPlane(a, b, c);
537  float d = -(n.x*a.x + n.y*a.y + n.z*a.z);
538 
539  return fabs(n.x*p.x + n.y*p.y + n.z*p.z + d);
540 }
541 
543 
547 inline bool IsSamePlane(const Math::Vector (&plane1)[3], const Math::Vector (&plane2)[3])
548 {
549  Math::Vector n1 = NormalToPlane(plane1[0], plane1[1], plane1[2]);
550  Math::Vector n2 = NormalToPlane(plane2[0], plane2[1], plane2[2]);
551 
552  if ( fabs(n1.x-n2.x) > 0.1f ||
553  fabs(n1.y-n2.y) > 0.1f ||
554  fabs(n1.z-n2.z) > 0.1f )
555  return false;
556 
557  float dist = DistanceToPlane(plane1[0], plane1[1], plane1[2], plane2[0]);
558  if ( dist > 0.1f )
559  return false;
560 
561  return true;
562 }
563 
565 inline bool Intersect(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c,
566  const Math::Vector &d, const Math::Vector &e, Math::Vector &i)
567 {
568  float d1 = (d.x-a.x)*((b.y-a.y)*(c.z-a.z)-(c.y-a.y)*(b.z-a.z)) -
569  (d.y-a.y)*((b.x-a.x)*(c.z-a.z)-(c.x-a.x)*(b.z-a.z)) +
570  (d.z-a.z)*((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
571 
572  float d2 = (d.x-e.x)*((b.y-a.y)*(c.z-a.z)-(c.y-a.y)*(b.z-a.z)) -
573  (d.y-e.y)*((b.x-a.x)*(c.z-a.z)-(c.x-a.x)*(b.z-a.z)) +
574  (d.z-e.z)*((b.x-a.x)*(c.y-a.y)-(c.x-a.x)*(b.y-a.y));
575 
576  if (d2 == 0)
577  return false;
578 
579  i.x = d.x + d1/d2*(e.x-d.x);
580  i.y = d.y + d1/d2*(e.y-d.y);
581  i.z = d.z + d1/d2*(e.z-d.z);
582 
583  return true;
584 }
585 
587 
588 inline bool IntersectY(const Math::Vector &a, const Math::Vector &b, const Math::Vector &c, Math::Vector &p)
589 {
590  float d = (b.x-a.x)*(c.z-a.z) - (c.x-a.x)*(b.z-a.z);
591  float d1 = (p.x-a.x)*(c.z-a.z) - (c.x-a.x)*(p.z-a.z);
592  float d2 = (b.x-a.x)*(p.z-a.z) - (p.x-a.x)*(b.z-a.z);
593 
594  if (d == 0.0f)
595  return false;
596 
597  p.y = a.y + d1/d*(b.y-a.y) + d2/d*(c.y-a.y);
598 
599  return true;
600 }
601 
603 inline Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float angleV, float length)
604 {
605  Math::Vector lookat = eye;
606  lookat.z += length;
607 
608  RotatePoint(eye, angleH, angleV, lookat);
609 
610  return lookat;
611 }
612 
614 
616 {
617  return MatrixVectorMultiply(m, p);
618 }
619 
621 
625 inline Math::Vector Projection(const Math::Vector &a, const Math::Vector &b, const Math::Vector &p)
626 {
627  float k = DotProduct(b - a, p - a);
628  k /= DotProduct(b - a, b - a);
629 
630  return a + k*(b-a);
631 }
632 
634 inline Math::Vector RotateView(Math::Vector center, float angleH, float angleV, float dist)
635 {
636  Math::Matrix mat1, mat2;
637  LoadRotationZMatrix(mat1, -angleV);
638  LoadRotationYMatrix(mat2, -angleH);
639 
640  Math::Matrix mat = MultiplyMatrices(mat2, mat1);
641 
642  Math::Vector eye;
643  eye.x = 0.0f+dist;
644  eye.y = 0.0f;
645  eye.z = 0.0f;
646  eye = Transform(mat, eye);
647 
648  return eye+center;
649 }
650 
651 
652 } // namespace Math
653 
void LoadRotationXMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the X axis.
Definition: geometry.h:405
void LoadIdentity()
Loads the identity matrix.
Definition: matrix.h:133
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:533
void LoadScaleMatrix(Math::Matrix &mat, const Math::Vector &scale)
Loads a scaling matrix fom given vector.
Definition: geometry.h:392
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:360
bool IsZero(float a, float tolerance=Math::TOLERANCE)
Compares a to zero within tolerance.
Definition: func.h:47
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:483
void LoadZero()
Loads the zero matrix.
Definition: matrix.h:126
float x
X coord.
Definition: point.h:53
Math::Vector Transform(const Math::Matrix &m, const Math::Vector &p)
Transforms the point p by matrix m.
Definition: geometry.h:615
float MidPoint(const Math::Point &a, const Math::Point &b, float px)
Returns py up on the line a - b.
Definition: geometry.h:45
float Distance(const Point &a, const Point &b)
Returns the distance between two points.
Definition: point.h:190
Point struct and related functions.
4x4 matrix
Definition: matrix.h:65
Vector Normalize(const Math::Vector &v)
Convenience function for getting normalized vector.
Definition: vector.h:243
void Normalize()
Normalizes the vector.
Definition: vector.h:101
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:58
float x
X - 1st coord.
Definition: vector.h:56
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:506
Math::Matrix MultiplyMatrices(const Math::Matrix &left, const Math::Matrix &right)
Convenience function for multiplying a matrix.
Definition: matrix.h:429
void LoadRotationMatrix(Math::Matrix &mat, const Math::Vector &dir, float angle)
Loads a rotation matrix along the given axis.
Definition: geometry.h:448
float y
Y coord.
Definition: point.h:55
float DotProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating dot product.
Definition: vector.h:251
const float PI
PI.
Definition: const.h:48
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:588
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:267
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:565
const float HUGE_NUM
Huge number.
Definition: const.h:45
bool IsEqual(float a, float b, float tolerance=Math::TOLERANCE)
Compares a and b within tolerance.
Definition: func.h:41
float RotateAngle(float x, float y)
Returns the angle between point (x,y) and (0,0)
Definition: geometry.h:201
Math::Vector MatrixVectorMultiply(const Math::Matrix &m, const Math::Vector &v, bool wDivide=false)
Calculates the result of multiplying m * v.
Definition: matrix.h:447
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:470
Namespace for (new) math code.
Definition: device.h:39
void LoadTranslationMatrix(Math::Matrix &mat, const Math::Vector &trans)
Loads a translation matrix from given vector.
Definition: geometry.h:379
void Swap(int &a, int &b)
Swaps two integers.
Definition: func.h:114
Matrix struct and related functions.
2D point
Definition: point.h:50
void RotatePoint2(const Math::Vector center, float angleH, float angleV, Math::Vector &p)
Rotates a point around a center in space.
Definition: geometry.h:181
Math::Point RotatePoint(const Math::Point &center, float angle, const Math::Point &p)
Rotates a point around a center.
Definition: geometry.h:89
float z
Z - 3rd coord.
Definition: vector.h:60
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:634
float Length() const
Returns the vector length.
Definition: vector.h:95
void LoadRotationZMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the Z axis.
Definition: geometry.h:433
void LoadRotationYMatrix(Math::Matrix &mat, float angle)
Loads a rotation matrix along the Y axis.
Definition: geometry.h:419
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:174
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:519
Math::Vector LookatPoint(const Math::Vector &eye, float angleH, float angleV, float length)
Calculates the end point.
Definition: geometry.h:603
Vector CrossProduct(const Math::Vector &left, const Math::Vector &right)
Convenience function for calculating cross product.
Definition: vector.h:257
3D (3x1) vector
Definition: vector.h:53
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:625
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:547
float y
Y - 2nd coord.
Definition: vector.h:58
float m[16]
Matrix values in column-major order.
Definition: matrix.h:68
float DistanceProjected(const Math::Vector &a, const Math::Vector &b)
Returns the distance between projections on XZ plane of two vectors.
Definition: geometry.h:496
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:336