Showing the changes to interface/src/ParticleSystem.cpp (1 of 4 files). Show all
Unified · Split
| @@ -56,6 +56,9 @@ ParticleSystem::ParticleSystem() { · 55 unmodified lines | ||
| 56 | 56 | a->collisionSphereRadius = 0.0f; |
| 57 | 57 | a->collisionSpherePosition = glm::vec3(0.0f, 0.0f, 0.0f); |
| 58 | 58 | a->usingCollisionSphere = false; |
| 59 | + a->collisionPlaneNormal = _upDirection; | |
| 60 | + a->collisionPlanePosition = glm::vec3(0.0f, 0.0f, 0.0f); | |
| 61 | + a->usingCollisionPlane = false; | |
| 59 | 62 | } |
| 60 | 63 | }; |
| 61 | 64 | |
| @@ -186,6 +189,9 @@ void ParticleSystem::setParticleAttributes(int emitterIndex, ParticleLifeStage l · 124 unmodified lines | ||
| 186 | 189 | a->usingCollisionSphere = attributes.usingCollisionSphere; |
| 187 | 190 | a->collisionSpherePosition = attributes.collisionSpherePosition; |
| 188 | 191 | a->collisionSphereRadius = attributes.collisionSphereRadius; |
| 192 | + a->usingCollisionPlane = attributes.usingCollisionPlane; | |
| 193 | + a->collisionPlanePosition = attributes.collisionPlanePosition; | |
| 194 | + a->collisionPlaneNormal = attributes.collisionPlaneNormal; | |
| 189 | 195 | } |
| 190 | 196 | |
| 191 | 197 | |
| @@ -260,13 +266,16 @@ void ParticleSystem::updateParticle(int p, float deltaTime) { · 68 unmodified lines | ||
| 260 | 266 | |
| 261 | 267 | // update position by velocity |
| 262 | 268 | _particle[p].position += _particle[p].velocity; |
| 263 | − | |
| 264 | − // collision with ground | |
| 265 | − if (_particle[p].position.y < _particle[p].radius) { | |
| 266 | − _particle[p].position.y = _particle[p].radius; | |
| 267 | − | |
| 268 | − if (_particle[p].velocity.y < 0.0f) { | |
| 269 | − _particle[p].velocity.y *= -myEmitter.particleAttributes[lifeStage].bounce; | |
| 269 | + | |
| 270 | + // collision with the plane surface | |
| 271 | + if (myEmitter.particleAttributes[lifeStage].usingCollisionPlane) { | |
| 272 | + glm::vec3 vectorFromParticleToPlanePosition = _particle[p].position - myEmitter.particleAttributes[lifeStage].collisionPlanePosition; | |
| 273 | + glm::vec3 normal = myEmitter.particleAttributes[lifeStage].collisionPlaneNormal; | |
| 274 | + float dot = glm::dot(vectorFromParticleToPlanePosition, normal); | |
| 275 | + if (dot < _particle[p].radius) { | |
| 276 | + _particle[p].position += normal * (_particle[p].radius - dot); | |
| 277 | + float planeNormalComponentOfVelocity = glm::dot(_particle[p].velocity, normal); | |
| 278 | + _particle[p].velocity -= normal * planeNormalComponentOfVelocity * (1.0f + myEmitter.particleAttributes[lifeStage].bounce); | |
| 270 | 279 | } |
| 271 | 280 | } |
| 272 | 281 | |