[Orxonox-commit 5528] r10191 - in code/trunk: data/levels src/libraries/tools
landauf at orxonox.net
landauf at orxonox.net
Sun Jan 11 21:28:39 CET 2015
Author: landauf
Date: 2015-01-11 21:28:39 +0100 (Sun, 11 Jan 2015)
New Revision: 10191
Modified:
code/trunk/data/levels/collisionShapes.oxw
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
Log:
added customized visualization for cylinders and cones to BulletDebugDrawer.
improved DebugDrawer by making circle, cylinder, and sphere rotatable. added rendering function for cones.
Modified: code/trunk/data/levels/collisionShapes.oxw
===================================================================
--- code/trunk/data/levels/collisionShapes.oxw 2015-01-11 17:21:51 UTC (rev 10190)
+++ code/trunk/data/levels/collisionShapes.oxw 2015-01-11 20:28:39 UTC (rev 10191)
@@ -33,11 +33,11 @@
<StaticEntity position="1000,0,0" collisionType="static">
<collisionShapes>
- <SphereCollisionShape position="0,-600,0" radius="100" />
- <CylinderCollisionShape position="0,-300,0" radius="50" height="150" />
- <BoxCollisionShape position="0,-100,0" halfExtents="30, 50, 80" />
- <ConeCollisionShape position="0,+100,0" radius="50" height="150" />
- <PlaneCollisionShape position="0,+300,0" normal="0, -1, 0" offset="30" />
+ <SphereCollisionShape yaw="20" pitch="20" roll="20" position="0,-300,0" radius="100" />
+ <CylinderCollisionShape yaw="20" pitch="20" roll="20" position="0,+000,0" radius="50" height="150" />
+ <BoxCollisionShape yaw="20" pitch="20" roll="20" position="0,+200,0" halfExtents="30, 50, 80" />
+ <ConeCollisionShape yaw="20" pitch="20" roll="20" position="0,+400,0" radius="50" height="150" />
+ <PlaneCollisionShape yaw="20" pitch="20" roll="20" position="0,+600,0" normal="0, -1, 0" offset="30" />
</collisionShapes>
</StaticEntity>
Modified: code/trunk/src/libraries/tools/BulletDebugDrawer.cc
===================================================================
--- code/trunk/src/libraries/tools/BulletDebugDrawer.cc 2015-01-11 17:21:51 UTC (rev 10190)
+++ code/trunk/src/libraries/tools/BulletDebugDrawer.cc 2015-01-11 20:28:39 UTC (rev 10191)
@@ -58,12 +58,13 @@
void BulletDebugDrawer::drawSphere(const btVector3& p, btScalar radius, const btVector3& color)
{
- this->drawer->drawSphere(vector3(p), radius, colour(color, 1.0f), true);
+ this->drawer->drawSphere(vector3(p), Ogre::Quaternion::IDENTITY, radius, colour(color, 1.0f), true);
}
void BulletDebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
{
- this->drawSphere(transform.getOrigin(), radius, color);
+ Ogre::Matrix4 matrix = matrix4(transform);
+ this->drawer->drawSphere(matrix.getTrans(), matrix.extractQuaternion(), radius, colour(color, 1.0f), true);
}
void BulletDebugDrawer::drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color)
@@ -94,6 +95,18 @@
this->drawer->drawCuboid(corners, colour(color, 1.0f), true);
}
+ void BulletDebugDrawer::drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color)
+ {
+ Ogre::Matrix4 matrix = matrix4(transform);
+ this->drawer->drawCylinder(matrix.getTrans(), matrix.extractQuaternion(), radius, halfHeight * 2, colour(color, 1.0f), true);
+ }
+
+ void BulletDebugDrawer::drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color)
+ {
+ Ogre::Matrix4 matrix = matrix4(transform);
+ this->drawer->drawCone(matrix.getTrans(), matrix.extractQuaternion(), radius, height, 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);
Modified: code/trunk/src/libraries/tools/BulletDebugDrawer.h
===================================================================
--- code/trunk/src/libraries/tools/BulletDebugDrawer.h 2015-01-11 17:21:51 UTC (rev 10190)
+++ code/trunk/src/libraries/tools/BulletDebugDrawer.h 2015-01-11 20:28:39 UTC (rev 10191)
@@ -25,8 +25,8 @@
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 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);
Modified: code/trunk/src/libraries/tools/DebugDrawer.cc
===================================================================
--- code/trunk/src/libraries/tools/DebugDrawer.cc 2015-01-11 17:21:51 UTC (rev 10190)
+++ code/trunk/src/libraries/tools/DebugDrawer.cc 2015-01-11 20:28:39 UTC (rev 10191)
@@ -83,7 +83,7 @@
addLineIndices(index + i, index + ((i + 1) % 4));
}
- void DebugDrawer::buildCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)
+ void DebugDrawer::buildCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)
{
int index = linesIndex;
float increment = 2 * Ogre::Math::PI / segmentsCount;
@@ -91,7 +91,7 @@
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)),
+ addLineVertex(transform * Ogre::Vector3(radius * Ogre::Math::Cos(angle), 0, radius * Ogre::Math::Sin(angle)),
Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
angle += increment;
}
@@ -100,7 +100,7 @@
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)
+ void DebugDrawer::buildFilledCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool up, float alpha)
{
int index = trianglesIndex;
float increment = 2 * Ogre::Math::PI / segmentsCount;
@@ -108,88 +108,85 @@
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)),
+ addTriangleVertex(transform * Ogre::Vector3(radius * Ogre::Math::Cos(angle), 0, 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));
+ addTriangleVertex(transform.getTrans(), 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);
+ {
+ if (up)
+ addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount);
+ else
+ addTriangleIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index, index + segmentsCount);
+ }
}
- void DebugDrawer::buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha)
+ void DebugDrawer::buildCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, 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;
- }
+ Ogre::Matrix4 transform(rotation);
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
- 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,
+ void DebugDrawer::buildFilledCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, 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
+ Ogre::Matrix4 transform(rotation);
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
+ this->buildFilledCircle(transform, radius, segmentsCount, colour, true, alpha);
+
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
+ this->buildFilledCircle(transform, radius, segmentsCount, colour, false, alpha);
+
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;
+ 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);
}
+ }
- addTriangleVertex(Ogre::Vector3(centre.x, centre.y + height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ void DebugDrawer::buildCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha)
+ {
+ int index = linesIndex;
- angle = 0.0f;
+ Ogre::Matrix4 transform(rotation);
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
- // Bottom circle
+ addLineVertex(centre + rotation * Ogre::Vector3(0, height / 2, 0), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+
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;
- }
+ addLineIndices(index + i, index + segmentsCount);
+ }
- addTriangleVertex(Ogre::Vector3(centre.x, centre.y - height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
+ void DebugDrawer::buildFilledCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour,
+ float alpha)
+ {
+ int index = trianglesIndex;
- for (int i = 0; i < segmentsCount; i++)
- {
- addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount);
+ Ogre::Matrix4 transform(rotation);
+ transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0));
+ this->buildCircle(transform, radius, segmentsCount, colour, alpha);
+ this->buildFilledCircle(transform, radius, segmentsCount, colour, false, alpha);
- addTriangleIndices(i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index,
- (segmentsCount + 1) + index + segmentsCount, (segmentsCount + 1) + index + i);
+ addTriangleVertex(centre + rotation * Ogre::Vector3(0, height / 2, 0), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
- 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);
- }
+ for (int i = 0; i < segmentsCount; i++)
+ addTriangleIndices(index + i, index + segmentsCount + 1, i + 1 < segmentsCount ? index + i + 1 : index);
}
void DebugDrawer::buildCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha)
@@ -300,20 +297,38 @@
buildLine(start, end, colour);
}
- void DebugDrawer::drawCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled)
+ void DebugDrawer::drawCircle(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled)
{
- buildCircle(centre, radius, segmentsCount, colour);
+ int segmentsCount = std::min(100.0, radius / 2.5);
+
+ Ogre::Matrix4 transform(rotation);
+ transform.setTrans(centre);
+
+ buildCircle(transform, radius, segmentsCount, colour);
if (isFilled)
- buildFilledCircle(centre, radius, segmentsCount, colour, fillAlpha);
+ buildFilledCircle(transform, radius, segmentsCount, colour, fillAlpha);
}
- void DebugDrawer::drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled)
+ void DebugDrawer::drawCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled)
{
- buildCylinder(centre, radius, segmentsCount, height, colour);
+ int segmentsCount = std::min(100.0, radius / 2.5);
+
if (isFilled)
- buildFilledCylinder(centre, radius, segmentsCount, height, colour, fillAlpha);
+ buildFilledCylinder(centre, rotation, radius, segmentsCount, height, colour, fillAlpha);
+ else
+ buildCylinder(centre, rotation, radius, segmentsCount, height, colour);
}
+ void DebugDrawer::drawCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled)
+ {
+ int segmentsCount = std::min(100.0, radius / 2.5);
+
+ if (isFilled)
+ buildFilledCone(centre, rotation, radius, segmentsCount, height, colour, fillAlpha);
+ else
+ buildCone(centre, rotation, radius, segmentsCount, height, colour);
+ }
+
void DebugDrawer::drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled)
{
buildQuad(vertices, colour);
@@ -328,20 +343,26 @@
buildFilledCuboid(vertices, colour, fillAlpha);
}
- void DebugDrawer::drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled)
+ void DebugDrawer::drawSphere(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, 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;
+ this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(1, 0, 0)), radius, colour, false);
+ this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(0, 1, 0)), radius, colour, false);
+ this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(0, 0, 1)), radius, colour, false);
+
+ int baseIndex = trianglesIndex;
trianglesIndex += sphere.addToVertices(&triangleVertices, centre, Ogre::ColourValue(colour.r, colour.g, colour.b, fillAlpha), radius);
sphere.addToTriangleIndices(baseIndex, &triangleIndices);
}
+ else
+ {
+ int baseIndex = linesIndex;
+ linesIndex += sphere.addToVertices(&lineVertices, centre, colour, radius);
+ sphere.addToLineIndices(baseIndex, &lineIndices);
+ }
}
const IcoSphere& DebugDrawer::getIcoSphere(float radius) const
Modified: code/trunk/src/libraries/tools/DebugDrawer.h
===================================================================
--- code/trunk/src/libraries/tools/DebugDrawer.h 2015-01-11 17:21:51 UTC (rev 10190)
+++ code/trunk/src/libraries/tools/DebugDrawer.h 2015-01-11 20:28:39 UTC (rev 10191)
@@ -34,11 +34,13 @@
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 drawCircle(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled = false);
+ void drawCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, 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 drawSphere(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, 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()
@@ -85,12 +87,15 @@
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 buildCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool up, 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 buildCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f);
+ void buildFilledCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, 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);
More information about the Orxonox-commit
mailing list