-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollision_world.h
More file actions
93 lines (76 loc) · 3.6 KB
/
collision_world.h
File metadata and controls
93 lines (76 loc) · 3.6 KB
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
83
84
85
86
87
88
89
90
91
92
93
/**
* collision_world.h -- detect and handle line segment intersections
* Copyright (c) 2012 the Massachusetts Institute of Technology
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
**/
#ifndef COLLISIONWORLD_H_
#define COLLISIONWORLD_H_
#include "./line.h"
#include "./intersection_detection.h"
#include "./quad_tree/quad_tree.h"
struct CollisionWorld {
// Time step used for simulation
double timeStep;
// Container that holds all the lines as an array of Line* lines.
// This CollisionWorld owns the Line* lines.
Line** lines;
QuadTree* quad_tree;
bool using_quad_tree;
unsigned int numOfLines;
// Record the total number of line-wall collisions.
unsigned int numLineWallCollisions;
// Record the total number of line-line intersections.
unsigned int numLineLineCollisions;
};
typedef struct CollisionWorld CollisionWorld;
// init and free
CollisionWorld* CollisionWorld_new(const unsigned int capacity, bool quad_tree_flag);
void CollisionWorld_delete(CollisionWorld* collisionWorld);
// Add a line into the box. Must be under capacity.
// This CollisionWorld becomes owner of the Line* line.
void CollisionWorld_addLine(CollisionWorld* collisionWorld, Line *line);
// Get a line from box.
Line* CollisionWorld_getLine(CollisionWorld* collisionWorld,
const unsigned int index);
// Return the total number of lines in the box.
unsigned int CollisionWorld_getNumOfLines(CollisionWorld* collisionWorld);
// Get total number of line-wall collisions.
unsigned int CollisionWorld_getNumLineWallCollisions(
CollisionWorld* collisionWorld);
// Get total number of line-line intersections.
unsigned int CollisionWorld_getNumLineLineCollisions(
CollisionWorld* collisionWorld);
// Update lines' situation in the box.
void CollisionWorld_updateLines(CollisionWorld* collisionWorld);
// Update position of lines.
void CollisionWorld_updatePosition(CollisionWorld* collisionWorld);
// Handle line-wall collision.
void CollisionWorld_lineWallCollision(CollisionWorld* collisionWorld);
// Detect line-line intersection.
void CollisionWorld_detectIntersection(CollisionWorld* collisionWorld);
// Update the two lines based on their intersection event.
// Precondition: compareLines(l1, l2) < 0 must be true.
void CollisionWorld_collisionSolver(CollisionWorld* collisionWorld, Line *l1,
Line *l2,
IntersectionType intersectionType);
// quad_tree stuff
void CollisionWorld_FillQuadTree(CollisionWorld* collisionWorld);
void CollisionWorld_ClearQuadTree(CollisionWorld* collisionWorld);
#endif // COLLISIONWORLD_H_