Overte C++ Documentation
PhysicsCollisionGroups.h
1 //
2 // PhysicsCollisionGroups.h
3 // libraries/shared/src
4 //
5 // Created by Andrew Meadows 2015.06.03
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_PhysicsCollisionGroups_h
13 #define hifi_PhysicsCollisionGroups_h
14 
15 #include <stdint.h>
16 
17 /* Note: These are the Bullet collision groups defined in btBroadphaseProxy. Only
18  * DefaultFilter and StaticFilter are explicitly used by Bullet (when the collision
19  * filter of an object is not manually specified), the rest are merely suggestions.
20  *
21 enum CollisionFilterGroups {
22  DefaultFilter = 1,
23  StaticFilter = 2,
24  KinematicFilter = 4,
25  DebrisFilter = 8,
26  SensorTrigger = 16,
27  CharacterFilter = 32,
28  AllFilter = -1
29 }
30  *
31  * When using custom collision filters we pretty much need to do all or nothing.
32  * We'll be doing it all which means we define our own groups and build custom masks
33  * for everything.
34  *
35 */
36 
37 const int32_t BULLET_COLLISION_GROUP_STATIC = 1 << 0;
38 const int32_t BULLET_COLLISION_GROUP_DYNAMIC = 1 << 1;
39 const int32_t BULLET_COLLISION_GROUP_KINEMATIC = 1 << 2;
40 const int32_t BULLET_COLLISION_GROUP_MY_AVATAR = 1 << 3;
41 const int32_t BULLET_COLLISION_GROUP_OTHER_AVATAR = 1 << 4;
42 const int32_t BULLET_COLLISION_GROUP_DETAILED_AVATAR = 1 << 5;
43 const int32_t BULLET_COLLISION_GROUP_DETAILED_RAY = 1 << 6;
44 // ...
45 const int32_t BULLET_COLLISION_GROUP_COLLISIONLESS = 1 << 31;
46 
47 
48 /* Note: In order for objectA to collide with objectB at the filter stage
49  * both (groupA & maskB) and (groupB & maskA) must be non-zero.
50  */
51 
52 // the default collision mask is: collides with everything except collisionless
53 const int32_t BULLET_COLLISION_MASK_DEFAULT = ~ BULLET_COLLISION_GROUP_COLLISIONLESS;
54 
55 // STATIC does not collide with itself (as optimization of physics simulation)
56 const int32_t BULLET_COLLISION_MASK_STATIC = ~ (BULLET_COLLISION_GROUP_COLLISIONLESS | BULLET_COLLISION_GROUP_KINEMATIC | BULLET_COLLISION_GROUP_STATIC);
57 
58 const int32_t BULLET_COLLISION_MASK_DYNAMIC = BULLET_COLLISION_MASK_DEFAULT;
59 const int32_t BULLET_COLLISION_MASK_KINEMATIC = BULLET_COLLISION_MASK_STATIC;
60 
61 // MY_AVATAR does not collide with itself
62 const int32_t BULLET_COLLISION_MASK_MY_AVATAR = ~(BULLET_COLLISION_GROUP_COLLISIONLESS | BULLET_COLLISION_GROUP_MY_AVATAR);
63 
64 // OTHER_AVATARs are dynamic, but are slammed to whatever the avatar-mixer says, which means
65 // their motion can't actually be affected by the local physics simulation -- we rely on the remote simulation
66 // to move its avatar around correctly and to communicate its motion through the avatar-mixer.
67 // Therefore, they only need to collide against things that can be affected by their motion: dynamic and MyAvatar
68 const int32_t BULLET_COLLISION_MASK_OTHER_AVATAR = BULLET_COLLISION_GROUP_DYNAMIC | BULLET_COLLISION_GROUP_MY_AVATAR;
69 const int32_t BULLET_COLLISION_MASK_DETAILED_AVATAR = BULLET_COLLISION_GROUP_DETAILED_RAY;
70 const int32_t BULLET_COLLISION_MASK_DETAILED_RAY = BULLET_COLLISION_GROUP_DETAILED_AVATAR;
71 // COLLISIONLESS gets an empty mask.
72 const int32_t BULLET_COLLISION_MASK_COLLISIONLESS = 0;
73 
74 /*@jsdoc
75  * <p>A collision may occur with the following types of items:</p>
76  * <table>
77  * <thead>
78  * <tr><th>Value</th><th>Description</th>
79  * </thead>
80  * <tbody>
81  * <tr><td><code>1</code></td><td>Static entities &mdash; non-dynamic entities with no velocity.</td></tr>
82  * <tr><td><code>2</code></td><td>Dynamic entities &mdash; entities that have their <code>dynamic</code> property set to
83  * <code>true</code>.</td></tr>
84  * <tr><td><code>4</code></td><td>Kinematic entities &mdash; non-dynamic entities with velocity.</td></tr>
85  * <tr><td><code>8</code></td><td>My avatar.</td></tr>
86  * <tr><td><code>16</code></td><td>Other avatars.</td></tr>
87  * </tbody>
88  * </table>
89  * <p>The values for the collision types that are enabled are added together to give the CollisionMask value. For example, a
90  * value of <code>31</code> means that an entity will collide with all item types.</p>
91  * @typedef {number} CollisionMask
92  */
93 
94 // The USER collision groups are exposed to script and can be used to generate per-object collision masks.
95 // They are not necessarily the same as the BULLET_COLLISION_GROUPS, but we start them off with matching numbers.
96 const uint16_t USER_COLLISION_GROUP_STATIC = 1 << 0;
97 const uint16_t USER_COLLISION_GROUP_DYNAMIC = 1 << 1;
98 const uint16_t USER_COLLISION_GROUP_KINEMATIC = 1 << 2;
99 const uint16_t USER_COLLISION_GROUP_MY_AVATAR = 1 << 3;
100 const uint16_t USER_COLLISION_GROUP_OTHER_AVATAR = 1 << 4;
101 
102 const uint16_t ENTITY_COLLISION_MASK_DEFAULT =
103  USER_COLLISION_GROUP_STATIC |
104  USER_COLLISION_GROUP_DYNAMIC |
105  USER_COLLISION_GROUP_KINEMATIC |
106  USER_COLLISION_GROUP_MY_AVATAR |
107  USER_COLLISION_GROUP_OTHER_AVATAR;
108 
109 const uint16_t USER_COLLISION_MASK_AVATARS = USER_COLLISION_GROUP_MY_AVATAR | USER_COLLISION_GROUP_OTHER_AVATAR;
110 const uint16_t USER_COLLISION_MASK_ENTITIES = USER_COLLISION_GROUP_STATIC | USER_COLLISION_GROUP_DYNAMIC | USER_COLLISION_GROUP_KINEMATIC;
111 
112 const int32_t NUM_USER_COLLISION_GROUPS = 5;
113 
114 #endif // hifi_PhysicsCollisionGroups_h