From 993dddb130ee7299c33d7d025a371e1f7a6ea670 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Tue, 15 Mar 2022 07:25:20 +0200 Subject: [PATCH] separated mesh data from Mesh class --- CMakeLists.txt | 2 +- assimpModelReader.cpp | 15 +++++--- box.cpp | 20 ++++++----- mesh.cpp | 84 +++++++++++++------------------------------ mesh.h | 41 +++++---------------- meshData.cpp | 29 +++++++++++++++ meshData.h | 39 ++++++++++++++++++++ node.h | 1 - quad.cpp | 21 ++++++----- ray.cpp | 13 +++++-- 10 files changed, 144 insertions(+), 121 deletions(-) create mode 100644 meshData.cpp create mode 100644 meshData.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 81b64a6..bcf2ed1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ cmake_policy(SET CMP0015 NEW) set(GUI text.cpp) set(UTILS util.cpp) set(MATH quaternion.cpp vector.cpp matrix.cpp ray.cpp) -set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp) +set(RENDER lineRenderer.cpp particleEmitter.cpp camera.cpp light.cpp material.cpp mesh.cpp meshData.cpp model.cpp node.cpp quad.cpp box.cpp root.cpp shader.cpp texture.cpp) set(ANIM animationController.cpp animationChannel.cpp animation.cpp animatable.cpp keyframeChannel.cpp driver.cpp) set(ARMATURE skeleton.cpp bone.cpp ikSolver.cpp) set(ASSET_READERS abstractAssetReader.cpp imageReader.cpp fontReader.cpp modelReader.cpp assimpModelReader.cpp xmlModelReader.cpp) diff --git a/assimpModelReader.cpp b/assimpModelReader.cpp index 97be523..85171ce 100644 --- a/assimpModelReader.cpp +++ b/assimpModelReader.cpp @@ -12,10 +12,12 @@ namespace vb01{ AssimpModelReader::AssimpModelReader(Model *model, string path) : ModelReader(model, path){ Importer importer; const aiScene *scene = importer.ReadFile(path, aiProcess_Triangulate | aiProcess_FlipUVs | aiProcess_GenNormals | aiProcess_CalcTangentSpace); + if(!scene || scene->mFlags & AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode){ cout<<"Failed to load model:"<mRootNode, scene, model); } @@ -24,6 +26,7 @@ namespace vb01{ aiMesh *mesh = scene->mMeshes[node->mMeshes[i]]; processMesh(mesh, scene, currentNode); } + for(int i = 0;i < node->mNumChildren; i++){ Node *childNode = new Node(); currentNode->attachChild(childNode); @@ -33,10 +36,11 @@ namespace vb01{ void AssimpModelReader::processMesh(aiMesh *mesh, const aiScene *scene, Node *currentNode){ const int numTris = mesh->mNumFaces; - Mesh::Vertex *vertices = new Mesh::Vertex[3 * numTris]; + MeshData::Vertex *vertices = new MeshData::Vertex[3 * numTris]; u32 *indices = new u32[3 * numTris]; + for(int i = 0; i < 3 * numTris; i++){ - Mesh::Vertex v; + MeshData::Vertex v; v.pos.x = mesh->mVertices[i].x; v.pos.y = mesh->mVertices[i].y; v.pos.z = mesh->mVertices[i].z; @@ -61,18 +65,19 @@ namespace vb01{ v.uv = Vector2::VEC_ZERO; vertices[i] = v; } + for(int i = 0; i < numTris; i++){ int numFaceIndices = mesh->mFaces[i].mNumIndices; - for(int j = 0; j < numFaceIndices; j++){ + + for(int j = 0; j < numFaceIndices; j++) indices[numFaceIndices * i + j] = mesh->mFaces[i].mIndices[j]; - } } /* if(mesh->mMaterialIndex>=0){ aiMaterial *material=scene->mMaterial[mesh->mMaterialIndex]; } */ - Mesh *vbMesh = new Mesh(vertices, indices, numTris); + Mesh *vbMesh = new Mesh(MeshData(vertices, indices, numTris)); vbMesh ->construct(); currentNode->attachMesh(vbMesh); } diff --git a/box.cpp b/box.cpp index 429089d..d41a877 100755 --- a/box.cpp +++ b/box.cpp @@ -2,19 +2,13 @@ namespace vb01{ Box::Box(Vector3 size){ - this->staticVerts = false; - - numTris = 12; - indices = new u32[3 * numTris]; - vertices = new Vertex[3 * numTris]; - setSize(size); - construct(); } void Box::setSize(Vector3 size){ this->size = size; + Vector3 pos[] = { Vector3(size.x / 2, size.y / 2, size.z / 2), Vector3(-size.x / 2, size.y / 2, size.z / 2), @@ -26,6 +20,7 @@ namespace vb01{ Vector3(-size.x / 2, -size.y / 2, -size.z / 2), Vector3(size.x / 2, -size.y / 2, -size.z / 2) }; + Vector3 norm[] = { Vector3(0, 0, 1), Vector3(0, 1, 0), @@ -35,12 +30,14 @@ namespace vb01{ Vector3(0, -1, 0), Vector3(-1, 0, 0) }; + Vector2 tex[] = { Vector2(1, 1), Vector2(0, 1), Vector2(0, 0), Vector2(1, 0) }; + unsigned int data[] = { 1, 3, 2, 4, 3, 0, 0, 3, 1, 4, 3, 0, 1, 3, 2, 5, 3, 3, @@ -60,13 +57,20 @@ namespace vb01{ 5, 5, 2, 6, 5, 1, 4, 5, 3, 7, 5, 0, 4, 5, 3, 6, 5, 1 }; + + int numTris = 12; + u32 *indices = new u32[3 * numTris]; + MeshData::Vertex *vertices = new MeshData::Vertex[3 * numTris]; + for(int i = 0; i < 3 * numTris; i++){ - Vertex v; + MeshData::Vertex v; v.pos = pos[data[3 * i]]; v.norm = norm[data[3 * i + 1]]; v.uv = tex[data[3 * i + 2]]; vertices[i] = v; indices[i] = i; } + + meshBase = MeshData(vertices, indices, 3 * numTris); } } diff --git a/mesh.cpp b/mesh.cpp index 3c95ac1..b2ab102 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -17,31 +17,8 @@ using namespace std; using namespace glm; namespace vb01{ - void Mesh::ShapeKey::animate(float value, KeyframeChannel keyframeChannel){ - switch(keyframeChannel.type){ - case KeyframeChannel::SHAPE_KEY_MIN: - this->minValue = value; - break; - case KeyframeChannel::SHAPE_KEY_VALUE: - this->value = value; - break; - case KeyframeChannel::SHAPE_KEY_MAX: - this->maxValue = value; - break; - } - } - - Mesh::Mesh(){} - - Mesh::Mesh(Vertex *vertices, unsigned int *indices, int numTris, string *vertexGroups, int numVertexGroups, ShapeKey *shapeKeys, int numShapeKeys, string name){ - this->vertices = vertices; - this->indices = indices; - this->numTris = numTris; - this->vertexGroups = vertexGroups; - this->numVertexGroups = numVertexGroups; - this->shapeKeys = shapeKeys; - this->numShapeKeys = numShapeKeys; - this->name = name; + Mesh::Mesh(MeshData meshBase){ + this->meshBase = meshBase; } Mesh::~Mesh(){ @@ -54,9 +31,6 @@ namespace vb01{ glDeleteVertexArrays(1, &VAO); glDeleteBuffers(1, &EBO); glDeleteBuffers(1, &VBO); - - delete[] indices; - delete[] vertices; } void Mesh::construct(){ @@ -99,31 +73,31 @@ namespace vb01{ glGenBuffers(1, &VBO); glGenBuffers(1, &EBO); - u32 size = sizeof(Vertex); + u32 size = sizeof(MeshData::Vertex); glBindVertexArray(VAO); glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferData(GL_ARRAY_BUFFER, 3 * numTris * size, staticVerts ? vertices : NULL, staticVerts ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW); + glBufferData(GL_ARRAY_BUFFER, 3 * meshBase.numTris * size, meshBase.vertices, GL_STATIC_DRAW); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * numTris * sizeof(u32), staticVerts ? indices : NULL, staticVerts ? GL_STATIC_DRAW : GL_DYNAMIC_DRAW); + glBufferData(GL_ELEMENT_ARRAY_BUFFER, 3 * meshBase.numTris * sizeof(u32), meshBase.indices, GL_STATIC_DRAW); glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, size, (void*)0); glEnableVertexAttribArray(0); - glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, norm))); + glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, norm))); glEnableVertexAttribArray(1); - glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, uv))); + glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, uv))); glEnableVertexAttribArray(2); - glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, tan))); + glVertexAttribPointer(3, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, tan))); glEnableVertexAttribArray(3); - glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, biTan))); + glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, biTan))); glEnableVertexAttribArray(4); - glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, weights))); + glVertexAttribPointer(5, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, weights))); glEnableVertexAttribArray(5); - glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, boneIndices))); + glVertexAttribPointer(6, 4, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, boneIndices))); glEnableVertexAttribArray(6); - for(int i = 0; i < numShapeKeys; i++){ - glVertexAttribPointer(7 + i, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(Vertex, shapeKeyOffsets) + 3 * i * sizeof(float))); + for(int i = 0; i < meshBase.numShapeKeys; i++){ + glVertexAttribPointer(7 + i, 3, GL_FLOAT, GL_FALSE, size, (void*)(offsetof(MeshData::Vertex, shapeKeyOffsets) + 3 * i * sizeof(float))); glEnableVertexAttribArray(7 + i); } } @@ -163,7 +137,7 @@ namespace vb01{ if(skeleton) updateSkeleton(shader); - if(numShapeKeys > 0) + if(meshBase.numShapeKeys > 0) updateShapeKeys(shader); if(reflect) @@ -187,22 +161,22 @@ namespace vb01{ } void Mesh::updateShapeKeys(Shader *shader){ - shader->editShader(Shader::VERTEX_SHADER, 5, "const int numShapeKeys=" + to_string(numShapeKeys) + ";"); + shader->editShader(Shader::VERTEX_SHADER, 5, "const int numShapeKeys=" + to_string(meshBase.numShapeKeys) + ";"); - for(int i = 0; i < numShapeKeys; i++){ - if(shapeKeys[i].value < shapeKeys[i].minValue) - shapeKeys[i].value = shapeKeys[i].minValue; - else if(shapeKeys[i].value > shapeKeys[i].maxValue) - shapeKeys[i].value = shapeKeys[i].maxValue; + for(int i = 0; i < meshBase.numShapeKeys; i++){ + if(meshBase.shapeKeys[i].value < meshBase.shapeKeys[i].minValue) + meshBase.shapeKeys[i].value = meshBase.shapeKeys[i].minValue; + else if(meshBase.shapeKeys[i].value > meshBase.shapeKeys[i].maxValue) + meshBase.shapeKeys[i].value = meshBase.shapeKeys[i].maxValue; - shader->setFloat(shapeKeys[i].value, "shapeKeyFactors[" + to_string(i) + "]"); + shader->setFloat(meshBase.shapeKeys[i].value, "shapeKeyFactors[" + to_string(i) + "]"); } } void Mesh::updateSkeleton(Shader *shader){ skeleton->update(); shader->editShader(Shader::VERTEX_SHADER, 2, "const int numBones=" + to_string(skeleton->getNumBones()) + ";"); - shader->editShader(Shader::VERTEX_SHADER, 3, "const int numVertGroups=" + to_string(numVertexGroups) + ";"); + shader->editShader(Shader::VERTEX_SHADER, 3, "const int numVertGroups=" + to_string(meshBase.numVertexGroups) + ";"); Node *modelNode = skeleton->getRootBone()->getParent(); for(int i = 0; i < skeleton->getNumBones(); i++){ @@ -215,8 +189,8 @@ namespace vb01{ int vertGroupId = -1; - for(int j = 0; j < numVertexGroups; j++) - if(bone->getName() == vertexGroups[j]) + for(int j = 0; j < meshBase.numVertexGroups; j++) + if(bone->getName() == meshBase.vertexGroups[j]) vertGroupId = j; int parentId = -1; @@ -429,15 +403,7 @@ namespace vb01{ void Mesh::render(){ glBindVertexArray(VAO); - - if(!staticVerts){ - glBindBuffer(GL_ARRAY_BUFFER, VBO); - glBufferSubData(GL_ARRAY_BUFFER, 0, 3 * numTris * sizeof(Vertex), vertices); - glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, EBO); - glBufferSubData(GL_ELEMENT_ARRAY_BUFFER, 0, 3 * numTris * sizeof(u32), indices); - } - glPolygonMode(GL_FRONT_AND_BACK, wireframe ? GL_LINE : GL_FILL); - glDrawElements(GL_TRIANGLES, 3 * numTris, GL_UNSIGNED_INT, 0); + glDrawElements(GL_TRIANGLES, 3 * meshBase.numTris, GL_UNSIGNED_INT, 0); } } diff --git a/mesh.h b/mesh.h index 4ffe853..2dc3daf 100755 --- a/mesh.h +++ b/mesh.h @@ -5,6 +5,8 @@ #include "util.h" #include "material.h" #include "animatable.h" +#include "meshData.h" + #include #include @@ -16,22 +18,7 @@ namespace vb01{ class Mesh{ public: - struct ShapeKey : public Animatable{ - std::string name; - float minValue, value, maxValue; - - void animate(float, KeyframeChannel); - }; - - struct Vertex{ - Vector3 pos, norm, tan, biTan; - Vector2 uv; - float weights[4]{0, 0, 0, 0}; - int boneIndices[4]{-1, -1, -1, -1}; - Vector3 shapeKeyOffsets[100]; - }; - - Mesh(Vertex*, u32*, int, std::string *vg = nullptr, int = 0, ShapeKey *sk = nullptr, int = 0, std::string = ""); + Mesh(MeshData); ~Mesh(); void construct(); virtual void update(); @@ -45,22 +32,14 @@ namespace vb01{ inline void setSkeleton(Skeleton *sk){this->skeleton = sk;} inline Node* getNode(){return node;} inline Material* getMaterial(){return material;} - inline std::vector& getMeshes(){return meshes;} inline bool isReflective(){return reflective;} inline bool isCastShadow(){return castShadow;} - inline int getNumVerts(){return 3 * numTris;} - inline Vertex* getVerts(){return vertices;} - inline std::string getName(){return name;} inline Skeleton* getSkeleton(){return skeleton;} - inline std::string* getVertexGroups(){return vertexGroups;} - inline int getNumVertexGroups(){return numVertexGroups;} - inline u32* getIndices(){return indices;} - inline ShapeKey& getShapeKey(int i){return shapeKeys[i];} - inline int getNumShapeKeys(){return numShapeKeys;} inline Texture* getPrefilterMap(){return prefilterMap;} inline Texture* getIrradianceMap(){return irradianceMap;} inline Texture* getPostfilterMap(){return postfilterMap;} inline Texture* getBrdfIntegrationMap(){return brdfIntegrationMap;} + inline MeshData getMeshBase(){return meshBase;} private: void initMesh(); void initFramebuffer(u32&, u32&, int); @@ -82,17 +61,13 @@ namespace vb01{ Material *material = nullptr; Node *node = nullptr; std::vector meshes; - std::string name = ""; Skeleton *skeleton = nullptr; protected: - Mesh(); + Mesh(){} - bool staticVerts = true, castShadow = false, reflect = false, reflective = false, wireframe = false; - Vertex *vertices; - std::string *vertexGroups = nullptr; - ShapeKey *shapeKeys = nullptr; - u32 *indices, VAO, VBO, EBO; - int numTris, numVertexGroups = 0, numShapeKeys = 0; + MeshData meshBase; + bool castShadow = false, reflect = false, reflective = false, wireframe = false; + u32 VAO, VBO, EBO; }; } diff --git a/meshData.cpp b/meshData.cpp new file mode 100644 index 0000000..29d9fdf --- /dev/null +++ b/meshData.cpp @@ -0,0 +1,29 @@ +#include "meshData.h" + +using namespace std; + +namespace vb01{ + void MeshData::ShapeKey::animate(float value, KeyframeChannel keyframeChannel){ + switch(keyframeChannel.type){ + case KeyframeChannel::SHAPE_KEY_MIN: + this->minValue = value; + break; + case KeyframeChannel::SHAPE_KEY_VALUE: + this->value = value; + break; + case KeyframeChannel::SHAPE_KEY_MAX: + this->maxValue = value; + break; + } + } + + MeshData::MeshData(Vertex *vertices, u32 *indices, int numTris, string *vertexGroups, int numVertexGroups, ShapeKey *shapeKeys, int numShapeKeys){ + this->vertices = vertices; + this->indices = indices; + this->numTris = numTris; + this->vertexGroups = vertexGroups; + this->numVertexGroups = numVertexGroups; + this->shapeKeys = shapeKeys; + this->numShapeKeys = numShapeKeys; + } +} diff --git a/meshData.h b/meshData.h new file mode 100644 index 0000000..336dde9 --- /dev/null +++ b/meshData.h @@ -0,0 +1,39 @@ +#ifndef MESH_BASE_H +#define MESH_BASE_H + +#include + +#include "vector.h" +#include "util.h" +#include "keyframeChannel.h" +#include "animatable.h" + +namespace vb01{ + struct MeshData{ + struct ShapeKey : public Animatable{ + std::string name; + float minValue, value, maxValue; + + void animate(float, KeyframeChannel); + }; + + struct Vertex{ + Vector3 pos, norm, tan, biTan; + Vector2 uv; + float weights[4]{0, 0, 0, 0}; + int boneIndices[4]{-1, -1, -1, -1}; + Vector3 shapeKeyOffsets[100]; + }; + + Vertex *vertices; + std::string *vertexGroups = nullptr; + ShapeKey *shapeKeys = nullptr; + u32 *indices, VAO, VBO, EBO; + int numTris, numVertexGroups = 0, numShapeKeys = 0; + + MeshData(){} + MeshData(Vertex*, u32*, int, std::string *vg = nullptr, int = 0, ShapeKey *sk = nullptr, int = 0); + }; +} + +#endif diff --git a/node.h b/node.h index 1b88f76..dda7492 100755 --- a/node.h +++ b/node.h @@ -11,7 +11,6 @@ #include namespace vb01{ - class Mesh; class Model; class Light; class ParticleEmitter; diff --git a/quad.cpp b/quad.cpp index 6e15119..373ea18 100755 --- a/quad.cpp +++ b/quad.cpp @@ -1,24 +1,18 @@ #include "quad.h" namespace vb01{ - Quad::Quad(Vector3 size, bool spatial) : Mesh(){ + Quad::Quad(Vector3 size, bool spatial){ this->spatial = spatial; - this->staticVerts = false; - - int numPolyVerts = 3; - numTris = 2; - indices = new u32[numTris * numPolyVerts]; - vertices = new Vertex[numTris * numPolyVerts]; setSize(size); - Mesh::construct(); } void Quad::setSize(Vector3 size){ this->size = size; - Vertex v1, v2, v3, v4, v5, v6; + MeshData::Vertex v1, v2, v3, v4, v5, v6; + if(spatial){ v1.pos = Vector3(size.x / 2, size.y / 2, 0); v2.pos = Vector3(-size.x / 2, size.y / 2, 0); @@ -35,6 +29,7 @@ namespace vb01{ v5.pos = Vector3(size.x, size.y, 0); v6.pos = Vector3(size.x, 0, 0); } + v1.norm = Vector3(0, 0, -1); v1.uv = Vector2(1, 1); @@ -52,7 +47,9 @@ namespace vb01{ v6.norm = Vector3(0, 0, -1); v6.uv = Vector2(1, 1); - + + int numTris = 2; + u32 *indices = new u32[numTris * 3]; indices[0] = 0; indices[1] = 1; indices[2] = 2; @@ -60,12 +57,14 @@ namespace vb01{ indices[4] = 4; indices[5] = 5; + MeshData::Vertex *vertices = new MeshData::Vertex[numTris * 3]; vertices[0] = v1; vertices[1] = v2; vertices[2] = v3; vertices[3] = v4; vertices[4] = v5; vertices[5] = v6; - } + meshBase = MeshData(vertices, indices, numTris * 3); + } } diff --git a/ray.cpp b/ray.cpp index fa2bd93..dbb9048 100644 --- a/ray.cpp +++ b/ray.cpp @@ -9,6 +9,7 @@ using namespace std; namespace vb01{ void Ray::retrieveCollisions(Vector3 rayPos, Vector3 rayDir, Node *node, std::vector &results, const float rayLength){ castRay(rayPos, rayDir, node, results, rayLength); + for(Node *c : node->getChildren()) retrieveCollisions(rayPos, rayDir, c, results, rayLength); } @@ -16,24 +17,29 @@ namespace vb01{ void Ray::castRay(Vector3 rayPos, Vector3 rayDir, Node *node, vector &results, float rayLength){ Vector3 pos = node->localToGlobalPosition(Vector3::VEC_ZERO); Quaternion rot = node->localToGlobalOrientation(Quaternion::QUAT_W); + for(Mesh *m : node->getMeshes()){ - const int numVerts = m->getNumVerts(); - Mesh::Vertex *vertices = m->getVerts(); - u32 *indices = m->getIndices(); + const int numVerts = m->getMeshBase().numTris * 3; + MeshData::Vertex *vertices = m->getMeshBase().vertices; + u32 *indices = m->getMeshBase().indices; for(int i = 0; i < numVerts / 3; i++){ Vector3 pointA = pos + rot * vertices[indices[i * 3]].pos, pointB = pos + rot * vertices[indices[i * 3 + 1]].pos, pointC = pos + rot * vertices[indices[i * 3 + 2]].pos; Vector3 hypVec = pointA - rayPos; Vector3 perpVec = (pointB - pointA).cross(pointC - pointA); float a1 = hypVec.norm().getAngleBetween(perpVec.norm()); + if(a1 > PI / 2){ a1 = PI - a1; perpVec = -perpVec; } + float perpLine = hypVec.getLength() * cos(a1); float a2 = perpVec.norm().getAngleBetween(rayDir.norm()); + if(a2 <= PI / 2){ float distance = perpLine / cos(a2); + if((distance <= rayLength && rayLength != .0) || rayLength == .0){ Vector3 contactPoint = rayPos + rayDir.norm() * distance; float angleA = (pointB - pointA).norm().getAngleBetween((pointC - pointA).norm()); @@ -45,6 +51,7 @@ namespace vb01{ bool withinBisecA = (contactPoint - pointA).norm().getAngleBetween(bisecAVec.norm()) <= angleA / 2; bool withinBisecB = (contactPoint - pointB).norm().getAngleBetween(bisecBVec.norm()) <= angleB / 2; bool withinBisecC = (contactPoint - pointC).norm().getAngleBetween(bisecCVec.norm()) <= angleC / 2; + if(withinBisecA && withinBisecB && withinBisecC){ CollisionResult result; result.pos = contactPoint;