Showing the changes to libraries/entities/src/EntityCollisionSystem.cpp (1 of 1 file). Show all
Unified · Split
| @@ -131,33 +131,24 @@ void EntityCollisionSystem::updateCollisionWithEntities(EntityItem* entityA) { · 130 unmodified lines | ||
| 131 | 131 | EntityItem* entityB; |
| 132 | 132 | if (_entities->findSpherePenetration(center, radius, penetration, (void**)&entityB, Octree::NoLock)) { |
| 133 | 133 | // NOTE: 'penetration' is the depth that 'entityA' overlaps 'entityB'. It points from A into B. |
| 134 | − | |
| 135 | −qDebug() << "penetration:" << penetration << "in meters"; | |
| 136 | − | |
| 137 | 134 | glm::vec3 penetrationInTreeUnits = penetration / (float)(TREE_SCALE); |
| 138 | 135 | |
| 139 | −qDebug() << "penetrationInTreeUnits:" << penetrationInTreeUnits; | |
| 140 | − | |
| 141 | 136 | // Even if the Entities overlap... when the Entities are already moving appart |
| 142 | 137 | // we don't want to count this as a collision. |
| 143 | 138 | glm::vec3 relativeVelocity = entityA->getVelocity() - entityB->getVelocity(); |
| 144 | 139 | |
| 145 | −qDebug() << "A old velocity:" << entityA->getVelocity() * (float)TREE_SCALE << "in meters"; | |
| 146 | −qDebug() << "B old velocity:" << entityB->getVelocity() * (float)TREE_SCALE << "in meters"; | |
| 147 | −qDebug() << "relativeVelocity:" << relativeVelocity * (float)TREE_SCALE << "in meters"; | |
| 148 | − | |
| 149 | 140 | bool movingTowardEachOther = glm::dot(relativeVelocity, penetrationInTreeUnits) > 0.0f; |
| 150 | 141 | bool doCollisions = true; |
| 151 | 142 | |
| 152 | 143 | if (doCollisions) { |
| 153 | − //entityA->collisionWithEntity(entityB, penetration); | |
| 154 | − //entityB->collisionWithEntity(entityA, penetration * -1.0f); // the penetration is reversed | |
| 144 | + entityA->collisionWithEntity(entityB, penetration); | |
| 145 | + entityB->collisionWithEntity(entityA, penetration * -1.0f); // the penetration is reversed | |
| 155 | 146 | |
| 156 | 147 | CollisionInfo collision; |
| 157 | 148 | collision._penetration = penetration; |
| 158 | 149 | // for now the contactPoint is the average between the the two paricle centers |
| 159 | 150 | collision._contactPoint = (0.5f * (float)TREE_SCALE) * (entityA->getPosition() + entityB->getPosition()); |
| 160 | − //emitGlobalEntityCollisionWithEntity(entityA, entityB, collision); | |
| 151 | + emitGlobalEntityCollisionWithEntity(entityA, entityB, collision); | |
| 161 | 152 | |
| 162 | 153 | glm::vec3 axis = glm::normalize(penetration); |
| 163 | 154 | glm::vec3 axialVelocity = glm::dot(relativeVelocity, axis) * axis; |
| @@ -165,85 +156,33 @@ qDebug() << "relativeVelocity:" << relativeVelocity * (float)TREE_SCALE << "in m · 1 unmodified line | ||
| 165 | 156 | float massA = entityA->getMass(); |
| 166 | 157 | float massB = entityB->getMass(); |
| 167 | 158 | float totalMass = massA + massB; |
| 168 | −qDebug() << "massA:" << massA; | |
| 169 | −qDebug() << "massB:" << massB; | |
| 170 | −qDebug() << "totalMass:" << totalMass; | |
| 171 | 159 | |
| 172 | 160 | // handle Entity A |
| 173 | − | |
| 174 | −qDebug() << "OLD - VALUES - entityA ----"; | |
| 175 | −qDebug() << "entityA->getVelocity():" << entityA->getVelocity() << "no scaling"; | |
| 176 | −qDebug() << "entityA->getVelocity():" << entityA->getVelocity() * (float)TREE_SCALE << "in meters"; | |
| 177 | −qDebug() << "entityA->getPosition():" << entityA->getPosition() * (float)TREE_SCALE << "in meters"; | |
| 178 | − | |
| 179 | − | |
| 180 | − glm::vec3 newVelocity = entityA->getVelocity() - axialVelocity * (2.0f * massB / totalMass); | |
| 181 | − glm::vec3 newPosition = entityA->getPosition() - 0.5f * penetrationInTreeUnits; | |
| 182 | − | |
| 183 | −qDebug() << "A new Velocity:" << newVelocity * (float)TREE_SCALE << "in meters"; | |
| 184 | −qDebug() << "A new Position:" << newPosition * (float)TREE_SCALE << "in meters"; | |
| 161 | + glm::vec3 newVelocityA = entityA->getVelocity() - axialVelocity * (2.0f * massB / totalMass); | |
| 162 | + glm::vec3 newPositionA = entityA->getPosition() - 0.5f * penetrationInTreeUnits; | |
| 185 | 163 | |
| 186 | 164 | EntityItemProperties propertiesA = entityA->getProperties(); |
| 187 | − | |
| 188 | −qDebug() << "propertiesA = entityA->getProperties() --- BEFORE SETTING ----"; | |
| 189 | −qDebug() << " propertiesA.getPosition():" << propertiesA.getPosition() << "in meters"; | |
| 190 | −qDebug() << " propertiesA.getVelocity():" << propertiesA.getVelocity() << "in meters"; | |
| 191 | −qDebug() << " propertiesA.getMaximumAACubeInTreeUnits():" << propertiesA.getMaximumAACubeInTreeUnits(); | |
| 192 | − | |
| 193 | 165 | EntityItemID idA(entityA->getID()); |
| 194 | − propertiesA.setVelocity(newVelocity * (float)TREE_SCALE); | |
| 195 | − propertiesA.setPosition(newPosition * (float)TREE_SCALE); | |
| 196 | − | |
| 197 | −qDebug() << "updateEntity(idA, propertiesA)...."; | |
| 198 | −qDebug() << " idA:" << idA; | |
| 199 | −qDebug() << " propertiesA.getPosition():" << propertiesA.getPosition() << "in meters"; | |
| 200 | −qDebug() << " propertiesA.getVelocity():" << propertiesA.getVelocity() << "in meters"; | |
| 201 | −qDebug() << " propertiesA.getMaximumAACubeInTreeUnits():" << propertiesA.getMaximumAACubeInTreeUnits(); | |
| 166 | + propertiesA.setVelocity(newVelocityA * (float)TREE_SCALE); | |
| 167 | + propertiesA.setPosition(newPositionA * (float)TREE_SCALE); | |
| 202 | 168 | |
| 203 | 169 | _entities->updateEntity(idA, propertiesA); |
| 204 | − | |
| 205 | −qDebug() << "AFTER updateEntity()...."; | |
| 206 | −qDebug() << " entityA->getVelocity():" << entityA->getVelocity() << "no scaling"; | |
| 207 | −qDebug() << " entityA->getPosition():" << entityA->getPosition() * (float)TREE_SCALE << "in meters"; | |
| 208 | − | |
| 209 | − | |
| 210 | 170 | _packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, idA, propertiesA); |
| 211 | − //queueEntityMessage(PacketTypeEntityAddOrEdit, entityID, properties); | |
| 212 | − | |
| 213 | −qDebug() << "OLD - VALUES - entityB ----"; | |
| 214 | −qDebug() << " entityB->getVelocity():" << entityB->getVelocity() << "no scaling"; | |
| 215 | −qDebug() << " entityB->getPosition():" << entityB->getPosition() * (float)TREE_SCALE << "in meters"; | |
| 216 | 171 | |
| 217 | 172 | glm::vec3 newVelocityB = entityB->getVelocity() + axialVelocity * (2.0f * massA / totalMass); |
| 218 | 173 | glm::vec3 newPositionB = entityB->getPosition() + 0.5f * penetrationInTreeUnits; |
| 219 | 174 | |
| 220 | −qDebug() << "B new Velocity:" << newVelocityB << "no scaling"; | |
| 221 | −qDebug() << "B new Position:" << newPositionB * (float)TREE_SCALE << "in meters"; | |
| 222 | − | |
| 223 | 175 | EntityItemProperties propertiesB = entityB->getProperties(); |
| 224 | 176 | |
| 225 | −qDebug() << "propertiesB = entityB->getProperties()"; | |
| 226 | −qDebug() << " propertiesB.getPosition():" << propertiesB.getPosition() << "not scaled, should be meters"; | |
| 227 | −qDebug() << " propertiesB.getVelocity():" << propertiesB.getVelocity() << "not scaled, should be ???"; | |
| 228 | −qDebug() << " propertiesB.getMaximumAACubeInTreeUnits():" << propertiesB.getMaximumAACubeInTreeUnits(); | |
| 229 | − | |
| 230 | 177 | EntityItemID idB(entityB->getID()); |
| 231 | 178 | propertiesB.setVelocity(newVelocityB * (float)TREE_SCALE); |
| 232 | 179 | propertiesB.setPosition(newPositionB * (float)TREE_SCALE); |
| 233 | 180 | |
| 234 | −qDebug() << "updateEntity(idB, propertiesB)...."; | |
| 235 | −qDebug() << " idB:" << idB; | |
| 236 | −qDebug() << " propertiesB.getPosition():" << propertiesB.getPosition(); | |
| 237 | −qDebug() << " propertiesB.getVelocity():" << propertiesB.getVelocity(); | |
| 238 | −qDebug() << " propertiesB.getMaximumAACubeInTreeUnits():" << propertiesB.getMaximumAACubeInTreeUnits(); | |
| 239 | − | |
| 240 | 181 | _entities->updateEntity(idB, propertiesB); |
| 241 | 182 | |
| 242 | −qDebug() << "AFTER updateEntity()...."; | |
| 243 | −qDebug() << " entityB->getVelocity():" << entityB->getVelocity() << "no scaling"; | |
| 244 | −qDebug() << " entityB->getPosition():" << entityB->getPosition() * (float)TREE_SCALE << "in meters"; | |
| 245 | − | |
| 246 | 183 | _packetSender->queueEditEntityMessage(PacketTypeEntityAddOrEdit, idB, propertiesB); |
| 184 | + | |
| 185 | + // TODO: Do we need this? | |
| 247 | 186 | //_packetSender->releaseQueuedMessages(); |
| 248 | 187 | |
| 249 | 188 | //updateCollisionSound(entityA, penetration, COLLISION_FREQUENCY); |
| @@ -252,6 +191,8 @@ qDebug() << " entityB->getPosition():" << entityB->getPosition() * (float)TRE · 2 unmodified lines | ||
| 252 | 191 | } |
| 253 | 192 | |
| 254 | 193 | void EntityCollisionSystem::updateCollisionWithAvatars(EntityItem* entity) { |
| 194 | + | |
| 195 | + // TODO: implement support for colliding with avatars | |
| 255 | 196 | |
| 256 | 197 | #if 0 |
| 257 | 198 | // Entities that are in hand, don't collide with avatars |