Physics4K  2013-06-04
Physics4K is the next great evolution in 2D physics engines. built upon the C++ Game Framework, it is going to take the next generation gaming world by storm.
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros
Collision.h
Go to the documentation of this file.
1 // Filename: Collision.h
4 
5 //Preprocessor directive designed to cause the current source file to be included only once in a single compilation
6 #pragma once
7 
8 //Includes
9 #include "PKInclude.h"
10 #include "Matrix22.h"
11 #include "Vector2f.h"
12 #include "MathXtras.h"
13 #include "Box.h"
14 #include "Contact.h"
15 #include "Circle.h"
16 #include "Shape.h"
17 
18 namespace PK
19 {
20  PK_API int OBBOBBCollision(Box* box1, Box* box2, Contact* contacts);
21  PK_API int CircleCircleCollision(Circle* circle1, Circle* circle2, Contact* contacts);
22  PK_API int BoxCircleCollision(Box* box, Circle* circle, Contact* contacts, bool isCircleFirst);
23 
31  static int CalculateCollision(Shape* shape1, Shape* shape2, Contact* contacts)
32  {
33  //Get the two shape types
34  ShapeType shape1Type = shape1->GetType();
35  ShapeType shape2Type = shape2->GetType();
36 
37  //OBB to OBB code
38  if (shape1Type == BoxType && shape2Type == BoxType)
39  return OBBOBBCollision((Box*)shape1, (Box*)shape2, contacts);
40 
41  //Box to Circle code
42  else if (shape1Type == BoxType && shape2Type == CircleType)
43  return BoxCircleCollision((Box*)shape1, (Circle*)shape2, contacts, false);
44 
45  //Circle to Box code
46  else if (shape1Type == CircleType && shape2Type == BoxType)
47  return BoxCircleCollision((Box*)shape2, (Circle*)shape1, contacts, true);
48 
49  //Circle to Circle code
50  else if (shape1Type == CircleType && shape2Type == CircleType)
51  return CircleCircleCollision((Circle*)shape1, (Circle*)shape2, contacts);
52 
53  //No supported collision, return such
54  return 0;
55  }
56 }