Added collision meshes from files
This commit is contained in:
@@ -1,3 +1,24 @@
|
||||
/*
|
||||
Dane Johnson <dane@danejohnson.org>
|
||||
|
||||
LICENSE
|
||||
|
||||
Couch Copyright (C) 2021 Dane Johnson
|
||||
|
||||
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for details at
|
||||
https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
DESCRIPTION
|
||||
|
||||
Defines various collision shapes for rigidbodies and trigger areas
|
||||
*/
|
||||
#include "CollisionShape.h"
|
||||
|
||||
CollisionShape::CollisionShape() {
|
||||
@@ -15,3 +36,24 @@ BoxCollisionShape::BoxCollisionShape(float width, float height, float depth) {
|
||||
CapsuleCollisionShape::CapsuleCollisionShape(float radius, float height) {
|
||||
shape = new btCapsuleShape(radius, height);
|
||||
}
|
||||
|
||||
MeshCollisionShape::MeshCollisionShape(Mesh *mesh) {
|
||||
btCompoundShape *compoundShape = new btCompoundShape();
|
||||
|
||||
for (SubMesh *submesh : mesh->submeshes) {
|
||||
btTriangleIndexVertexArray *indexVertexArray = new btTriangleIndexVertexArray(
|
||||
submesh->indices.size(),
|
||||
(int*) &submesh->indices[0],
|
||||
sizeof(Index),
|
||||
submesh->vertices.size(),
|
||||
(float*) &submesh->vertices[0],
|
||||
sizeof(Vertex)
|
||||
);
|
||||
compoundShape->addChildShape(
|
||||
btTransform::getIdentity(),
|
||||
new btBvhTriangleMeshShape(indexVertexArray, true)
|
||||
);
|
||||
}
|
||||
|
||||
shape = compoundShape;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,36 @@
|
||||
/**
|
||||
@file
|
||||
@author Dane Johnson <dane@danejohnson.org>
|
||||
|
||||
@section LICENSE
|
||||
|
||||
Couch Copyright (C) 2021 Dane Johnson
|
||||
|
||||
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for details at
|
||||
https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
@section DESCRIPTION
|
||||
|
||||
Defines various collision shapes for rigidbodies and trigger areas
|
||||
*/
|
||||
#ifndef COLLISIONSHAPE_H
|
||||
#define COLLISIONSHAPE_H
|
||||
|
||||
#include <btBulletDynamicsCommon.h>
|
||||
|
||||
#include "types.h"
|
||||
#include "Mesh.h"
|
||||
|
||||
/**
|
||||
Base collision shape, should not be instanced directly
|
||||
*/
|
||||
class CollisionShape {
|
||||
public:
|
||||
CollisionShape();
|
||||
@@ -16,17 +42,41 @@ private:
|
||||
|
||||
class SphereCollisionShape : public CollisionShape {
|
||||
public:
|
||||
/**
|
||||
Creates a collision sphere with a defined radius
|
||||
@param radius The radius
|
||||
*/
|
||||
SphereCollisionShape(float radius);
|
||||
};
|
||||
|
||||
class BoxCollisionShape : public CollisionShape {
|
||||
public:
|
||||
/**
|
||||
Creates a collision cube with the desired width, height, and depth
|
||||
@param width The desired width
|
||||
@param height The desired height
|
||||
@param depth The desired depth
|
||||
*/
|
||||
BoxCollisionShape(float width, float height, float depth);
|
||||
};
|
||||
|
||||
class CapsuleCollisionShape: public CollisionShape {
|
||||
public:
|
||||
/**
|
||||
Creates a collision shape that is a cylinder with height, capped with a hemisphere of radius
|
||||
@param radius The hemisphere radius
|
||||
@param height The cylinder height
|
||||
*/
|
||||
CapsuleCollisionShape(float radius, float height);
|
||||
};
|
||||
|
||||
class MeshCollisionShape: public CollisionShape {
|
||||
public:
|
||||
/**
|
||||
Creates a concave mesh with the same faces as mesh
|
||||
@param mesh The mesh who's faces to use
|
||||
*/
|
||||
MeshCollisionShape(Mesh *mesh);
|
||||
};
|
||||
|
||||
#endif /* COLLISIONSHAPE_H */
|
||||
|
||||
@@ -105,6 +105,7 @@ public:
|
||||
protected:
|
||||
SubMeshList submeshes;
|
||||
virtual void SetupMesh();
|
||||
friend class MeshCollisionShape;
|
||||
};
|
||||
|
||||
#endif /* MESH_H */
|
||||
|
||||
@@ -1,26 +1,27 @@
|
||||
/*
|
||||
Dane Johnson <dane@danejohnson.org>
|
||||
Dane Johnson <dane@danejohnson.org>
|
||||
|
||||
LICENSE
|
||||
LICENSE
|
||||
|
||||
Couch Copyright (C) 2021 Dane Johnson
|
||||
Couch Copyright (C) 2021 Dane Johnson
|
||||
|
||||
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for details at
|
||||
https://www.gnu.org/licenses/gpl-3.0.html
|
||||
This program comes with ABSOLUTELY NO WARRANTY; without event the
|
||||
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
||||
See the GNU General Public License for details at
|
||||
https://www.gnu.org/licenses/gpl-3.0.html
|
||||
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under the terms of the GNU General Public License as published
|
||||
by the Free Software Foundation; either version 3 of the License,
|
||||
or (at your option) any later version.
|
||||
|
||||
DESCRIPTION
|
||||
DESCRIPTION
|
||||
|
||||
A spatial is a node with a transform property, i.e. position, scale or rotation.
|
||||
They can be instanced on the scene tree as an anchor for some other nodes.
|
||||
A spatial is a node with a transform property, i.e. position, scale or rotation.
|
||||
They can be instanced on the scene tree as an anchor for some other nodes.
|
||||
*/
|
||||
#include "Spatial.h"
|
||||
#include "Util.h"
|
||||
|
||||
Name Spatial::GetType() const {return "Spatial";}
|
||||
|
||||
@@ -32,6 +33,18 @@ void Spatial::SetTransform(Transform transform) {
|
||||
this->transform = transform;
|
||||
}
|
||||
|
||||
Transform Spatial::GetGlobalTransform() {
|
||||
Util::Die("Global transform is not implemented yet.\n"
|
||||
"I don't fully understand the maths yet!");
|
||||
return Transform();
|
||||
}
|
||||
|
||||
void Spatial::SetGlobalTransform(Transform globalTransform) {
|
||||
// TODO
|
||||
Util::Die("Global transform is not implemented yet.\n"
|
||||
"I don't fully understand the maths yet!");
|
||||
}
|
||||
|
||||
Spatial *Spatial::Create() {
|
||||
return new Spatial;
|
||||
}
|
||||
|
||||
@@ -46,6 +46,16 @@ public:
|
||||
@param transform The transform property
|
||||
*/
|
||||
void SetTransform(Transform transform);
|
||||
/**
|
||||
Gets the translation with relation to the world origin
|
||||
@returns the global transform
|
||||
*/
|
||||
Transform GetGlobalTransform();
|
||||
/**
|
||||
Sets the transform with relation to the world origin
|
||||
@param globalTransform The global transform property
|
||||
*/
|
||||
void SetGlobalTransform(Transform globalTransform);
|
||||
|
||||
/**
|
||||
Directly translates the spatial by offset
|
||||
|
||||
Reference in New Issue
Block a user