source: trunk/src/lol/math/geometry.h @ 2459

Last change on this file since 2459 was 2459, checked in by sam, 7 years ago

math: add Box2D and Box3D classes.

File size: 2.0 KB
Line 
1//
2// Lol Engine
3//
4// Copyright: (c) 2010-2013 Sam Hocevar <sam@hocevar.net>
5//            (c) 2010-2013 Benjamin "Touky" Huet <huet.benjamin@gmail.com>
6//   This program is free software; you can redistribute it and/or
7//   modify it under the terms of the Do What The Fuck You Want To
8//   Public License, Version 2, as published by Sam Hocevar. See
9//   http://www.wtfpl.net/ for more details.
10//
11
12//
13// Various geometry functions
14// --------------------------
15//
16
17#if !defined __LOL_MATH_GEOMETRY_H__
18#define __LOL_MATH_GEOMETRY_H__
19
20#include <cmath>
21#include <cstdio>
22#include <algorithm>
23
24#include <stdint.h>
25
26#define CSG_EPSILON     0.0001
27
28namespace lol
29{
30
31struct Box2D
32{
33    inline Box2D(vec2 a, vec2 b)
34      : A(a),
35        B(b)
36    {}
37
38    vec2 A, B;
39};
40
41struct Box3D
42{
43    inline Box3D(vec3 a, vec3 b)
44      : A(a),
45        B(b)
46    {}
47
48    vec3 A, B;
49};
50
51bool TriangleIsectTriangle(vec3 const &v00, vec3 const &v01, vec3 const &v02,
52                           vec3 const &v10, vec3 const &v11, vec3 const &v12,
53                           vec3 &iP00, vec3 &iP10);
54bool RayIsectTriangleSide(vec3 const &v0, vec3 const &v1, vec3 const &v2,
55                          vec3 const &iP0, vec3 const &iP1,
56                          vec3 &iV0, int &iIdx0, vec3 &iV1, int &iIdx1);
57bool RayIsectTriangle(vec3 const &rayP, vec3 const &rayD,
58                      vec3 const &triV0, vec3 const &triV1, vec3 const &triV2,
59                      vec3 &vi);
60#define RAY_ISECT_NOTHING   0
61#define RAY_ISECT_ALL       1
62#define RAY_ISECT_NONE      2
63#define RAY_ISECT_P0        3
64#define RAY_ISECT_P1        4
65int RayIsectRay(vec3 const &rayP00, vec3 const &rayP01,
66                vec3 const &rayP10, vec3 const &rayP11,
67                vec3 &vIsec);
68vec3 ProjPointOnPlane(vec3 const &point, vec3 const &planeP, vec3 const &planeN);
69bool RayIsectPlane(vec3 const &rayP0, vec3 const &rayP1,
70                   vec3 const &planeP, vec3 const &planeN,
71                   vec3 &vIsec, bool test_line_only = false);
72
73} /* namespace lol */
74
75#endif // __LOL_MATH_GEOMETRY_H__
76
Note: See TracBrowser for help on using the repository browser.