ephysics/ephysics/collision/shapes/SphereShape.cpp
Edouard DUPIN 66a20f94b3 [LICENCE] change ZLib to MPL-2 with athoriqzation of author:
Email exchange:

On 29.09.2017 14:35 Edouard DUPIN wrote:
Hello,

I have fork your physic engine and update it to fit better with my 3d
game engine and my framework.

I do many change:
  - on assert policy (I do not like it)
  - the back-end use of the vector3D and quaternion, that I have
already an other implementation...
  - Log management
  - Other build system (lutin)
  - organisation of doxygen (all in the header)
  - remove dependency of the STL (in progress)
  - some bugs ...
  - ...

And I have a problem with the licence. You use BSD-3 that is a good
point, but this licence does not force the user to send your their
modification. Then I ask you to permit me to change the licence of the
FORK in MPL-2 that have the benefit to force developer to publish the
modification and permit to use the software in a proprietary
application without contamination.

Best regards

Edouard DUPIN

https://github.com/HeeroYui
https://github.com/atria-soft
https://github.com/musicdsp

answers from chappuis.daniel@XXXXXXX.yyy
Hello,

I am glad that you have found the ReactPhysics3D library to be useful.
You said that you have found bugs. Maybe I have already found and fixed some of them but do not hesitate to report them
here (https://github.com/DanielChappuis/reactphysics3d/issues) if not done yet.

Concerning the license. The library is not under the BSD-3 license but under the zlib license (https://opensource.org/licenses/Zlib).
With this license, it is allowed to use the software in a proprietary application without contamination. Regarding your request to
change the license to the MPL-2, you can do it with the following condition : You need to add the following text in all the source files
of ReactPhysics3D where the license will change. It must always be clear where the original code is coming from.

--------------- TEXT TO ADD TO THE LICENSE IN EACH FILE -------------------------
Original ReactPhysics3D C++ library by Daniel Chappuis <http://www.reactphysics3d.com/>
This code is re-licensed with permission from ReactPhysics3D author.
---------------------------------------------------------------------------------

For example, you can see here how the flow/react library (java port of ReactPhysics3D) has been re-licensed from
ReactPhysics3D (https://github.com/flow/react/blob/develop/src/main/java/com/flowpowered/react/constraint/ContactPoint.java)

I hope it fits your needs.

Best Regards,

Daniel Chappuis
2017-10-02 16:20:11 +02:00

101 lines
3.1 KiB
C++

/** @file
* Original ReactPhysics3D C++ library by Daniel Chappuis <http://www.reactphysics3d.com/> This code is re-licensed with permission from ReactPhysics3D author.
* @author Daniel CHAPPUIS
* @author Edouard DUPIN
* @copyright 2010-2016, Daniel Chappuis
* @copyright 2017, Edouard DUPIN
* @license MPL v2.0 (see license file)
*/
#include <ephysics/collision/shapes/SphereShape.hpp>
#include <ephysics/collision/ProxyShape.hpp>
#include <ephysics/configuration.hpp>
using namespace ephysics;
// Constructor
/**
* @param radius Radius of the sphere (in meters)
*/
SphereShape::SphereShape(float radius) : ConvexShape(SPHERE, radius) {
assert(radius > 0.0f);
}
void SphereShape::setLocalScaling(const vec3& _scaling) {
m_margin = (m_margin / m_scaling.x()) * _scaling.x();
CollisionShape::setLocalScaling(_scaling);
}
void SphereShape::computeLocalInertiaTensor(etk::Matrix3x3& _tensor, float _mass) const {
float diag = 0.4f * _mass * m_margin * m_margin;
_tensor.setValue(diag, 0.0f, 0.0f,
0.0f, diag, 0.0f,
0.0f, 0.0f, diag);
}
void SphereShape::computeAABB(AABB& _aabb, const etk::Transform3D& _transform) const {
// Get the local extents in x,y and z direction
vec3 extents(m_margin, m_margin, m_margin);
// Update the AABB with the new minimum and maximum coordinates
_aabb.setMin(_transform.getPosition() - extents);
_aabb.setMax(_transform.getPosition() + extents);
}
void SphereShape::getLocalBounds(vec3& _min, vec3& _max) const {
// Maximum bounds
_max.setX(m_margin);
_max.setY(m_margin);
_max.setZ(m_margin);
// Minimum bounds
_min.setX(-m_margin);
_min.setY(_min.x());
_min.setZ(_min.x());
}
// Raycast method with feedback information
bool SphereShape::raycast(const Ray& ray, RaycastInfo& raycastInfo, ProxyShape* proxyShape) const {
const vec3 m = ray.point1;
float c = m.dot(m) - m_margin * m_margin;
// If the origin of the ray is inside the sphere, we return no int32_tersection
if (c < 0.0f) return false;
const vec3 rayDirection = ray.point2 - ray.point1;
float b = m.dot(rayDirection);
// If the origin of the ray is outside the sphere and the ray
// is pointing away from the sphere, there is no int32_tersection
if (b > 0.0f) return false;
float raySquareLength = rayDirection.length2();
// Compute the discriminant of the quadratic equation
float discriminant = b * b - raySquareLength * c;
// If the discriminant is negative or the ray length is very small, there is no int32_tersection
if (discriminant < 0.0f || raySquareLength < FLT_EPSILON) return false;
// Compute the solution "t" closest to the origin
float t = -b - etk::sqrt(discriminant);
assert(t >= 0.0f);
// If the hit point is withing the segment ray fraction
if (t < ray.maxFraction * raySquareLength) {
// Compute the int32_tersection information
t /= raySquareLength;
raycastInfo.body = proxyShape->getBody();
raycastInfo.proxyShape = proxyShape;
raycastInfo.hitFraction = t;
raycastInfo.worldPoint = ray.point1 + t * rayDirection;
raycastInfo.worldNormal = raycastInfo.worldPoint;
return true;
}
return false;
}