#include <collisionset.h>
Collaboration diagram for CollisionSet:
Public Member Functions | |
CollisionSet () | |
empty constructor | |
bool | insert (Model *model) |
insert object into collision set | |
bool | contains (Model *model) |
check wether collision set contains given object | |
void | setTranslation (double t[3]) |
set translation matrix | |
void | setOrientation (double o[3][3]) |
set orientation matrix | |
~CollisionSet () | |
destructor | |
Static Public Member Functions | |
bool | checkForCollision (CollisionSet *setA, CollisionSet *setB) |
check for collision | |
Public Attributes | |
double | translation [3] |
translation matrix | |
double | orientation [3][3] |
orientation matrix | |
Private Attributes | |
ModelList * | root |
This class represents a data structure to store Model instances that are involved in the collision detection process.
|
empty constructor
00012 { 00013 root = new ModelList; 00014 root->next = NULL; 00015 root->model = NULL; 00016 00017 // set orientation to identity matrix 00018 orientation[0][0] = 1.0; orientation[0][1] = 0.0; orientation[0][2] = 0.0; 00019 orientation[1][0] = 0.0; orientation[1][1] = 1.0; orientation[1][2] = 0.0; 00020 orientation[2][0] = 0.0; orientation[2][1] = 0.0; orientation[2][2] = 1.0; 00021 00022 // set translation to zero vector 00023 translation[0] = 0.0; 00024 translation[1] = 0.0; 00025 translation[2] = 0.0; 00026 } |
|
destructor
00088 { } |
|
check for collision check every model from each set against every model from the other set if there is a collision return true, otherwise false.
00093 { 00094 bool collision = false; 00095 ModelList* modelA, *modelB; 00096 for (modelA = setA->root->next; modelA != NULL; modelA = modelA->next) { 00097 for (modelB = setB->root->next; modelB != NULL; modelB = modelB->next) { 00098 Model* A = modelA->model; 00099 Model* B = modelB->model; 00100 00101 RAPID_Collide(setA->orientation, setA->translation, 00102 A->rapidModel, setB->orientation, setB->translation, B->rapidModel, 00103 RAPID_FIRST_CONTACT); 00104 collision = (RAPID_num_contacts != 0); 00105 if (collision) { 00106 return true; 00107 } 00108 } 00109 } 00110 00111 return collision; 00112 } |
|
check wether collision set contains given object check whether given model is present in set
|
|
insert object into collision set insert Model into collision set if it does not already exist
00032 { 00033 if (contains(model)) { 00034 // model is already in set 00035 return false; 00036 } 00037 00038 // find end of list 00039 ModelList* ptr = root; 00040 while (ptr->next != NULL) { 00041 ptr = ptr->next; 00042 } 00043 // ptr.next == NULL now 00044 ptr->next = new ModelList; 00045 ptr->next->next = NULL; 00046 ptr->next->model = model; 00047 00048 return true; 00049 } |
|
set orientation matrix
00078 { 00079 for (int i=0; i<3; i++) { 00080 for (int j=0; j<3; j++) { 00081 orientation[i][j] = o[i][j]; 00082 } 00083 } 00084 } |
|
set translation matrix
00069 { 00070 for (int i=0; i<3; i++) { 00071 translation[i] = t[i]; 00072 } 00073 } |
|
orientation matrix
|
|
|
|
translation matrix
|