Welcome to mirror list, hosted at ThFree Co, Russian Federation.

collisiondetection.h « Internal « Source - github.com/WolfireGames/overgrowth.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6275dff2e61dec0ccabba96e09b3f047e1d59a55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//-----------------------------------------------------------------------------
//           Name: collisiondetection.h
//      Developer: Wolfire Games LLC
//         Author: David Rosen
//    Description: This file stores collision detection functions 
//                 (mostly scavenged from the internet)
//        License: Read below
//-----------------------------------------------------------------------------
//
//   Copyright 2022 Wolfire Games LLC
//
//   Licensed under the Apache License, Version 2.0 (the "License");
//   you may not use this file except in compliance with the License.
//   You may obtain a copy of the License at
//
//       http://www.apache.org/licenses/LICENSE-2.0
//
//   Unless required by applicable law or agreed to in writing, software
//   distributed under the License is distributed on an "AS IS" BASIS,
//   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//   See the License for the specific language governing permissions and
//   limitations under the License.
//
//-----------------------------------------------------------------------------
#pragma once

#include <Math/vec3.h>

class Object;
class Collision {
public:
    Collision();
    
    bool hit;
    Object* hit_what;
    int hit_how;
    vec3 hit_normal;
    vec3 hit_where;
};

//-----------------------------------------------------------------------------
// Class Definition
//-----------------------------------------------------------------------------

int LineFacet(const vec3 &p1,const vec3 &p2,const vec3 &pa,const vec3 &pb,const vec3 &pc, vec3 *p);
int LineFacetNoBackface(const vec3 &p1,const vec3 &p2,const vec3 &pa,const vec3 &pb,const vec3 &pc, vec3 *p, const vec3 &n);
int LineFacet(const vec3 &p1,const vec3 &p2,const vec3 &pa,const vec3 &pb,const vec3 &pc, vec3 *p, const vec3 &n);
int LineFacet(vec3 *p1,vec3 *p2,vec3 *pa,vec3 *pb,vec3 *pc,vec3 *p);
int LineFacet(vec3 *p1,vec3 *p2,vec3 *pa,vec3 *pb,vec3 *pc,vec3 *p,vec3 *n);

bool inTriangle(const vec3 &pointv, const vec3 &normal, const vec3 &p1v, const vec3 &p2v, const vec3 &p3v);
vec3 barycentric(const vec3 &pointv, const vec3 &normal, const vec3 &p1v, const vec3 &p2v, const vec3 &p3v);

bool sphere_line_intersection (const vec3& p1, const vec3& p2, const vec3& p3, const float &r , vec3 *ret=0);

bool lineBox(const vec3 &start, const vec3 &end,const vec3 &box_min,const vec3 &box_max, float *time);

bool triBoxOverlap(const vec3 &min, const vec3 &max, const vec3 &vert1, const vec3 &vert2, const vec3 &vert3);


int coplanar_tri_tri_OG(float N[3],float V0[3],float V1[3],float V2[3],
                        float U0[3],float U1[3],float U2[3]);

int tri_tri_intersect(float V0[3],float V1[3],float V2[3],
                      float U0[3],float U1[3],float U2[3]);

int NoDivTriTriIsect(float V0[3],float V1[3],float V2[3],
                     float U0[3],float U1[3],float U2[3]);

int tri_tri_intersect_with_isectline(float V0[3],float V1[3],float V2[3],
                     float U0[3],float U1[3],float U2[3],int *coplanar,
                     float *isectpt1,float *isectpt2);

bool PointInTriangle(vec3 &point, vec3 *tri_point[3]);

bool LineIntersection2D(vec3 &p1, vec3 &p2, vec3 &p3, vec3 &p4);

bool LineSquareIntersection2D(vec3 &min, vec3 &max, vec3 &start, vec3 &end);

bool TriangleSquareIntersection2D(vec3 &min, vec3 &max, vec3 *tri_point[3]);

bool DistancePointLine( const vec3 &Point, const vec3 &LineStart, const vec3 &LineEnd, float *Distance, vec3 *Intersection );