TDME2  1.9.200
HeightMap.cpp
Go to the documentation of this file.
2 
3 #include <reactphysics3d/collision/shapes/HeightFieldShape.h>
4 #include <reactphysics3d/mathematics/Vector3.h>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/math/Vector3.h>
10 
11 using std::to_string;
12 
14 
18 
19 HeightMap::HeightMap(
20  int columns,
21  int rows,
22  float minHeight,
23  float maxHeight,
24  float* heightValues,
25  const Vector3& scale
26 ) {
27  this->scale.set(scale);
28  this->columns = columns;
29  this->rows = rows;
30  this->minHeight = minHeight;
31  this->maxHeight = maxHeight;
32  this->heightValues = heightValues;
33 }
34 
37 }
38 
39 void HeightMap::setScale(const Vector3& scale) {
40  Console::println("HeightMap::setScale(): not supported!");
41 }
42 
44  if (collisionShape == nullptr) return;
45  this->world->physicsCommon.destroyHeightFieldShape(static_cast<reactphysics3d::HeightFieldShape*>(collisionShape));
46  collisionShape = nullptr;
47  world = nullptr;
48 }
49 
51  if (this->world != nullptr && this->world != world) {
52  Console::println("HeightMap::createCollisionShape(): already attached to a world.");
53  }
54  this->world = world;
55 
56  //
57  collisionShape = world->physicsCommon.createHeightFieldShape(
58  columns,
59  rows,
60  minHeight,
61  maxHeight,
63  reactphysics3d::HeightFieldShape::HeightDataType::HEIGHT_FLOAT_TYPE,
64  1,
65  1.0f,
66  reactphysics3d::Vector3(scale.getX(), scale.getY(), scale.getZ())
67  );
68 }
69 
71 {
73 }
74 
Dynamic physics world class.
Definition: World.h:38
reactphysics3d::PhysicsCommon physicsCommon
Definition: World.h:53
reactphysics3d::CollisionShape * collisionShape
Height map physics primitive.
Definition: HeightMap.h:19
HeightMap(int columns, int rows, float minHeight, float maxHeight, float *heightValues, const Vector3 &scale=Vector3(1.0f, 1.0f, 1.0f))
Public constructor.
Definition: HeightMap.cpp:19
void destroyCollisionShape() override
Destroy collision shape.
Definition: HeightMap.cpp:43
void setScale(const Vector3 &scale) override
Set local scale.
Definition: HeightMap.cpp:39
~HeightMap()
Public destructor.
Definition: HeightMap.cpp:35
void createCollisionShape(World *world) override
Create collision shap.
Definition: HeightMap.cpp:50
BoundingVolume * clone() const override
Clones this bounding volume.
Definition: HeightMap.cpp:70
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 & set(float x, float y, float z)
Sets this vector3 by its components.
Definition: Vector3.h:70
Console class.
Definition: Console.h:29