mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-25 19:55:07 +02:00
Adding BulletUtil.h with tests.
This commit is contained in:
parent
57e972d876
commit
2734afcf9a
4 changed files with 170 additions and 0 deletions
40
libraries/physics/src/BulletUtil.h
Normal file
40
libraries/physics/src/BulletUtil.h
Normal file
|
@ -0,0 +1,40 @@
|
|||
//
|
||||
// BulletUtil.h
|
||||
// libraries/physcis/src
|
||||
//
|
||||
// Created by Andrew Meadows 2014.11.02
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_BulletUtil_h
|
||||
#define hifi_BulletUtil_h
|
||||
|
||||
#include <btBulletDynamicsCommon.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
|
||||
inline void bulletToGLM(const btVector3& b, glm::vec3& g) {
|
||||
g = glm::vec3(b.getX(), b.getY(), b.getZ());
|
||||
}
|
||||
|
||||
inline void bulletToGLM(const btQuaternion& b, glm::quat& g) {
|
||||
g.x = b.getX();
|
||||
g.y = b.getY();
|
||||
g.z = b.getZ();
|
||||
g.w = b.getW();
|
||||
}
|
||||
|
||||
inline void glmToBullet(const glm::vec3& g, btVector3& b) {
|
||||
b.setX(g.x);
|
||||
b.setY(g.y);
|
||||
b.setZ(g.z);
|
||||
}
|
||||
|
||||
inline void glmToBullet(const glm::quat& g, btQuaternion& b) {
|
||||
b = btQuaternion(g.x, g.y, g.z, g.w);
|
||||
}
|
||||
|
||||
#endif // hifi_BulletUtil_h
|
107
tests/physics/src/BulletUtilTests.cpp
Normal file
107
tests/physics/src/BulletUtilTests.cpp
Normal file
|
@ -0,0 +1,107 @@
|
|||
//
|
||||
// BulletUtilTests.cpp
|
||||
// tests/physics/src
|
||||
//
|
||||
// Created by Andrew Meadows on 2014.11.02
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
|
||||
#include <BulletUtil.h>
|
||||
#include <SharedUtil.h>
|
||||
|
||||
#include "BulletUtilTests.h"
|
||||
|
||||
void BulletUtilTests::fromBulletToGLM() {
|
||||
btVector3 bV(1.23f, 4.56f, 7.89f);
|
||||
glm::vec3 gV;
|
||||
bulletToGLM(bV, gV);
|
||||
if (gV.x != bV.getX()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.x = " << bV.getX() << " != glm.x = " << gV.x << std::endl;
|
||||
}
|
||||
if (gV.y != bV.getY()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.y = " << bV.getY() << " != glm.y = " << gV.y << std::endl;
|
||||
}
|
||||
if (gV.z != bV.getZ()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.z = " << bV.getZ() << " != glm.z = " << gV.z << std::endl;
|
||||
}
|
||||
|
||||
float angle = 0.317f * PI;
|
||||
btVector3 axis(1.23f, 2.34f, 3.45f);
|
||||
axis.normalize();
|
||||
btQuaternion bQ(axis, angle);
|
||||
|
||||
glm::quat gQ;
|
||||
bulletToGLM(bQ, gQ);
|
||||
if (gQ.x != bQ.getX()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.x = " << bQ.getX() << " != glm.x = " << gQ.x << std::endl;
|
||||
}
|
||||
if (gQ.y != bQ.getY()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.y = " << bQ.getY() << " != glm.y = " << gQ.y << std::endl;
|
||||
}
|
||||
if (gQ.z != bQ.getZ()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.z = " << bQ.getZ() << " != glm.z = " << gQ.z << std::endl;
|
||||
}
|
||||
if (gQ.w != bQ.getW()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch bullet.w = " << bQ.getW() << " != glm.w = " << gQ.w << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void BulletUtilTests::fromGLMToBullet() {
|
||||
glm::vec3 gV(1.23f, 4.56f, 7.89f);
|
||||
btVector3 bV;
|
||||
glmToBullet(gV, bV);
|
||||
if (gV.x != bV.getX()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.x = " << gV.x << " != bullet.x = " << bV.getX() << std::endl;
|
||||
}
|
||||
if (gV.y != bV.getY()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.y = " << gV.y << " != bullet.y = " << bV.getY() << std::endl;
|
||||
}
|
||||
if (gV.z != bV.getZ()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.z = " << gV.z << " != bullet.z = " << bV.getZ() << std::endl;
|
||||
}
|
||||
|
||||
float angle = 0.317f * PI;
|
||||
btVector3 axis(1.23f, 2.34f, 3.45f);
|
||||
axis.normalize();
|
||||
btQuaternion bQ(axis, angle);
|
||||
|
||||
glm::quat gQ;
|
||||
bulletToGLM(bQ, gQ);
|
||||
if (gQ.x != bQ.getX()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.x = " << gQ.x << " != bullet.x = " << bQ.getX() << std::endl;
|
||||
}
|
||||
if (gQ.y != bQ.getY()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.y = " << gQ.y << " != bullet.y = " << bQ.getY() << std::endl;
|
||||
}
|
||||
if (gQ.z != bQ.getZ()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.z = " << gQ.z << " != bullet.z = " << bQ.getZ() << std::endl;
|
||||
}
|
||||
if (gQ.w != bQ.getW()) {
|
||||
std::cout << __FILE__ << ":" << __LINE__
|
||||
<< " ERROR: x mismatch glm.w = " << gQ.w << " != bullet.w = " << bQ.getW() << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void BulletUtilTests::runAllTests() {
|
||||
fromBulletToGLM();
|
||||
fromGLMToBullet();
|
||||
}
|
||||
|
21
tests/physics/src/BulletUtilTests.h
Normal file
21
tests/physics/src/BulletUtilTests.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
//
|
||||
// BulletUtilTests.h
|
||||
// tests/physics/src
|
||||
//
|
||||
// Created by Andrew Meadows on 2014.11.02
|
||||
// Copyright 2014 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
#ifndef hifi_BulletUtilTests_h
|
||||
#define hifi_BulletUtilTests_h
|
||||
|
||||
namespace BulletUtilTests {
|
||||
void fromBulletToGLM();
|
||||
void fromGLMToBullet();
|
||||
void runAllTests();
|
||||
}
|
||||
|
||||
#endif // hifi_BulletUtilTests_h
|
|
@ -12,11 +12,13 @@
|
|||
//#include "VerletShapeTests.h"
|
||||
#include "ShapeInfoTests.h"
|
||||
#include "ShapeManagerTests.h"
|
||||
#include "BulletUtilTests.h"
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
//ShapeColliderTests::runAllTests();
|
||||
//VerletShapeTests::runAllTests();
|
||||
ShapeInfoTests::runAllTests();
|
||||
ShapeManagerTests::runAllTests();
|
||||
BulletUtilTests::runAllTests();
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue