TDME2  1.9.200
Sphere.cpp
Go to the documentation of this file.
2 
3 #include <reactphysics3d/collision/shapes/SphereShape.h>
4 
5 #include <tdme/tdme.h>
7 #include <tdme/math/Math.h>
8 #include <tdme/math/Vector3.h>
10 
11 using std::to_string;
12 
15 using tdme::math::Math;
18 
19 Sphere::Sphere()
20 {
21  radius = Math::EPSILON;
22 }
23 
24 Sphere::Sphere(const Vector3& center, float radius, const Vector3& scale)
25 {
26  this->center.set(center);
27  this->radius = radius;
28  setScale(scale);
29 }
30 
33 }
34 
35 float Sphere::getRadius() const
36 {
37  return radius;
38 }
39 
40 void Sphere::setScale(const Vector3& scale) {
41  // store new scale
42  this->scale.set(scale);
43 
44  //
47 }
48 
50  if (collisionShape == nullptr) return;
51  this->world->physicsCommon.destroySphereShape(static_cast<reactphysics3d::SphereShape*>(collisionShape));
52  collisionShape = nullptr;
53  world = nullptr;
54 }
55 
57  if (this->world != nullptr && this->world != world) {
58  Console::println("Sphere::createCollisionShape(): already attached to a world.");
59  }
60  this->world = world;
61 
62  //
63  collisionShape = world->physicsCommon.createSphereShape(
64  Math::max(Math::EPSILON, radius * Math::max(Math::abs(scale.getZ()), Math::max(Math::abs(scale.getX()), Math::abs(scale.getY()))))
65  );
66 }
67 
69 {
70  return new Sphere(center, radius, scale);
71 }
72 
Dynamic physics world class.
Definition: World.h:38
reactphysics3d::PhysicsCommon physicsCommon
Definition: World.h:53
reactphysics3d::Transform collisionShapeLocalTransform
reactphysics3d::CollisionShape * collisionShape
Sphere physics primitive.
Definition: Sphere.h:19
Sphere()
Public constructor.
Definition: Sphere.cpp:19
void destroyCollisionShape() override
Destroy collision shape.
Definition: Sphere.cpp:49
void setScale(const Vector3 &scale) override
Set local scale.
Definition: Sphere.cpp:40
~Sphere()
Public destructor.
Definition: Sphere.cpp:31
void createCollisionShape(World *world) override
Create collision shap.
Definition: Sphere.cpp:56
BoundingVolume * clone() const override
Clones this bounding volume.
Definition: Sphere.cpp:68
Standard math functions.
Definition: Math.h:19
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
float getY() const
Definition: Vector3.h:117
float getX() const
Definition: Vector3.h:100
float getZ() const
Definition: Vector3.h:134
Vector3 & scale(float scalar)
Scales by scalar.
Definition: Vector3.h:201
Vector3 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70
Console class.
Definition: Console.h:29