1#include "CollisionSystem.h"
3#include "Resources/Model.h"
4#include "Resources/Mesh.h"
6#include "Components/Core/MeshComponent.h"
8#include "PhysicsManager.h"
12 for (
auto & c :
pool) {
13 auto & data = getData(&c);
15 if (c.hasChanged() || !data.collisionShape) {
16 data.collisionShape = std::make_unique<btStaticPlaneShape>(btVector3(0, 0, 1), 0.0f);
19 c.collisionShape = data.collisionShape.get();
25 for (
auto & c : pool) {
26 auto & data = getData(&c);
28 if (c.hasChanged() || !data.collisionShape) {
29 data.collisionShape = std::make_unique<btSphereShape>(c.radius);
32 c.collisionShape = data.collisionShape.get();
38 for (
auto & c : pool) {
39 auto & data = getData(&c);
41 if (c.hasChanged() || !data.collisionShape) {
42 data.collisionShape = std::make_unique<btBoxShape>(toBullet(c.halfSize));
45 c.collisionShape = data.collisionShape.get();
51 for (
auto & c : pool) {
52 auto & data = getData(&c);
54 if (c.hasChanged() || !data.collisionShape) {
55 data.collisionShape = std::make_unique<btCapsuleShapeZ>(c.radius, c.height);
58 c.collisionShape = data.collisionShape.get();
64 for (
auto & c : pool) {
65 auto & data = getData(&c);
67 if (c.hasChanged() || !data.collisionShape) {
68 data.collisionShape = std::make_unique<btCylinderShapeZ>(btVector3(c.radius, c.radius, c.height));
71 c.collisionShape = data.collisionShape.get();
77 for (
auto & c : pool) {
78 auto & data = getData(&c);
80 if (c.hasChanged() || !data.collisionShape) {
81 data.collisionShape = std::make_unique<btEmptyShape>();
84 c.collisionShape = data.collisionShape.get();
92 for (
auto & part : model.parts) {
93 if (part.meshIndex !=
static_cast<uint32_t
>(-1))
return ∂
102 for (
auto & c : pool) {
103 auto & data = getData(&c);
105 if (c.hasChanged() || !data.collisionShape) {
106 Mesh * mesh =
nullptr;
107 glm::mat4 transform(1.0f);
110 mesh = c.mesh.resolve();
111 }
else if (c.model) {
112 auto model = c.model.resolve();
114 if (model->isLoaded() && model->parts.size()) {
115 auto part = findFirst(*model);
118 mesh = model->meshes[part->meshIndex].resolve();
119 transform = model->getPartTransform(*part);
125 if (mc && mc->meshHandle) {
126 mesh = mc->meshHandle.resolve();
131 data.mesh = std::make_unique<btTriangleMesh>();
135 auto indexes = mesh->getIndexes();
136 if (indexes.size()) {
137 const size_t faces = indexes.size() / 3;
139 for (
size_t i = 0; i < faces; ++i) {
140 auto v1 = *
reinterpret_cast<const glm::vec3 *
>(vertexData + indexes[i * 3 + 0] * stride);
141 auto v2 = *
reinterpret_cast<const glm::vec3 *
>(vertexData + indexes[i * 3 + 1] * stride);
142 auto v3 = *
reinterpret_cast<const glm::vec3 *
>(vertexData + indexes[i * 3 + 2] * stride);
144 v1 = glm::vec3(transform * glm::vec4(v1, 1));
145 v2 = glm::vec3(transform * glm::vec4(v2, 1));
146 v3 = glm::vec3(transform * glm::vec4(v3, 1));
148 data.mesh->addTriangle(
155 data.collisionShape = std::make_unique<btBvhTriangleMeshShape>(data.mesh.get(),
false);
160 c.collisionShape = data.collisionShape.get();
void update()
Updates the system state to that of the current frame.
ComponentPool< ComponentType > pool
Pool of components managed by the system.
A Context instance contains all the services, systems and runtime components needed to use Cogs.
Contains a handle to a Mesh resource to use when rendering using the MeshRenderComponent.
Contains the Engine, Renderer, resource managers and other systems needed to run Cogs....
Meshes contain streams of vertex data in addition to index data and options defining geometry used fo...
StreamReference getPositionStream()
Get the data of the stream containing positions.
Model resources define a template for a set of connected entities, with resources such as meshes,...