Changeset 10191
- Timestamp:
- Jan 11, 2015, 9:28:39 PM (10 years ago)
- Location:
- code/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/data/levels/collisionShapes.oxw
r10189 r10191 34 34 <StaticEntity position="1000,0,0" collisionType="static"> 35 35 <collisionShapes> 36 <SphereCollisionShape position="0,-600,0" radius="100" />37 <CylinderCollisionShape position="0,-300,0" radius="50" height="150" />38 <BoxCollisionShape position="0,-100,0" halfExtents="30, 50, 80" />39 <ConeCollisionShape position="0,+100,0" radius="50" height="150" />40 <PlaneCollisionShape position="0,+300,0" normal="0, -1, 0" offset="30" />36 <SphereCollisionShape yaw="20" pitch="20" roll="20" position="0,-300,0" radius="100" /> 37 <CylinderCollisionShape yaw="20" pitch="20" roll="20" position="0,+000,0" radius="50" height="150" /> 38 <BoxCollisionShape yaw="20" pitch="20" roll="20" position="0,+200,0" halfExtents="30, 50, 80" /> 39 <ConeCollisionShape yaw="20" pitch="20" roll="20" position="0,+400,0" radius="50" height="150" /> 40 <PlaneCollisionShape yaw="20" pitch="20" roll="20" position="0,+600,0" normal="0, -1, 0" offset="30" /> 41 41 </collisionShapes> 42 42 </StaticEntity> -
code/trunk/src/libraries/tools/BulletDebugDrawer.cc
r10190 r10191 59 59 void BulletDebugDrawer::drawSphere(const btVector3& p, btScalar radius, const btVector3& color) 60 60 { 61 this->drawer->drawSphere(vector3(p), radius, colour(color, 1.0f), true);61 this->drawer->drawSphere(vector3(p), Ogre::Quaternion::IDENTITY, radius, colour(color, 1.0f), true); 62 62 } 63 63 64 64 void BulletDebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color) 65 65 { 66 this->drawSphere(transform.getOrigin(), radius, color); 66 Ogre::Matrix4 matrix = matrix4(transform); 67 this->drawer->drawSphere(matrix.getTrans(), matrix.extractQuaternion(), radius, colour(color, 1.0f), true); 67 68 } 68 69 … … 93 94 corners[7] = Ogre::Vector3(trans * btVector3(bbMax[0], bbMin[1], bbMax[2])); 94 95 this->drawer->drawCuboid(corners, colour(color, 1.0f), true); 96 } 97 98 void BulletDebugDrawer::drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color) 99 { 100 Ogre::Matrix4 matrix = matrix4(transform); 101 this->drawer->drawCylinder(matrix.getTrans(), matrix.extractQuaternion(), radius, halfHeight * 2, colour(color, 1.0f), true); 102 } 103 104 void BulletDebugDrawer::drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color) 105 { 106 Ogre::Matrix4 matrix = matrix4(transform); 107 this->drawer->drawCone(matrix.getTrans(), matrix.extractQuaternion(), radius, height, colour(color, 1.0f), true); 95 108 } 96 109 -
code/trunk/src/libraries/tools/BulletDebugDrawer.h
r10190 r10191 26 26 virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color); 27 27 virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btTransform& trans, const btVector3& color); 28 //virtual void drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color);29 //virtual void drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color);28 virtual void drawCylinder(btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color); 29 virtual void drawCone(btScalar radius, btScalar height, int upAxis, const btTransform& transform, const btVector3& color); 30 30 // virtual void drawPlane(const btVector3& planeNormal, btScalar planeConst, const btTransform& transform, const btVector3& color); 31 31 -
code/trunk/src/libraries/tools/DebugDrawer.cc
r10190 r10191 84 84 } 85 85 86 void DebugDrawer::buildCircle(const Ogre:: Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)86 void DebugDrawer::buildCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha) 87 87 { 88 88 int index = linesIndex; … … 92 92 for (int i = 0; i < segmentsCount; i++) 93 93 { 94 addLineVertex( Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y, centre.z +radius * Ogre::Math::Sin(angle)),94 addLineVertex(transform * Ogre::Vector3(radius * Ogre::Math::Cos(angle), 0, radius * Ogre::Math::Sin(angle)), 95 95 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 96 96 angle += increment; … … 101 101 } 102 102 103 void DebugDrawer::buildFilledCircle(const Ogre:: Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha)103 void DebugDrawer::buildFilledCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool up, float alpha) 104 104 { 105 105 int index = trianglesIndex; … … 109 109 for (int i = 0; i < segmentsCount; i++) 110 110 { 111 addTriangleVertex( Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y, centre.z +radius * Ogre::Math::Sin(angle)),111 addTriangleVertex(transform * Ogre::Vector3(radius * Ogre::Math::Cos(angle), 0, radius * Ogre::Math::Sin(angle)), 112 112 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 113 113 angle += increment; 114 114 } 115 115 116 addTriangleVertex(centre, Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 117 118 for (int i = 0; i < segmentsCount; i++) 119 addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount); 120 } 121 122 void DebugDrawer::buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha) 116 addTriangleVertex(transform.getTrans(), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 117 118 for (int i = 0; i < segmentsCount; i++) 119 { 120 if (up) 121 addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount); 122 else 123 addTriangleIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index, index + segmentsCount); 124 } 125 } 126 127 void DebugDrawer::buildCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha) 123 128 { 124 129 int index = linesIndex; 125 float increment = 2 * Ogre::Math::PI / segmentsCount; 126 float angle = 0.0f; 127 128 // Top circle 129 for (int i = 0; i < segmentsCount; i++) 130 { 131 addLineVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y + height / 2, centre.z + radius * Ogre::Math::Sin(angle)), 132 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 133 angle += increment; 134 } 135 136 angle = 0.0f; 137 138 // Bottom circle 139 for (int i = 0; i < segmentsCount; i++) 140 { 141 addLineVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y - height / 2, centre.z + radius * Ogre::Math::Sin(angle)), 142 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 143 angle += increment; 144 } 145 146 for (int i = 0; i < segmentsCount; i++) 147 { 148 addLineIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index); 149 addLineIndices(segmentsCount + index + i, i + 1 < segmentsCount ? segmentsCount + index + i + 1 : segmentsCount + index); 130 131 Ogre::Matrix4 transform(rotation); 132 transform.setTrans(centre + rotation * Ogre::Vector3(0, height / 2, 0)); 133 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 134 transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0)); 135 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 136 137 for (int i = 0; i < segmentsCount; i++) 150 138 addLineIndices(index + i, segmentsCount + index + i); 151 } 152 } 153 154 void DebugDrawer::buildFilledCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, 139 } 140 141 void DebugDrawer::buildFilledCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, 155 142 float alpha) 156 143 { 157 144 int index = trianglesIndex; 158 float increment = 2 * Ogre::Math::PI / segmentsCount; 159 float angle = 0.0f; 160 161 // Top circle 162 for (int i = 0; i < segmentsCount; i++) 163 { 164 addTriangleVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y + height / 2, centre.z + radius * Ogre::Math::Sin(angle)), 165 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 166 angle += increment; 167 } 168 169 addTriangleVertex(Ogre::Vector3(centre.x, centre.y + height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 170 171 angle = 0.0f; 172 173 // Bottom circle 174 for (int i = 0; i < segmentsCount; i++) 175 { 176 addTriangleVertex(Ogre::Vector3(centre.x + radius * Ogre::Math::Cos(angle), centre.y - height / 2, centre.z + radius * Ogre::Math::Sin(angle)), 177 Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 178 angle += increment; 179 } 180 181 addTriangleVertex(Ogre::Vector3(centre.x, centre.y - height / 2, centre.z), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 182 183 for (int i = 0; i < segmentsCount; i++) 184 { 185 addTriangleIndices(i + 1 < segmentsCount ? index + i + 1 : index, index + i, index + segmentsCount); 186 187 addTriangleIndices(i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index, 188 (segmentsCount + 1) + index + segmentsCount, (segmentsCount + 1) + index + i); 189 145 146 Ogre::Matrix4 transform(rotation); 147 transform.setTrans(centre + rotation * Ogre::Vector3(0, height / 2, 0)); 148 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 149 this->buildFilledCircle(transform, radius, segmentsCount, colour, true, alpha); 150 151 transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0)); 152 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 153 this->buildFilledCircle(transform, radius, segmentsCount, colour, false, alpha); 154 155 for (int i = 0; i < segmentsCount; i++) 156 { 190 157 addQuadIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index, 191 158 i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index, (segmentsCount + 1) + index + i); 192 159 } 160 } 161 162 void DebugDrawer::buildCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha) 163 { 164 int index = linesIndex; 165 166 Ogre::Matrix4 transform(rotation); 167 transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0)); 168 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 169 170 addLineVertex(centre + rotation * Ogre::Vector3(0, height / 2, 0), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 171 172 for (int i = 0; i < segmentsCount; i++) 173 addLineIndices(index + i, index + segmentsCount); 174 } 175 176 void DebugDrawer::buildFilledCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, 177 float alpha) 178 { 179 int index = trianglesIndex; 180 181 Ogre::Matrix4 transform(rotation); 182 transform.setTrans(centre + rotation * Ogre::Vector3(0, -height / 2, 0)); 183 this->buildCircle(transform, radius, segmentsCount, colour, alpha); 184 this->buildFilledCircle(transform, radius, segmentsCount, colour, false, alpha); 185 186 addTriangleVertex(centre + rotation * Ogre::Vector3(0, height / 2, 0), Ogre::ColourValue(colour.r, colour.g, colour.b, alpha)); 187 188 for (int i = 0; i < segmentsCount; i++) 189 addTriangleIndices(index + i, index + segmentsCount + 1, i + 1 < segmentsCount ? index + i + 1 : index); 193 190 } 194 191 … … 301 298 } 302 299 303 void DebugDrawer::drawCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled) 304 { 305 buildCircle(centre, radius, segmentsCount, colour); 306 if (isFilled) 307 buildFilledCircle(centre, radius, segmentsCount, colour, fillAlpha); 308 } 309 310 void DebugDrawer::drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled) 311 { 312 buildCylinder(centre, radius, segmentsCount, height, colour); 313 if (isFilled) 314 buildFilledCylinder(centre, radius, segmentsCount, height, colour, fillAlpha); 300 void DebugDrawer::drawCircle(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled) 301 { 302 int segmentsCount = std::min(100.0, radius / 2.5); 303 304 Ogre::Matrix4 transform(rotation); 305 transform.setTrans(centre); 306 307 buildCircle(transform, radius, segmentsCount, colour); 308 if (isFilled) 309 buildFilledCircle(transform, radius, segmentsCount, colour, fillAlpha); 310 } 311 312 void DebugDrawer::drawCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled) 313 { 314 int segmentsCount = std::min(100.0, radius / 2.5); 315 316 if (isFilled) 317 buildFilledCylinder(centre, rotation, radius, segmentsCount, height, colour, fillAlpha); 318 else 319 buildCylinder(centre, rotation, radius, segmentsCount, height, colour); 320 } 321 322 void DebugDrawer::drawCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled) 323 { 324 int segmentsCount = std::min(100.0, radius / 2.5); 325 326 if (isFilled) 327 buildFilledCone(centre, rotation, radius, segmentsCount, height, colour, fillAlpha); 328 else 329 buildCone(centre, rotation, radius, segmentsCount, height, colour); 315 330 } 316 331 … … 329 344 } 330 345 331 void DebugDrawer::drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled)346 void DebugDrawer::drawSphere(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled) 332 347 { 333 348 const IcoSphere& sphere = this->getIcoSphere(radius); 334 349 335 i nt baseIndex = linesIndex;336 linesIndex += sphere.addToVertices(&lineVertices, centre, colour, radius);337 sphere.addToLineIndices(baseIndex, &lineIndices);338 339 if (isFilled)340 { 341 baseIndex = trianglesIndex;350 if (isFilled) 351 { 352 this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(1, 0, 0)), radius, colour, false); 353 this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(0, 1, 0)), radius, colour, false); 354 this->drawCircle(centre, rotation * Ogre::Quaternion(Ogre::Degree(90), Ogre::Vector3(0, 0, 1)), radius, colour, false); 355 356 int baseIndex = trianglesIndex; 342 357 trianglesIndex += sphere.addToVertices(&triangleVertices, centre, Ogre::ColourValue(colour.r, colour.g, colour.b, fillAlpha), radius); 343 358 sphere.addToTriangleIndices(baseIndex, &triangleIndices); 359 } 360 else 361 { 362 int baseIndex = linesIndex; 363 linesIndex += sphere.addToVertices(&lineVertices, centre, colour, radius); 364 sphere.addToLineIndices(baseIndex, &lineIndices); 344 365 } 345 366 } -
code/trunk/src/libraries/tools/DebugDrawer.h
r10190 r10191 35 35 36 36 void drawLine(const Ogre::Vector3& start, const Ogre::Vector3& end, const Ogre::ColourValue& colour); 37 void drawCircle(const Ogre::Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool isFilled = false); 38 void drawCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, bool isFilled = false); 37 void drawCircle(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled = false); 38 void drawCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled = false); 39 void drawCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, float height, const Ogre::ColourValue& colour, bool isFilled = false); 40 39 41 void drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false); 40 42 void drawCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false); 41 void drawSphere(const Ogre::Vector3& centre, float radius, const Ogre::ColourValue& colour, bool isFilled = false);43 void drawSphere(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, const Ogre::ColourValue& colour, bool isFilled = false); 42 44 void drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false); 43 45 … … 86 88 void buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f); 87 89 88 void buildCircle(const Ogre:: Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);89 void buildFilledCircle(const Ogre:: Vector3& centre, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f);90 void buildCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, float alpha = 1.0f); 91 void buildFilledCircle(const Ogre::Matrix4& transform, float radius, int segmentsCount, const Ogre::ColourValue& colour, bool up, float alpha = 1.0f); 90 92 91 void buildCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 92 void buildFilledCylinder(const Ogre::Vector3& centre, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 93 void buildCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 94 void buildFilledCylinder(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 95 96 void buildCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 97 void buildFilledCone(const Ogre::Vector3& centre, const Ogre::Quaternion& rotation, float radius, int segmentsCount, float height, const Ogre::ColourValue& colour, float alpha = 1.0f); 93 98 94 99 void buildTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, float alpha = 1.0f);
Note: See TracChangeset
for help on using the changeset viewer.