Allow GameObjects without physics

This commit is contained in:
MrLetsplay 2023-09-16 20:41:30 +02:00
parent 777628d7e1
commit 4026a09928
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg
2 changed files with 20 additions and 1 deletions

View File

@ -5,6 +5,7 @@
#include "internal.h"
#include "internal/physics.h"
#include "object.h"
namespace kek {
@ -44,18 +45,36 @@ void GameObject::addPhysics(btCollisionShape *shape, float mass, int collisionFl
}
void GameObject::rotateTo(glm::quat rotation) {
if(!this->physics) {
DefaultRotateableObject::rotateTo(rotation);
return;
}
this->physics->body->getWorldTransform().setRotation(Physics::fromGLM(rotation));
}
glm::quat GameObject::getRotation() {
if(!this->physics) {
return DefaultRotateableObject::getRotation();
}
return Physics::toGLM(this->physics->body->getWorldTransform().getRotation());
}
void GameObject::moveTo(glm::vec3 position) {
if(!this->physics) {
DefaultRotateableObject::moveTo(position);
return;
}
this->physics->body->getWorldTransform().setOrigin(Physics::fromGLM(position));
}
glm::vec3 GameObject::getPosition() {
if(!this->physics) {
return DefaultRotateableObject::getPosition();
}
return Physics::toGLM(this->physics->body->getWorldTransform().getOrigin());
}

View File

@ -8,7 +8,7 @@
namespace kek {
class GameObject: public RotateableObject {
class GameObject: public DefaultRotateableObject {
protected:
std::vector<Mesh *> meshes;