[Orxonox-commit 5527] r10190 - code/trunk/src/libraries/tools
landauf at orxonox.net
landauf at orxonox.net
Sun Jan 11 18:21:52 CET 2015
Author: landauf
Date: 2015-01-11 18:21:51 +0100 (Sun, 11 Jan 2015)
New Revision: 10190
Added:
code/trunk/src/libraries/tools/BulletDebugDrawer.cc
code/trunk/src/libraries/tools/BulletDebugDrawer.h
code/trunk/src/libraries/tools/DebugDrawer.cc
code/trunk/src/libraries/tools/DebugDrawer.h
code/trunk/src/libraries/tools/IcoSphere.cc
code/trunk/src/libraries/tools/IcoSphere.h
code/trunk/src/libraries/tools/OgreBulletUtils.h
Modified:
code/trunk/src/libraries/tools/CMakeLists.txt
code/trunk/src/libraries/tools/ToolsPrereqs.h
Log:
added utility to visualize collision shapes
Added: code/trunk/src/libraries/tools/BulletDebugDrawer.cc
===================================================================
--- code/trunk/src/libraries/tools/BulletDebugDrawer.cc (rev 0)
+++ code/trunk/src/libraries/tools/BulletDebugDrawer.cc 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,155 @@
+/**
+ * Originally from http://www.ogre3d.org/tikiwiki/BulletDebugDrawer&structure=Cookbook
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau by using DebugDrawer and Orxonox specific utilities (e.g. output).
+ */
+
+#include "BulletDebugDrawer.h"
+#include "OgreBulletUtils.h"
+
+#include <OgreRoot.h>
+#include <OgreManualObject.h>
+#include <OgreMaterialManager.h>
+#include <OgreSceneManager.h>
+
+#include "util/Output.h"
+#include "DebugDrawer.h"
+
+namespace orxonox
+{
+ BulletDebugDrawer::BulletDebugDrawer(Ogre::SceneManager* sceneManager)
+ {
+ this->drawer = new DebugDrawer(sceneManager, 0.5f);
+
+ mContactPoints = &mContactPoints1;
+ //mLines->estimateVertexCount(100000);
+ //mLines->estimateIndexCount(0);
+
+ static const char* matName = "OgreBulletCollisionsDebugDefault";
+ Ogre::MaterialPtr mtl = Ogre::MaterialManager::getSingleton().getDefaultSettings()->clone(matName);
+ mtl->setReceiveShadows(false);
+ mtl->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
+ mtl->setDepthBias(0.1, 0);
+ Ogre::TextureUnitState* tu = mtl->getTechnique(0)->getPass(0)->createTextureUnitState();
+ tu->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_DIFFUSE);
+ mtl->getTechnique(0)->setLightingEnabled(false);
+ //mtl->getTechnique(0)->setSelfIllumination(Ogre::ColourValue::White);
+
+ mDebugMode = (DebugDrawModes) DBG_DrawWireframe;
+ Ogre::Root::getSingleton().addFrameListener(this);
+ }
+
+ BulletDebugDrawer::~BulletDebugDrawer()
+ {
+ Ogre::Root::getSingleton().removeFrameListener(this);
+ delete this->drawer;
+ }
+
+ void BulletDebugDrawer::drawLine(const btVector3& from, const btVector3& to, const btVector3& color)
+ {
+ this->drawer->drawLine(vector3(from), vector3(to), colour(color, 1.0f));
+ }
+
+// void BulletDebugDrawer::drawTriangle(const btVector3& v0, const btVector3& v1, const btVector3& v2, const btVector3& color, btScalar alpha)
+// {
+// // TODO
+// }
+
+ void BulletDebugDrawer::drawSphere(const btVector3& p, btScalar radius, const btVector3& color)
+ {
+ this->drawer->drawSphere(vector3(p), radius, colour(color, 1.0f), true);
+ }
+
+ void BulletDebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
+ {
+ this->drawSphere(transform.getOrigin(), radius, color);
+ }
+
+ void BulletDebugDrawer::drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)
+ {
+ Ogre::Vector3* corners = new Ogre::Vector3[8];
+ corners[0] = Ogre::Vector3(bbMin[0], bbMin[1], bbMin[2]);
+ corners[1] = Ogre::Vector3(bbMin[0], bbMax[1], bbMin[2]);
+ corners[2] = Ogre::Vector3(bbMax[0], bbMax[1], bbMin[2]);
+ corners[3] = Ogre::Vector3(bbMax[0], bbMin[1], bbMin[2]);
+ corners[4] = Ogre::Vector3(bbMax[0], bbMax[1], bbMax[2]);
+ corners[5] = Ogre::Vector3(bbMin[0], bbMax[1], bbMax[2]);
+ corners[6] = Ogre::Vector3(bbMin[0], bbMin[1], bbMax[2]);
+ corners[7] = Ogre::Vector3(bbMax[0], bbMin[1], bbMax[2]);
+ this->drawer->drawCuboid(corners, colour(color, 1.0f), true);
+ }
+
+ void BulletDebugDrawer::drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color)
+ {
+ Ogre::Vector3* corners = new Ogre::Vector3[8];
+ corners[0] = Ogre::Vector3(trans * btVector3(bbMin[0], bbMin[1], bbMin[2]));
+ corners[1] = Ogre::Vector3(trans * btVector3(bbMin[0], bbMax[1], bbMin[2]));
+ corners[2] = Ogre::Vector3(trans * btVector3(bbMax[0], bbMax[1], bbMin[2]));
+ corners[3] = Ogre::Vector3(trans * btVector3(bbMax[0], bbMin[1], bbMin[2]));
+ corners[4] = Ogre::Vector3(trans * btVector3(bbMax[0], bbMax[1], bbMax[2]));
+ corners[5] = Ogre::Vector3(trans * btVector3(bbMin[0], bbMax[1], bbMax[2]));
+ corners[6] = Ogre::Vector3(trans * btVector3(bbMin[0], bbMin[1], bbMax[2]));
+ corners[7] = Ogre::Vector3(trans * btVector3(bbMax[0], bbMin[1], bbMax[2]));
+ this->drawer->drawCuboid(corners, colour(color, 1.0f), true);
+ }
+
+ void BulletDebugDrawer::drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color)
+ {
+ mContactPoints->resize(mContactPoints->size() + 1);
+ ContactPoint p = mContactPoints->back();
+ p.from = vector3(PointOnB);
+ p.to = p.from + vector3(normalOnB) * distance;
+ p.dieTime = Ogre::Root::getSingleton().getTimer()->getMilliseconds() + lifeTime;
+ p.color.r = color.x();
+ p.color.g = color.y();
+ p.color.b = color.z();
+ }
+
+ bool BulletDebugDrawer::frameStarted(const Ogre::FrameEvent& evt)
+ {
+ size_t now = Ogre::Root::getSingleton().getTimer()->getMilliseconds();
+ std::vector<ContactPoint>* newCP = mContactPoints == &mContactPoints1 ? &mContactPoints2 : &mContactPoints1;
+ for (std::vector<ContactPoint>::iterator i = mContactPoints->begin(); i < mContactPoints->end(); i++ )
+ {
+ ContactPoint& cp = *i;
+ this->drawer->drawLine(cp.from, cp.to, cp.color);
+ if (now <= cp.dieTime)
+ newCP->push_back(cp);
+ }
+ mContactPoints->clear();
+ mContactPoints = newCP;
+
+ // Right before the frame is rendered, call DebugDrawer::build().
+ this->drawer->build();
+ return true;
+ }
+
+ bool BulletDebugDrawer::frameEnded(const Ogre::FrameEvent& evt)
+ {
+ // After the frame is rendered, call DebugDrawer::clear()
+ this->drawer->clear();
+ return true;
+ }
+
+ void BulletDebugDrawer::reportErrorWarning(const char* warningString)
+ {
+ orxout(internal_error) << warningString << endl;
+ Ogre::LogManager::getSingleton().getDefaultLog()->logMessage(warningString);
+ }
+
+ void BulletDebugDrawer::draw3dText(const btVector3& location, const char* textString)
+ {
+
+ }
+
+ void BulletDebugDrawer::setDebugMode(int debugMode)
+ {
+ mDebugMode = (DebugDrawModes) debugMode;
+ }
+
+ int BulletDebugDrawer::getDebugMode() const
+ {
+ return mDebugMode;
+ }
+}
Added: code/trunk/src/libraries/tools/BulletDebugDrawer.h
===================================================================
--- code/trunk/src/libraries/tools/BulletDebugDrawer.h (rev 0)
+++ code/trunk/src/libraries/tools/BulletDebugDrawer.h 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,61 @@
+/**
+ * Originally from http://www.ogre3d.org/tikiwiki/BulletDebugDrawer&structure=Cookbook
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau by using DebugDrawer and Orxonox specific utilities (e.g. output).
+ */
+
+#ifndef _BulletDebugDrawer_H__
+#define _BulletDebugDrawer_H__
+
+#include "tools/ToolsPrereqs.h"
+
+#include <btBulletCollisionCommon.h>
+
+namespace orxonox
+{
+ class _ToolsExport BulletDebugDrawer : public btIDebugDraw, public Ogre::FrameListener
+ {
+ public:
+ BulletDebugDrawer(Ogre::SceneManager* sceneManager);
+ ~BulletDebugDrawer();
+ virtual void drawLine(const btVector3& from, const btVector3& to, const btVector3& color);
+// virtual void drawTriangle(const btVector3& v0, const btVector3& v1, const btVector3& v2, const btVector3& color, btScalar);
+ virtual void drawSphere (const btVector3& p, btScalar radius, const btVector3& color);
+ virtual void drawSphere(btScalar radius, const btTransform& transform, const btVector3& color);
+ virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color);
+ virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color);
+// virtual void drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color);
+// virtual void drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color);
+// virtual void drawPlane(const btVector3& planeNormal, btScalar planeConst, const btTransform& transform, const btVector3& color);
+
+ virtual void drawContactPoint(const btVector3& PointOnB, const btVector3& normalOnB, btScalar distance, int lifeTime, const btVector3& color);
+
+ virtual void reportErrorWarning(const char* warningString);
+ virtual void draw3dText(const btVector3& location, const char* textString);
+
+ virtual void setDebugMode(int debugMode);
+ virtual int getDebugMode() const;
+
+ protected:
+ bool frameStarted(const Ogre::FrameEvent& evt);
+ bool frameEnded(const Ogre::FrameEvent& evt);
+
+ private:
+ struct ContactPoint
+ {
+ Ogre::Vector3 from;
+ Ogre::Vector3 to;
+ Ogre::ColourValue color;
+ size_t dieTime;
+ };
+
+ DebugDrawer* drawer;
+ DebugDrawModes mDebugMode;
+ std::vector<ContactPoint>* mContactPoints;
+ std::vector<ContactPoint> mContactPoints1;
+ std::vector<ContactPoint> mContactPoints2;
+ };
+}
+
+#endif /* _BulletDebugDrawer_H__ */
Modified: code/trunk/src/libraries/tools/CMakeLists.txt
===================================================================
--- code/trunk/src/libraries/tools/CMakeLists.txt 2015-01-11 14:40:41 UTC (rev 10189)
+++ code/trunk/src/libraries/tools/CMakeLists.txt 2015-01-11 17:21:51 UTC (rev 10190)
@@ -10,8 +10,11 @@
BUILD_UNIT OgreBuildUnit.cc
BillboardSet.cc
+ BulletDebugDrawer.cc
+ DebugDrawer.cc
DynamicLines.cc
DynamicRenderable.cc
+ IcoSphere.cc
Mesh.cc
ParticleInterface.cc
Shader.cc
@@ -28,6 +31,7 @@
${Boost_FILESYSTEM_LIBRARY}
${Boost_SYSTEM_LIBRARY} # Filesystem dependency
tinyxml_orxonox
+ bullet_orxonox
util
core
SOURCE_FILES
Added: code/trunk/src/libraries/tools/DebugDrawer.cc
===================================================================
--- code/trunk/src/libraries/tools/DebugDrawer.cc (rev 0)
+++ code/trunk/src/libraries/tools/DebugDrawer.cc 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,445 @@
+/**
+ * Copy-pasted from
+ * - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src
+ * - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class
+ *
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau
+ */
+
+#include "DebugDrawer.h"
+
+#include <OgreSceneManager.h>
+#include <OgreRenderQueue.h>
+#include <OgreManualObject.h>
+#include <OgreAxisAlignedBox.h>
+
+#include "util/Output.h"
+
+#define DEFAULT_ICOSPHERE_RECURSION_LEVEL 1
+
+namespace orxonox
+{
+ DebugDrawer::DebugDrawer(Ogre::SceneManager *_sceneManager, float _fillAlpha) :
+ sceneManager(_sceneManager), fillAlpha(_fillAlpha), manualObject(0), linesIndex(0), trianglesIndex(0)
+ {
+ initialise();
+ }
+
+ DebugDrawer::~DebugDrawer()
+ {
+ shutdown();
+ }
+
+ void DebugDrawer::initialise()
+ {
+ manualObject = sceneManager->createManualObject("debug_object");
+ sceneManager->getRootSceneNode()->createChildSceneNode("debug_object")->attachObject(manualObject);
+ manualObject->setDynamic(true);
+
+ icoSphere0.create(0);
+ icoSphere1.create(1);
+ icoSphere2.create(2);
+ icoSphere3.create(3);
+ icoSphere4.create(4);
+
+ manualObject->begin("debug_draw", Ogre::RenderOperation::OT_LINE_LIST);
+ manualObject->position(Ogre::Vector3::ZERO);
+ manualObject->colour(Ogre::ColourValue::ZERO);
+ manualObject->index(0);
+ manualObject->end();
+ manualObject->begin("debug_draw", Ogre::RenderOperation::OT_TRIANGLE_LIST);
+ manualObject->position(Ogre::Vector3::ZERO);
+ manualObject->colour(Ogre::ColourValue::ZERO);
+ manualObject->index(0);
+ manualObject->end();
+
+ linesIndex = trianglesIndex = 0;
+ }
+
+ void DebugDrawer::shutdown()
+ {
+ sceneManager->destroySceneNode("debug_object");
+ sceneManager->destroyManualObject(manualObject);
+ }
+
+ void DebugDrawer::buildLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour, float alpha)
+ {
+ int i = addLineVertex(start, Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(end, Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addLineIndices(i, i + 1);
+ }
+
+ void DebugDrawer::buildQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = addLineVertex(vertices[0], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(vertices[1], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(vertices[2], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(vertices[3], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ for (int i = 0; i < 4; ++i)
+ addLineIndices(index + i, index + ((i + 1) % 4));
+ }
+
+ void DebugDrawer::buildCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = linesIndex;
+ float increment = 2 * Ogre::Math::PI / segmentsCount;
+ float angle = 0.0f;
+
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addLineVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ for (int i = 0; i < segmentsCount; i++)
+ addLineIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index);
+ }
+
+ void DebugDrawer::buildFilledCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = trianglesIndex;
+ float increment = 2 * Ogre::Math::PI / segmentsCount;
+ float angle = 0.0f;
+
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addTriangleVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ addTriangleVertex(centre, Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ for (int i = 0; i < segmentsCount; i++)
+ addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount);
+ }
+
+ void DebugDrawer::buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = linesIndex;
+ float increment = 2 * Ogre::Math::PI / segmentsCount;
+ float angle = 0.0f;
+
+ // Top circle
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addLineVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y + height / 2, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ angle = 0.0f;
+
+ // Bottom circle
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addLineVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y - height / 2, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addLineIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index);
+ addLineIndices(segmentsCount + index + i, i + 1 < segmentsCount ? segmentsCount + index + i + 1 : segmentsCount + index);
+ addLineIndices(index + i, segmentsCount + index + i);
+ }
+ }
+
+ void DebugDrawer::buildFilledCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour,
+ float alpha)
+ {
+ int index = trianglesIndex;
+ float increment = 2 * Ogre::Math::PI / segmentsCount;
+ float angle = 0.0f;
+
+ // Top circle
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addTriangleVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y + height / 2, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ addTriangleVertex(Ogre::Vector3(centre.x, centre.y + height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ angle = 0.0f;
+
+ // Bottom circle
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addTriangleVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y - height / 2, centre.z + radius * Ogre::Math::Sin(angle)),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ angle += increment;
+ }
+
+ addTriangleVertex(Ogre::Vector3(centre.x, centre.y - height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ for (int i = 0; i < segmentsCount; i++)
+ {
+ addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount);
+
+ addTriangleIndices(i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index,
+ (segmentsCount + 1) + index + segmentsCount, (segmentsCount + 1) + index + i);
+
+ addQuadIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index,
+ i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index, (segmentsCount + 1) + index + i);
+ }
+ }
+
+ void DebugDrawer::buildCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = addLineVertex(vertices[0], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ for (int i = 1; i < 8; ++i)
+ addLineVertex(vertices[i], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ for (int i = 0; i < 4; ++i)
+ addLineIndices(index + i, index + ((i + 1) % 4));
+ for (int i = 4; i < 8; ++i)
+ addLineIndices(index + i, i == 7 ? index + 4 : index + i + 1);
+ addLineIndices(index + 1, index + 5);
+ addLineIndices(index + 2, index + 4);
+ addLineIndices(index, index + 6);
+ addLineIndices(index + 3, index + 7);
+ }
+
+ void DebugDrawer::buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = addTriangleVertex(vertices[0], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ for (int i = 1; i < 8; ++i)
+ addTriangleVertex(vertices[i], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addQuadIndices(index, index + 1, index + 2, index + 3);
+ addQuadIndices(index + 4, index + 5, index + 6, index + 7);
+
+ addQuadIndices(index + 1, index + 5, index + 4, index + 2);
+ addQuadIndices(index, index + 3, index + 7, index + 6);
+
+ addQuadIndices(index + 1, index, index + 6, index + 5);
+ addQuadIndices(index + 4, index + 7, index + 3, index + 2);
+ }
+
+ void DebugDrawer::buildFilledQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = addTriangleVertex(vertices[0], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(vertices[1], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(vertices[2], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(vertices[3], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addQuadIndices(index, index + 1, index + 2, index + 3);
+ }
+
+ void DebugDrawer::buildFilledTriangle(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = addTriangleVertex(vertices[0], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(vertices[1], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(vertices[2], Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addTriangleIndices(index, index + 1, index + 2);
+ }
+
+ void DebugDrawer::buildTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = linesIndex;
+
+ // Distance from the centre
+ float bottomDistance = scale * 0.2f;
+ float topDistance = scale * 0.62f;
+ float frontDistance = scale * 0.289f;
+ float backDistance = scale * 0.577f;
+ float leftRightDistance = scale * 0.5f;
+
+ addLineVertex(Ogre::Vector3(centre.x, centre.y + topDistance, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(Ogre::Vector3(centre.x, centre.y - bottomDistance, centre.z + frontDistance), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(Ogre::Vector3(centre.x + leftRightDistance, centre.y - bottomDistance, centre.z - backDistance),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addLineVertex(Ogre::Vector3(centre.x - leftRightDistance, centre.y - bottomDistance, centre.z - backDistance),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addLineIndices(index, index + 1);
+ addLineIndices(index, index + 2);
+ addLineIndices(index, index + 3);
+
+ addLineIndices(index + 1, index + 2);
+ addLineIndices(index + 2, index + 3);
+ addLineIndices(index + 3, index + 1);
+ }
+
+ void DebugDrawer::buildFilledTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = trianglesIndex;
+
+ // Distance from the centre
+ float bottomDistance = scale * 0.2f;
+ float topDistance = scale * 0.62f;
+ float frontDistance = scale * 0.289f;
+ float backDistance = scale * 0.577f;
+ float leftRightDistance = scale * 0.5f;
+
+ addTriangleVertex(Ogre::Vector3(centre.x, centre.y + topDistance, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(Ogre::Vector3(centre.x, centre.y - bottomDistance, centre.z + frontDistance), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(Ogre::Vector3(centre.x + leftRightDistance, centre.y - bottomDistance, centre.z - backDistance),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ addTriangleVertex(Ogre::Vector3(centre.x - leftRightDistance, centre.y - bottomDistance, centre.z - backDistance),
+ Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
+ addTriangleIndices(index, index + 1, index + 2);
+ addTriangleIndices(index, index + 2, index + 3);
+ addTriangleIndices(index, index + 3, index + 1);
+
+ addTriangleIndices(index + 1, index + 3, index + 2);
+ }
+
+ void DebugDrawer::drawLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour)
+ {
+ buildLine(start, end, colour);
+ }
+
+ void DebugDrawer::drawCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ buildCircle(centre, radius, segmentsCount, colour);
+ if (isFilled)
+ buildFilledCircle(centre, radius, segmentsCount, colour, fillAlpha);
+ }
+
+ void DebugDrawer::drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ buildCylinder(centre, radius, segmentsCount, height, colour);
+ if (isFilled)
+ buildFilledCylinder(centre, radius, segmentsCount, height, colour, fillAlpha);
+ }
+
+ void DebugDrawer::drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ buildQuad(vertices, colour);
+ if (isFilled)
+ buildFilledQuad(vertices, colour, fillAlpha);
+ }
+
+ void DebugDrawer::drawCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ buildCuboid(vertices, colour);
+ if (isFilled)
+ buildFilledCuboid(vertices, colour, fillAlpha);
+ }
+
+ void DebugDrawer::drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ const IcoSphere& sphere = this->getIcoSphere(radius);
+
+ int baseIndex = linesIndex;
+ linesIndex += sphere.addToVertices(&lineVertices, centre, colour, radius);
+ sphere.addToLineIndices(baseIndex, &lineIndices);
+
+ if (isFilled)
+ {
+ baseIndex = trianglesIndex;
+ trianglesIndex += sphere.addToVertices(&triangleVertices, centre, Ogre::ColourValue(colour.r, colour.g, colour.b, fillAlpha), radius);
+ sphere.addToTriangleIndices(baseIndex, &triangleIndices);
+ }
+ }
+
+ const IcoSphere& DebugDrawer::getIcoSphere(float radius) const
+ {
+ if (radius < 50)
+ return this->icoSphere0;
+ else if (radius < 500)
+ return this->icoSphere1;
+ else if (radius < 5000)
+ return this->icoSphere2;
+ else if (radius < 50000)
+ return this->icoSphere3;
+ else
+ return this->icoSphere4;
+ }
+
+ void DebugDrawer::drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ buildTetrahedron(centre, scale, colour);
+ if (isFilled)
+ buildFilledTetrahedron(centre, scale, colour, fillAlpha);
+ }
+
+ void DebugDrawer::build()
+ {
+ manualObject->beginUpdate(0);
+ if (lineVertices.size() > 0 && isEnabled)
+ {
+ manualObject->estimateVertexCount(lineVertices.size());
+ manualObject->estimateIndexCount(lineIndices.size());
+ for (std::list<VertexPair>::iterator i = lineVertices.begin(); i != lineVertices.end(); i++)
+ {
+ manualObject->position(i->first);
+ manualObject->colour(i->second);
+ }
+ for (std::list<int>::iterator i = lineIndices.begin(); i != lineIndices.end(); i++)
+ manualObject->index(*i);
+ }
+ manualObject->end();
+
+ manualObject->beginUpdate(1);
+ if (triangleVertices.size() > 0 && isEnabled)
+ {
+ manualObject->estimateVertexCount(triangleVertices.size());
+ manualObject->estimateIndexCount(triangleIndices.size());
+ for (std::list<VertexPair>::iterator i = triangleVertices.begin(); i != triangleVertices.end(); i++)
+ {
+ manualObject->position(i->first);
+ manualObject->colour(i->second.r, i->second.g, i->second.b, fillAlpha);
+ }
+ for (std::list<int>::iterator i = triangleIndices.begin(); i != triangleIndices.end(); i++)
+ manualObject->index(*i);
+ }
+ manualObject->end();
+ }
+
+ void DebugDrawer::clear()
+ {
+ lineVertices.clear();
+ triangleVertices.clear();
+ lineIndices.clear();
+ triangleIndices.clear();
+ linesIndex = trianglesIndex = 0;
+ }
+
+ int DebugDrawer::addLineVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour)
+ {
+ lineVertices.push_back(VertexPair(vertex, colour));
+ return linesIndex++;
+ }
+
+ void DebugDrawer::addLineIndices(int index1, int index2)
+ {
+ lineIndices.push_back(index1);
+ lineIndices.push_back(index2);
+ }
+
+ int DebugDrawer::addTriangleVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour)
+ {
+ triangleVertices.push_back(VertexPair(vertex, colour));
+ return trianglesIndex++;
+ }
+
+ void DebugDrawer::addTriangleIndices(int index1, int index2, int index3)
+ {
+ triangleIndices.push_back(index1);
+ triangleIndices.push_back(index2);
+ triangleIndices.push_back(index3);
+ }
+
+ void DebugDrawer::addQuadIndices(int index1, int index2, int index3, int index4)
+ {
+ triangleIndices.push_back(index1);
+ triangleIndices.push_back(index2);
+ triangleIndices.push_back(index3);
+
+ triangleIndices.push_back(index1);
+ triangleIndices.push_back(index3);
+ triangleIndices.push_back(index4);
+ }
+}
Added: code/trunk/src/libraries/tools/DebugDrawer.h
===================================================================
--- code/trunk/src/libraries/tools/DebugDrawer.h (rev 0)
+++ code/trunk/src/libraries/tools/DebugDrawer.h 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,107 @@
+/**
+ * Copy-pasted from
+ * - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src
+ * - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class
+ *
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau
+ */
+
+/**
+ * @file
+ * @brief DebugDrawer is a utility to draw debug shapes (lines, triangles, spheres) with Ogre.
+ * This utility is e.g. used by @ref BulletDebugDrawer to visualize collision shapes and other physical entities.
+ */
+
+#ifndef _DebugDrawer_H__
+#define _DebugDrawer_H__
+
+#include "tools/ToolsPrereqs.h"
+
+#include <map>
+
+#include "IcoSphere.h"
+
+namespace orxonox
+{
+ class _ToolsExport DebugDrawer
+ {
+ public:
+ DebugDrawer(Ogre::SceneManager *_sceneManager, float _fillAlpha);
+ ~DebugDrawer();
+
+ void build();
+
+ void drawLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour);
+ void drawCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false);
+
+ bool getEnabled()
+ {
+ return isEnabled;
+ }
+ void setEnabled(bool _isEnabled)
+ {
+ isEnabled = _isEnabled;
+ }
+ void switchEnabled()
+ {
+ isEnabled = !isEnabled;
+ }
+
+ void clear();
+
+ private:
+ const IcoSphere& getIcoSphere(float radius) const;
+
+ Ogre::SceneManager* sceneManager;
+ float fillAlpha;
+ Ogre::ManualObject* manualObject;
+ IcoSphere icoSphere0;
+ IcoSphere icoSphere1;
+ IcoSphere icoSphere2;
+ IcoSphere icoSphere3;
+ IcoSphere icoSphere4;
+
+ bool isEnabled;
+
+ std::list<VertexPair> lineVertices, triangleVertices;
+ std::list<int> lineIndices, triangleIndices;
+
+ int linesIndex, trianglesIndex;
+
+ void initialise();
+ void shutdown();
+
+ void buildLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledTriangle(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
+
+ void buildCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
+
+ void buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
+
+ void buildTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f);
+
+ int addLineVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour);
+ void addLineIndices(int index1, int index2);
+
+ int addTriangleVertex(const Ogre::Vector3& vertex, const Ogre::ColourValue& colour);
+ void addTriangleIndices(int index1, int index2, int index3);
+
+ void addQuadIndices(int index1, int index2, int index3, int index4);
+ };
+}
+
+#endif /* _DebugDrawer_H__ */
Added: code/trunk/src/libraries/tools/IcoSphere.cc
===================================================================
--- code/trunk/src/libraries/tools/IcoSphere.cc (rev 0)
+++ code/trunk/src/libraries/tools/IcoSphere.cc 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,224 @@
+/**
+ * Copy-pasted from
+ * - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src
+ * - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class
+ *
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau
+ */
+
+#include "IcoSphere.h"
+
+#include <OgreSceneManager.h>
+#include <OgreRenderQueue.h>
+#include <OgreManualObject.h>
+#include <OgreAxisAlignedBox.h>
+
+namespace orxonox
+{
+ IcoSphere::IcoSphere() :
+ index(0)
+ {
+ }
+
+ IcoSphere::~IcoSphere()
+ {
+ }
+
+ void IcoSphere::create(int recursionLevel)
+ {
+ vertices.clear();
+ lineIndices.clear();
+ triangleIndices.clear();
+ faces.clear();
+ middlePointIndexCache.clear();
+ index = 0;
+
+ float t = (1.0f + Ogre::Math::Sqrt(5.0f)) / 2.0f;
+
+ addVertex(Ogre::Vector3(-1.0f, t, 0.0f));
+ addVertex(Ogre::Vector3(1.0f, t, 0.0f));
+ addVertex(Ogre::Vector3(-1.0f, -t, 0.0f));
+ addVertex(Ogre::Vector3(1.0f, -t, 0.0f));
+
+ addVertex(Ogre::Vector3(0.0f, -1.0f, t));
+ addVertex(Ogre::Vector3(0.0f, 1.0f, t));
+ addVertex(Ogre::Vector3(0.0f, -1.0f, -t));
+ addVertex(Ogre::Vector3(0.0f, 1.0f, -t));
+
+ addVertex(Ogre::Vector3(t, 0.0f, -1.0f));
+ addVertex(Ogre::Vector3(t, 0.0f, 1.0f));
+ addVertex(Ogre::Vector3(-t, 0.0f, -1.0f));
+ addVertex(Ogre::Vector3(-t, 0.0f, 1.0f));
+
+ addFace(0, 11, 5);
+ addFace(0, 5, 1);
+ addFace(0, 1, 7);
+ addFace(0, 7, 10);
+ addFace(0, 10, 11);
+
+ addFace(1, 5, 9);
+ addFace(5, 11, 4);
+ addFace(11, 10, 2);
+ addFace(10, 7, 6);
+ addFace(7, 1, 8);
+
+ addFace(3, 9, 4);
+ addFace(3, 4, 2);
+ addFace(3, 2, 6);
+ addFace(3, 6, 8);
+ addFace(3, 8, 9);
+
+ addFace(4, 9, 5);
+ addFace(2, 4, 11);
+ addFace(6, 2, 10);
+ addFace(8, 6, 7);
+ addFace(9, 8, 1);
+
+ addLineIndices(1, 0);
+ addLineIndices(1, 5);
+ addLineIndices(1, 7);
+ addLineIndices(1, 8);
+ addLineIndices(1, 9);
+
+ addLineIndices(2, 3);
+ addLineIndices(2, 4);
+ addLineIndices(2, 6);
+ addLineIndices(2, 10);
+ addLineIndices(2, 11);
+
+ addLineIndices(0, 5);
+ addLineIndices(5, 9);
+ addLineIndices(9, 8);
+ addLineIndices(8, 7);
+ addLineIndices(7, 0);
+
+ addLineIndices(10, 11);
+ addLineIndices(11, 4);
+ addLineIndices(4, 3);
+ addLineIndices(3, 6);
+ addLineIndices(6, 10);
+
+ addLineIndices(0, 11);
+ addLineIndices(11, 5);
+ addLineIndices(5, 4);
+ addLineIndices(4, 9);
+ addLineIndices(9, 3);
+ addLineIndices(3, 8);
+ addLineIndices(8, 6);
+ addLineIndices(6, 7);
+ addLineIndices(7, 10);
+ addLineIndices(10, 0);
+
+ for (int i = 0; i < recursionLevel; i++)
+ {
+ std::list<TriangleIndices> faces2;
+
+ for (std::list<TriangleIndices>::iterator j = faces.begin(); j != faces.end(); j++)
+ {
+ TriangleIndices f = *j;
+ int a = getMiddlePoint(f.v1, f.v2);
+ int b = getMiddlePoint(f.v2, f.v3);
+ int c = getMiddlePoint(f.v3, f.v1);
+
+ removeLineIndices(f.v1, f.v2);
+ removeLineIndices(f.v2, f.v3);
+ removeLineIndices(f.v3, f.v1);
+
+ faces2.push_back(TriangleIndices(f.v1, a, c));
+ faces2.push_back(TriangleIndices(f.v2, b, a));
+ faces2.push_back(TriangleIndices(f.v3, c, b));
+ faces2.push_back(TriangleIndices(a, b, c));
+
+ addTriangleLines(f.v1, a, c);
+ addTriangleLines(f.v2, b, a);
+ addTriangleLines(f.v3, c, b);
+ }
+
+ faces = faces2;
+ }
+ }
+
+ void IcoSphere::addLineIndices(int index0, int index1)
+ {
+ lineIndices.push_back(LineIndices(index0, index1));
+ }
+
+ void IcoSphere::removeLineIndices(int index0, int index1)
+ {
+ std::list<LineIndices>::iterator result = std::find(lineIndices.begin(), lineIndices.end(), LineIndices(index0, index1));
+
+ if (result != lineIndices.end())
+ lineIndices.erase(result);
+ }
+
+ void IcoSphere::addTriangleLines(int index0, int index1, int index2)
+ {
+ addLineIndices(index0, index1);
+ addLineIndices(index1, index2);
+ addLineIndices(index2, index0);
+ }
+
+ int IcoSphere::addVertex(const Ogre::Vector3& vertex)
+ {
+ Ogre::Real length = vertex.length();
+ vertices.push_back(Ogre::Vector3(vertex.x / length, vertex.y / length, vertex.z / length));
+ return index++;
+ }
+
+ int IcoSphere::getMiddlePoint(int index0, int index1)
+ {
+ bool isFirstSmaller = index0 < index1;
+ __int64 smallerIndex = isFirstSmaller ? index0 : index1;
+ __int64 largerIndex = isFirstSmaller ? index1 : index0;
+ __int64 key = (smallerIndex << 32) | largerIndex;
+
+ if (middlePointIndexCache.find(key) != middlePointIndexCache.end())
+ return middlePointIndexCache[key];
+
+ Ogre::Vector3 point1 = vertices[index0];
+ Ogre::Vector3 point2 = vertices[index1];
+ Ogre::Vector3 middle = point1.midPoint(point2);
+
+ int index = addVertex(middle);
+ middlePointIndexCache[key] = index;
+ return index;
+ }
+
+ void IcoSphere::addFace(int index0, int index1, int index2)
+ {
+ faces.push_back(TriangleIndices(index0, index1, index2));
+ }
+
+ void IcoSphere::addToLineIndices(int baseIndex, std::list<int>* target) const
+ {
+ for (std::list<LineIndices>::const_iterator i = lineIndices.begin(); i != lineIndices.end(); i++)
+ {
+ target->push_back(baseIndex + (*i).v1);
+ target->push_back(baseIndex + (*i).v2);
+ }
+ }
+
+ void IcoSphere::addToTriangleIndices(int baseIndex, std::list<int>* target) const
+ {
+ for (std::list<TriangleIndices>::const_iterator i = faces.begin(); i != faces.end(); i++)
+ {
+ target->push_back(baseIndex + (*i).v1);
+ target->push_back(baseIndex + (*i).v2);
+ target->push_back(baseIndex + (*i).v3);
+ }
+ }
+
+ int IcoSphere::addToVertices(std::list<VertexPair>* target, const Ogre::Vector3& position, const Ogre::ColourValue& colour, float scale) const
+ {
+ Ogre::Matrix4 transform = Ogre::Matrix4::IDENTITY;
+ transform.setTrans(position);
+ transform.setScale(Ogre::Vector3(scale, scale, scale));
+
+ for (int i = 0; i < (int) vertices.size(); i++)
+ target->push_back(VertexPair(transform * vertices[i], colour));
+
+ return vertices.size();
+ }
+}
Added: code/trunk/src/libraries/tools/IcoSphere.h
===================================================================
--- code/trunk/src/libraries/tools/IcoSphere.h (rev 0)
+++ code/trunk/src/libraries/tools/IcoSphere.h 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,88 @@
+/**
+ * Copy-pasted from
+ * - https://bitbucket.org/hasyimi/ogre-debug-drawing-utility/src
+ * - http://www.ogre3d.org/tikiwiki/tiki-index.php?page=Debug+Drawing+Utility+Class
+ *
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau
+ */
+
+/**
+ * @file
+ * @brief DebugDrawer is a utility to draw debug shapes (lines, triangles, spheres) with Ogre.
+ * This utility is e.g. used by @ref BulletDebugDrawer to visualize collision shapes and other physical entities.
+ */
+
+#ifndef _IcoSphere_H__
+#define _IcoSphere_H__
+
+#include "tools/ToolsPrereqs.h"
+
+#include <OgreSingleton.h>
+#include <map>
+
+namespace orxonox
+{
+ typedef std::pair<Ogre::Vector3, Ogre::ColourValue> VertexPair;
+
+ class _ToolsExport IcoSphere
+ {
+ public:
+ struct TriangleIndices
+ {
+ int v1, v2, v3;
+
+ TriangleIndices(int _v1, int _v2, int _v3) :
+ v1(_v1), v2(_v2), v3(_v3)
+ {
+ }
+
+ bool operator <(const TriangleIndices &o) const
+ {
+ return v1 < o.v1 && v2 < o.v2 && v3 < o.v3;
+ }
+ };
+
+ struct LineIndices
+ {
+ int v1, v2;
+
+ LineIndices(int _v1, int _v2) :
+ v1(_v1), v2(_v2)
+ {
+ }
+
+ bool operator ==(const LineIndices &o) const
+ {
+ return (v1 == o.v1 && v2 == o.v2) || (v1 == o.v2 && v2 == o.v1);
+ }
+ };
+
+ IcoSphere();
+ ~IcoSphere();
+
+ void create(int recursionLevel);
+ void addToLineIndices(int baseIndex, std::list<int>* target) const;
+ int addToVertices(std::list<VertexPair>* target, const Ogre::Vector3& position, const Ogre::ColourValue& colour, float scale) const;
+ void addToTriangleIndices(int baseIndex, std::list<int>* target) const;
+
+ private:
+ int addVertex(const Ogre::Vector3& vertex);
+ void addLineIndices(int index0, int index1);
+ void addTriangleLines(int index0, int index1, int index2);
+ int getMiddlePoint(int index0, int index1);
+ void addFace(int index0, int index1, int index2);
+
+ void removeLineIndices(int index0, int index1);
+
+ std::vector<Ogre::Vector3> vertices;
+ std::list<LineIndices> lineIndices;
+ std::list<int> triangleIndices;
+ std::list<TriangleIndices> faces;
+ std::map<__int64, int> middlePointIndexCache;
+ int index;
+ };
+}
+
+#endif /* _IcoSphere_H__ */
Added: code/trunk/src/libraries/tools/OgreBulletUtils.h
===================================================================
--- code/trunk/src/libraries/tools/OgreBulletUtils.h (rev 0)
+++ code/trunk/src/libraries/tools/OgreBulletUtils.h 2015-01-11 17:21:51 UTC (rev 10190)
@@ -0,0 +1,62 @@
+/**
+ * Copy-pasted from http://www.ogre3d.org/tikiwiki/BulletDebugDrawer&structure=Cookbook
+ * This source code is released into the Public Domain.
+ *
+ * Modified by Fabian 'x3n' Landau
+ */
+
+#ifndef _OgreBulletUtils_H__
+#define _OgreBulletUtils_H__
+
+#include "tools/ToolsPrereqs.h"
+
+namespace orxonox
+{
+ inline btVector3 vector3(const Ogre::Vector3& V)
+ {
+ return btVector3(V.x, V.y, V.z);
+ }
+
+ inline Ogre::Vector3 vector3(const btVector3& V)
+ {
+ return Ogre::Vector3(V.x(), V.y(), V.z());
+ }
+
+ inline btQuaternion quaternion(const Ogre::Quaternion& Q)
+ {
+ return btQuaternion(Q.x, Q.y, Q.z, Q.w);
+ }
+
+ inline Ogre::Quaternion quaternion(const btQuaternion& Q)
+ {
+ return Ogre::Quaternion(Q.w(), Q.x(), Q.y(), Q.z());
+ }
+
+ inline Ogre::ColourValue colour(const btVector3& color, btScalar alpha)
+ {
+ Ogre::ColourValue c(color.getX(), color.getY(), color.getZ(), alpha);
+ c.saturate();
+ return c;
+ }
+
+ inline Ogre::Matrix3 matrix3(const btMatrix3x3& matrix)
+ {
+ return Matrix3(
+ matrix[0][0], matrix[0][1], matrix[0][2],
+ matrix[1][0], matrix[1][1], matrix[1][2],
+ matrix[2][0], matrix[2][1], matrix[2][2]
+ );
+ }
+
+ inline Ogre::Matrix4 matrix4(const btTransform& transform)
+ {
+ const btMatrix3x3& rotation = transform.getBasis();
+ const btVector3& translation = transform.getOrigin();
+
+ Ogre::Matrix4 matrix4 = Ogre::Matrix4(matrix3(rotation));
+ matrix4.setTrans(vector3(translation));
+ return matrix4;
+ }
+}
+
+#endif /* _OgreBulletUtils_H__ */
Modified: code/trunk/src/libraries/tools/ToolsPrereqs.h
===================================================================
--- code/trunk/src/libraries/tools/ToolsPrereqs.h 2015-01-11 14:40:41 UTC (rev 10189)
+++ code/trunk/src/libraries/tools/ToolsPrereqs.h 2015-01-11 17:21:51 UTC (rev 10190)
@@ -85,6 +85,9 @@
namespace orxonox
{
class BillboardSet;
+ class BulletDebugDrawer;
+ class DebugDrawer;
+ class IcoSphere;
class Mesh;
class ParticleInterface;
class RealTimer;
More information about the Orxonox-commit
mailing list