1 /******************************************************************************* 2 * Copyright 2011 See AUTHORS file. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 ******************************************************************************/ 16 #ifdef _MSC_VER 17 #pragma once 18 #endif 19 20 #ifndef ContactListener_H 21 #define ContactListener_H 22 23 #include "GdxCollisionObjectBridge.h" 24 #include "../../../bullet/BulletCollision/CollisionDispatch/btCollisionObject.h" 25 #include "../../../bullet/BulletCollision/CollisionDispatch/btCollisionObjectWrapper.h" 26 #include "../../../bullet/BulletCollision/CollisionDispatch/btManifoldResult.h" 27 #include "../../../bullet/BulletCollision/NarrowPhaseCollision/btPersistentManifold.h" 28 29 enum ContactCallbackEvent { 30 TYPE_MASK = 0x0F, 31 BY_MASK = 12, 32 FILTERED = 1, 33 INCLUDE_POINT = 2, 34 BY_WRAPPER = 4, 35 BY_MANIFOLD = 4, 36 BY_OBJECT = 8, 37 BY_VALUE = 12, 38 39 SHIFT_ON_ADDED = 0, 40 SHIFT_ON_PROCESSED = 4, 41 SHIFT_ON_DESTROYED = 8, 42 SHIFT_ON_STARTED = 12, 43 SHIFT_ON_ENDED = 16, 44 45 ON_ADDED_UNFILTERED_WRAPPER = (BY_WRAPPER) << SHIFT_ON_ADDED, 46 ON_ADDED_UNFILTERED_OBJECT = (BY_OBJECT) << SHIFT_ON_ADDED, 47 ON_ADDED_UNFILTERED_VALUE = (BY_VALUE) << SHIFT_ON_ADDED, 48 ON_ADDED_UNFILTERED_WRAPPER_INCLUDEPOINT = (BY_WRAPPER | INCLUDE_POINT) << SHIFT_ON_ADDED, 49 ON_ADDED_UNFILTERED_OBJECT_INCLUDEPOINT = (BY_OBJECT | INCLUDE_POINT) << SHIFT_ON_ADDED, 50 ON_ADDED_UNFILTERED_VALUE_INCLUDEPOINT = (BY_VALUE | INCLUDE_POINT) << SHIFT_ON_ADDED, 51 ON_ADDED_FILTERED_WRAPPER = (FILTERED | BY_WRAPPER) << SHIFT_ON_ADDED, 52 ON_ADDED_FILTERED_OBJECT = (FILTERED | BY_OBJECT) << SHIFT_ON_ADDED, 53 ON_ADDED_FILTERED_VALUE = (FILTERED | BY_VALUE) << SHIFT_ON_ADDED, 54 ON_ADDED_FILTERED_WRAPPER_INCLUDEPOINT = (FILTERED | BY_WRAPPER | INCLUDE_POINT) << SHIFT_ON_ADDED, 55 ON_ADDED_FILTERED_OBJECT_INCLUDEPOINT = (FILTERED | BY_OBJECT | INCLUDE_POINT) << SHIFT_ON_ADDED, 56 ON_ADDED_FILTERED_VALUE_INCLUDEPOINT = (FILTERED | BY_VALUE | INCLUDE_POINT) << SHIFT_ON_ADDED, 57 58 ON_PROCESSED_UNFILTERED_OBJECT = (BY_OBJECT) << SHIFT_ON_PROCESSED, 59 ON_PROCESSED_UNFILTERED_VALUE = (BY_VALUE) << SHIFT_ON_PROCESSED, 60 ON_PROCESSED_UNFILTERED_OBJECT_INCLUDEPOINT = (BY_OBJECT | INCLUDE_POINT) << SHIFT_ON_PROCESSED, 61 ON_PROCESSED_UNFILTERED_VALUE_INCLUDEPOINT = (BY_VALUE | INCLUDE_POINT) << SHIFT_ON_PROCESSED, 62 ON_PROCESSED_FILTERED_OBJECT = (FILTERED | BY_OBJECT) << SHIFT_ON_PROCESSED, 63 ON_PROCESSED_FILTERED_VALUE = (FILTERED | BY_VALUE) << SHIFT_ON_PROCESSED, 64 ON_PROCESSED_FILTERED_OBJECT_INCLUDEPOINT = (FILTERED | BY_OBJECT | INCLUDE_POINT) << SHIFT_ON_PROCESSED, 65 ON_PROCESSED_FILTERED_VALUE_INCLUDEPOINT = (FILTERED | BY_VALUE | INCLUDE_POINT) << SHIFT_ON_PROCESSED, 66 67 ON_DESTROYED = BY_VALUE << SHIFT_ON_DESTROYED, 68 69 ON_STARTED_UNFILTERED_MANIFOLD = (BY_MANIFOLD) << SHIFT_ON_STARTED, 70 ON_STARTED_UNFILTERED_OBJECT = (BY_OBJECT) << SHIFT_ON_STARTED, 71 ON_STARTED_UNFILTERED_VALUE = (BY_VALUE) << SHIFT_ON_STARTED, 72 ON_STARTED_FILTERED_MANIFOLD = (FILTERED | BY_MANIFOLD) << SHIFT_ON_STARTED, 73 ON_STARTED_FILTERED_OBJECT = (FILTERED | BY_OBJECT) << SHIFT_ON_STARTED, 74 ON_STARTED_FILTERED_VALUE = (FILTERED | BY_VALUE) << SHIFT_ON_STARTED, 75 76 ON_ENDED_UNFILTERED_MANIFOLD = (BY_MANIFOLD) << SHIFT_ON_ENDED, 77 ON_ENDED_UNFILTERED_OBJECT = (BY_OBJECT) << SHIFT_ON_ENDED, 78 ON_ENDED_UNFILTERED_VALUE = (BY_VALUE) << SHIFT_ON_ENDED, 79 ON_ENDED_FILTERED_MANIFOLD = (FILTERED | BY_MANIFOLD) << SHIFT_ON_ENDED, 80 ON_ENDED_FILTERED_OBJECT = (FILTERED | BY_OBJECT) << SHIFT_ON_ENDED, 81 ON_ENDED_FILTERED_VALUE = (FILTERED | BY_VALUE) << SHIFT_ON_ENDED, 82 }; 83 84 /** @author Xoppa */ 85 class ContactListener { 86 protected: 87 #ifndef SWIG 88 int events; 89 #endif 90 public: 91 ContactListener(bool dummy); 92 virtual ~ContactListener(); 93 94 #ifndef SWIG 95 void setEvents(const int &events); 96 #endif //SWIG 97 98 void enable(); 99 void disable(); 100 101 void enableOnAdded(); 102 void disableOnAdded(); 103 bool isOnAddedEnabled(); 104 105 virtual bool onContactAdded(btManifoldPoint& cp,const btCollisionObjectWrapper &colObj0Wrap,int partId0,int index0, 106 const btCollisionObjectWrapper &colObj1Wrap,int partId1,int index1) = 0; 107 virtual bool onContactAdded(btManifoldPoint& cp,const btCollisionObject* colObj0,int partId0,int index0, 108 const btCollisionObject* colObj1,int partId1,int index1) = 0; 109 virtual bool onContactAdded(btManifoldPoint& cp,int userValue0,int partId0,int index0, 110 int userValue1,int partId1,int index1) = 0; 111 112 virtual bool onContactAdded(btManifoldPoint& cp,const btCollisionObjectWrapper &colObj0Wrap,int partId0,int index0,bool match0, 113 const btCollisionObjectWrapper &colObj1Wrap,int partId1,int index1,bool match1) = 0; 114 virtual bool onContactAdded(btManifoldPoint& cp,const btCollisionObject* colObj0,int partId0,int index0,bool match0, 115 const btCollisionObject* colObj1,int partId1,int index1,bool match1) = 0; 116 virtual bool onContactAdded(btManifoldPoint& cp,int userValue0,int partId0,int index0,bool match0, 117 int userValue1,int partId1,int index1,bool match1) = 0; 118 119 virtual bool onContactAdded(const btCollisionObjectWrapper &colObj0Wrap,int partId0,int index0, 120 const btCollisionObjectWrapper &colObj1Wrap,int partId1,int index1) = 0; 121 virtual bool onContactAdded(const btCollisionObject* colObj0,int partId0,int index0, 122 const btCollisionObject* colObj1,int partId1,int index1) = 0; 123 virtual bool onContactAdded(int userValue0,int partId0,int index0, 124 int userValue1,int partId1,int index1) = 0; 125 126 virtual bool onContactAdded(const btCollisionObjectWrapper &colObj0Wrap,int partId0,int index0,bool match0, 127 const btCollisionObjectWrapper &colObj1Wrap,int partId1,int index1,bool match1) = 0; 128 virtual bool onContactAdded(const btCollisionObject* colObj0,int partId0,int index0,bool match0, 129 const btCollisionObject* colObj1,int partId1,int index1,bool match1) = 0; 130 virtual bool onContactAdded(int userValue0,int partId0,int index0,bool match0, 131 int userValue1,int partId1,int index1,bool match1) = 0; 132 133 void enableOnProcessed(); 134 void disableOnProcessed(); 135 bool isOnProcessedEnabled(); 136 137 virtual void onContactProcessed(btManifoldPoint& cp, const btCollisionObject* colObj0, const btCollisionObject* colObj1) = 0; 138 virtual void onContactProcessed(btManifoldPoint& cp, int userValue0, int userValue1) = 0; 139 140 virtual void onContactProcessed(btManifoldPoint& cp, const btCollisionObject* colObj0, bool match0, const btCollisionObject* colObj1, bool match1) = 0; 141 virtual void onContactProcessed(btManifoldPoint& cp, int userValue0, bool match0, int userValue1, bool match1) = 0; 142 143 virtual void onContactProcessed(const btCollisionObject* colObj0, const btCollisionObject* colObj1) = 0; 144 virtual void onContactProcessed(int userValue0, int userValue1) = 0; 145 146 virtual void onContactProcessed(const btCollisionObject* colObj0, bool match0, const btCollisionObject* colObj1, bool match1) = 0; 147 virtual void onContactProcessed(int userValue0, bool match0, int userValue1, bool match1) = 0; 148 149 void enableOnDestroyed(); 150 void disableOnDestroyed(); 151 bool isOnDestroyedEnabled(); 152 153 virtual void onContactDestroyed(int manifoldPointUserValue) = 0; 154 155 void enableOnStarted(); 156 void disableOnStarted(); 157 bool isOnStartedEnabled(); 158 159 virtual void onContactStarted(btPersistentManifold* manifold) = 0; 160 virtual void onContactStarted(const btCollisionObject* colObj0, const btCollisionObject* colObj1) = 0; 161 virtual void onContactStarted(const int &userValue0, const int &userValue1) = 0; 162 163 virtual void onContactStarted(btPersistentManifold* manifold, const bool &match0, const bool &match1) = 0; 164 virtual void onContactStarted(const btCollisionObject* colObj0, const bool &match0, const btCollisionObject* colObj1, const bool &match1) = 0; 165 virtual void onContactStarted(const int &userValue0, const bool &match0, const int &userValue1, const bool &match1) = 0; 166 167 void enableOnEnded(); 168 void disableOnEnded(); 169 bool isOnEndedEnabled(); 170 171 virtual void onContactEnded(btPersistentManifold* manifold) = 0; 172 virtual void onContactEnded(const btCollisionObject* colObj0, const btCollisionObject* colObj1) = 0; 173 virtual void onContactEnded(const int &userValue0, const int &userValue1) = 0; 174 175 virtual void onContactEnded(btPersistentManifold* manifold, const bool &match0, const bool &match1) = 0; 176 virtual void onContactEnded(const btCollisionObject* colObj0, const bool &match0, const btCollisionObject* colObj1, const bool &match1) = 0; 177 virtual void onContactEnded(const int &userValue0, const bool &match0, const int &userValue1, const bool &match1) = 0; 178 }; 179 180 #endif //ContactListener_H