From bae1b7a9ccbfbbeab63a8c1df672dbcaa6fd64f9 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 12 Sep 2020 13:26:34 +0300 Subject: [PATCH] bone test --- CMakeLists.txt | 2 +- boneTest.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ boneTest.h | 28 ++++++++++++++++++++++++++++ main.cpp | 2 ++ mesh.cpp | 4 ++-- 5 files changed, 80 insertions(+), 3 deletions(-) create mode 100644 boneTest.cpp create mode 100644 boneTest.h diff --git a/CMakeLists.txt b/CMakeLists.txt index bdb5bce..819ecbf 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,7 @@ set(anim animationController.cpp animationChannel.cpp animation.cpp) set(armature skeleton.cpp bone.cpp) set(library ${render} ${math} ${model} ${utils} ${gui} ${armature} ${anim}) -set(test cameraTest.cpp nodeTest.cpp) +set(test cameraTest.cpp nodeTest.cpp boneTest.cpp) add_library(vb01 SHARED ${library}) target_link_libraries(vb01 glfw) diff --git a/boneTest.cpp b/boneTest.cpp new file mode 100644 index 0000000..0ee8023 --- /dev/null +++ b/boneTest.cpp @@ -0,0 +1,47 @@ +#include "boneTest.h" +#include "model.h" +#include "root.h" +#include "skeleton.h" +#include "mesh.h" + +#include + +using namespace std; + +namespace vb01{ + BoneTest::BoneTest(){ + } + + void BoneTest::setUp(){ + string PATH="/home/dominykas/c++/v/"; + + Root *root = Root::getSingleton(); + root->setBasePath("../"); + rootNode = root->getRootNode(); + model = new Model(PATH + "../vb01/test.vb"); + Material *glMat=new Material(); + glMat->setTexturingEnabled(true); + glMat->setLightingEnabled(false); + glMat->addDiffuseMap(PATH+"defaultTexture.jpg"); + //model->setMaterial(glMat); + rootNode->attachChild(model); + } + + void BoneTest::tearDown(){ + rootNode->dettachChild(model); + delete model; + } + + void BoneTest::testGetModelSpacePos(){ + float eps = .0001; + + int numChildren = model->getNumChildren(); + Skeleton *skeleton = model->getChild(numChildren - 1)->getMesh(0)->getSkeleton(); + Bone *bone = skeleton->getBone("ik"); + Vector3 initModelPos = bone->getModelSpacePos(); + model->setPosition(Vector3(1, 2, 3)); + Vector3 deltaModelPos = bone->getModelSpacePos(); + + CPPUNIT_ASSERT(initModelPos.getDistanceFrom(deltaModelPos) <= eps); + } +} diff --git a/boneTest.h b/boneTest.h new file mode 100644 index 0000000..af05131 --- /dev/null +++ b/boneTest.h @@ -0,0 +1,28 @@ +#ifndef BONE_TEST_H +#define BONE_TEST_H + +#include +#include + +namespace vb01{ + class Model; + class Node; + + class BoneTest : public CppUnit::TestFixture{ + CPPUNIT_TEST_SUITE(BoneTest); + CPPUNIT_TEST(testGetModelSpacePos); + CPPUNIT_TEST_SUITE_END(); + + public: + BoneTest(); + void setUp(); + void tearDown(); + private: + void testGetModelSpacePos(); + + Model *model = nullptr; + Node *rootNode = nullptr; + }; +} + +#endif diff --git a/main.cpp b/main.cpp index 9edc8f3..fffb9e1 100755 --- a/main.cpp +++ b/main.cpp @@ -5,6 +5,7 @@ #include "cameraTest.h" #include "nodeTest.h" +#include "boneTest.h" using namespace CppUnit; using namespace vb01; @@ -13,6 +14,7 @@ int main(){ TextUi::TestRunner runner; runner.addTest(CameraTest::suite()); runner.addTest(NodeTest::suite()); + runner.addTest(BoneTest::suite()); runner.run(); return 0; } diff --git a/mesh.cpp b/mesh.cpp index a47a723..8142b6f 100755 --- a/mesh.cpp +++ b/mesh.cpp @@ -52,6 +52,8 @@ namespace vb01{ void Mesh::initFramebuffer(){ int width = Root::getSingleton()->getWidth(); + /* + */ u32 RBO; string basePath = "../../vb01/depthMap."; environmentShader = new Shader(basePath + "vert", basePath + "frag", basePath + "geo"); @@ -61,12 +63,10 @@ namespace vb01{ glBindFramebuffer(GL_FRAMEBUFFER, environmentBuffer); glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, *(environmentMap->getTexture()), 0); - /* glGenRenderbuffers(1,&RBO); glBindRenderbuffer(GL_RENDERBUFFER,RBO); glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH24_STENCIL8,width,width); glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_STENCIL_ATTACHMENT,GL_RENDERBUFFER,RBO); - */ if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) cout<<"Not complete\n";