2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (C) 2013 Henry van Merode. All rights reserved.
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2022-07-10 09:47:41 +08:00
|
|
|
https://axis-project.github.io/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2022-07-16 10:43:05 +08:00
|
|
|
#ifndef __AX_PU_PARTICLE_3D_BASE_COLLIDER_H__
|
|
|
|
#define __AX_PU_PARTICLE_3D_BASE_COLLIDER_H__
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#include "extensions/Particle3D/PU/CCPUAffector.h"
|
|
|
|
#include "3d/CCAABB.h"
|
|
|
|
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_BEGIN
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
struct PUParticle3D;
|
2022-07-16 10:43:05 +08:00
|
|
|
class AX_EX_DLL PUBaseCollider : public PUAffector
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Determines how a particle collision should be determined. IT_POINT means that the position of
|
2019-11-23 20:27:39 +08:00
|
|
|
the particle will be validated against the Colliders' shape. IT_BOX means that the dimensions
|
|
|
|
(width, height and depth) are used to determine whether the particle collides.
|
|
|
|
*/
|
|
|
|
enum IntersectionType
|
|
|
|
{
|
|
|
|
IT_POINT,
|
|
|
|
IT_BOX
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Determines how a particle behaves after collision with this collider. The behaviour of the
|
|
|
|
particle is solved in the collider and only behaviour that needs the colliders?data is taken
|
2021-12-25 10:04:45 +08:00
|
|
|
into account. The fact that a particle expires for example, can be achieved by using an
|
2019-11-23 20:27:39 +08:00
|
|
|
Observer in combination with an EventHandler (DoExpireEventHandler).
|
2021-12-25 10:04:45 +08:00
|
|
|
CT_NONE means that the particle doesn't do anything. This value should be set if the behaviour
|
2019-11-23 20:27:39 +08:00
|
|
|
of the particle is determined outside the collider (for example, expiring the particle).
|
|
|
|
CT_BOUNCE means that the particle bounces off the collider.
|
|
|
|
CT_FLOW means that the particle flows around the contours of the collider.
|
|
|
|
*/
|
|
|
|
enum CollisionType
|
|
|
|
{
|
|
|
|
CT_NONE,
|
|
|
|
CT_BOUNCE,
|
|
|
|
CT_FLOW,
|
|
|
|
};
|
|
|
|
|
|
|
|
// Constants
|
|
|
|
static const float DEFAULT_BOUNCYNESS;
|
|
|
|
static const float DEFAULT_FRICTION;
|
|
|
|
static const IntersectionType DEFAULT_INTERSECTION_TYPE;
|
|
|
|
static const CollisionType DEFAULT_COLLISION_TYPE;
|
|
|
|
|
|
|
|
virtual void preUpdateAffector(float deltaTime) override;
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
/** Returns the type of intersection.
|
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
IntersectionType getIntersectionType() const;
|
|
|
|
|
|
|
|
/** Sets the type of intersection.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setIntersectionType(const IntersectionType& intersectionType);
|
|
|
|
|
|
|
|
/** Returns the type of collision.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
CollisionType getCollisionType() const;
|
|
|
|
|
|
|
|
/** Sets the type of collision.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setCollisionType(const CollisionType& collisionType);
|
|
|
|
|
|
|
|
/** Returns the friction value.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getFriction() const;
|
|
|
|
|
|
|
|
/** Sets the friction value.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setFriction(const float friction);
|
|
|
|
|
|
|
|
/** Returns the bouncyness value.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
float getBouncyness() const;
|
|
|
|
|
|
|
|
/** Sets the bouncyness value.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
2019-11-23 20:27:39 +08:00
|
|
|
void setBouncyness(const float bouncyness);
|
|
|
|
|
|
|
|
/** Fill the AxisAlignedBox with data derived from the other arguments.
|
2021-12-25 10:04:45 +08:00
|
|
|
*/
|
|
|
|
void populateAlignedBox(AABB& box, const Vec3& position, const float width, const float height, const float depth);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
/** Recalculates the rotation speed after collision.
|
2021-12-25 10:04:45 +08:00
|
|
|
This function must be explicitly called in the updatePUAffector(float deltaTime) function of the class that
|
|
|
|
inherits from BaseCollider.
|
2019-11-23 20:27:39 +08:00
|
|
|
*/
|
|
|
|
void calculateRotationSpeedAfterCollision(PUParticle3D* particle);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual void copyAttributesTo(PUAffector* affector) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2022-03-18 21:46:07 +08:00
|
|
|
PUBaseCollider();
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~PUBaseCollider();
|
|
|
|
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
float _friction; // Physics characteristic that influences particle rotation speed.
|
|
|
|
float _bouncyness; // Physics characteristic that influences particle velocity.
|
2019-11-23 20:27:39 +08:00
|
|
|
IntersectionType _intersectionType;
|
|
|
|
CollisionType _collisionType;
|
2021-12-25 10:04:45 +08:00
|
|
|
float _velocityScale; // Value set in the particle system, but stored in the collider for convenience.
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
2022-07-11 17:50:21 +08:00
|
|
|
NS_AX_END
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
#endif
|