Add force testing.
This commit is contained in:
@ -95,6 +95,22 @@ BodyID Collider::getBodyId() {
|
||||
return bodyId;
|
||||
}
|
||||
|
||||
glm::vec3 Collider::getVelocity() {
|
||||
if(!this->isColliderReady()) return glm::vec3(0.0f, 0.0f, 0.0f);
|
||||
auto vel = getBodyInterface().GetLinearVelocity(this->bodyId);
|
||||
return glm::vec3(vel.GetX(), vel.GetY(), vel.GetZ());
|
||||
}
|
||||
|
||||
void Collider::setVelocity(const glm::vec3 velocity) {
|
||||
if(!this->isColliderReady()) {
|
||||
assertUnreachable("Collider is not ready.");
|
||||
}
|
||||
|
||||
getBodyInterface().SetLinearVelocity(
|
||||
this->bodyId, RVec3(velocity.x, velocity.y, velocity.z)
|
||||
);
|
||||
}
|
||||
|
||||
void Collider::setColliderType(const ColliderType type) {
|
||||
this->colliderType = type;
|
||||
|
||||
@ -105,4 +121,17 @@ void Collider::setColliderType(const ColliderType type) {
|
||||
Collider::getMotionType(type),
|
||||
EActivation::Activate// TODO: Should be false on kinematics
|
||||
);
|
||||
}
|
||||
|
||||
void Collider::addForce(
|
||||
const glm::vec3 force,
|
||||
const glm::vec3 inPoint
|
||||
) {
|
||||
if(!this->isColliderReady()) assertUnreachable("Collider is not ready.");
|
||||
|
||||
getBodyInterface().AddForce(
|
||||
this->bodyId,
|
||||
RVec3(force.x, force.y, force.z),
|
||||
RVec3(0, 0, 0)
|
||||
);
|
||||
}
|
@ -74,11 +74,36 @@ namespace Dawn {
|
||||
*/
|
||||
JPH::BodyID getBodyId();
|
||||
|
||||
/**
|
||||
* Returns the velocity of the collider.
|
||||
*
|
||||
* @return The velocity of the collider.
|
||||
*/
|
||||
glm::vec3 getVelocity();
|
||||
|
||||
/**
|
||||
* Sets the collider type.
|
||||
*
|
||||
* @param colliderType The collider type.
|
||||
*/
|
||||
void setColliderType(ColliderType colliderType);
|
||||
|
||||
/**
|
||||
* Sets the velocity of the collider.
|
||||
*
|
||||
* @param velocity The velocity.
|
||||
*/
|
||||
void setVelocity(const glm::vec3 velocity);
|
||||
|
||||
/**
|
||||
* Adds a force to the collider.
|
||||
*
|
||||
* @param force Force to add.
|
||||
* @param inPoint Application point of the force.
|
||||
*/
|
||||
void addForce(
|
||||
const glm::vec3 force,
|
||||
const glm::vec3 inPoint = glm::vec3(0, 0, 0)
|
||||
);
|
||||
};
|
||||
}
|
@ -9,25 +9,25 @@ using namespace Dawn;
|
||||
|
||||
void SphereMesh::create(
|
||||
std::shared_ptr<Mesh> mesh,
|
||||
const float radius,
|
||||
const uint32_t segments,
|
||||
const uint32_t rings
|
||||
const float_t radius,
|
||||
const int32_t segments,
|
||||
const int32_t rings
|
||||
) {
|
||||
// Create the vertices
|
||||
std::vector<glm::vec3> vertices;
|
||||
for(uint32_t r = 0; r < rings; ++r) {
|
||||
for(uint32_t s = 0; s < segments; ++s) {
|
||||
float const y = sin(-M_PI_2 + M_PI * r / rings);
|
||||
float const x = cos(2 * M_PI * s / segments) * sin(M_PI * r / rings);
|
||||
float const z = sin(2 * M_PI * s / segments) * sin(M_PI * r / rings);
|
||||
float_t const y = sin(-M_PI_2 + M_PI * r / rings);
|
||||
float_t const x = cos(2 * M_PI * s / segments) * sin(M_PI * r / rings);
|
||||
float_t const z = sin(2 * M_PI * s / segments) * sin(M_PI * r / rings);
|
||||
vertices.push_back(glm::vec3(x, y, z) * radius);
|
||||
}
|
||||
}
|
||||
|
||||
// Create the indices
|
||||
std::vector<int32_t> indices;
|
||||
for(uint32_t r = 0; r < rings - 1; ++r) {
|
||||
for(uint32_t s = 0; s < segments - 1; ++s) {
|
||||
for(int32_t r = 0; r < rings - 1; ++r) {
|
||||
for(int32_t s = 0; s < segments - 1; ++s) {
|
||||
indices.push_back(r * segments + s);
|
||||
indices.push_back(r * segments + (s + 1));
|
||||
indices.push_back((r + 1) * segments + (s + 1));
|
||||
|
@ -19,9 +19,9 @@ namespace Dawn {
|
||||
*/
|
||||
static void create(
|
||||
std::shared_ptr<Mesh> mesh,
|
||||
const float radius = 1.0f,
|
||||
const uint32_t segments = 16,
|
||||
const uint32_t rings = 16
|
||||
const float_t radius = 1.0f,
|
||||
const int32_t segments = 16,
|
||||
const int32_t rings = 16
|
||||
);
|
||||
};
|
||||
}
|
@ -5,9 +5,8 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "scene/SceneList.hpp"
|
||||
#include "component/SimpleComponent.hpp"
|
||||
#include "component/display/Camera.hpp"
|
||||
#include "prefab/SimpleSpinningCube.hpp"
|
||||
|
||||
#include "component/display/material/SimpleTexturedMaterial.hpp"
|
||||
#include "component/display/MeshRenderer.hpp"
|
||||
#include "display/mesh/CubeMesh.hpp"
|
||||
|
Reference in New Issue
Block a user