Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 10191 for code/trunk


Ignore:
Timestamp:
Jan 11, 2015, 9:28:39 PM (9 years ago)
Author:
landauf
Message:

added customized visualization for cylinders and cones to BulletDebugDrawer.
improved DebugDrawer by making circle, cylinder, and sphere rotatable. added rendering function for cones.

Location:
code/trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/trunk/data/levels/collisionShapes.oxw

    r10189 r10191  
    3434        <StaticEntity position="1000,0,0" collisionType="static">
    3535                <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" />
    4141                </collisionShapes>
    4242        </StaticEntity>
  • code/trunk/src/libraries/tools/BulletDebugDrawer.cc

    r10190 r10191  
    5959    void BulletDebugDrawer::drawSphere(const btVector3& p, btScalar radius, const btVector3& color)
    6060    {
    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);
    6262    }
    6363
    6464    void BulletDebugDrawer::drawSphere(btScalar radius, const btTransform& transform, const btVector3& color)
    6565    {
    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);
    6768    }
    6869
     
    9394        corners[7]  = Ogre::Vector3(trans * btVector3(bbMax[0], bbMin[1], bbMax[2]));
    9495        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);
    95108    }
    96109
  • code/trunk/src/libraries/tools/BulletDebugDrawer.h

    r10190 r10191  
    2626            virtual void drawBox(const btVector3& bbMin, const btVector3& bbMax, const btVector3& color);
    2727            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);
    3030//            virtual void drawPlane(const btVector3& planeNormal, btScalar planeConst, const btTransform& transform, const btVector3& color);
    3131
  • code/trunk/src/libraries/tools/DebugDrawer.cc

    r10190 r10191  
    8484    }
    8585
    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)
    8787    {
    8888        int index = linesIndex;
     
    9292        for (int i = 0; i < segmentsCount; i++)
    9393        {
    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)),
    9595                    Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
    9696            angle += increment;
     
    101101    }
    102102
    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)
    104104    {
    105105        int index = trianglesIndex;
     
    109109        for (int i = 0; i < segmentsCount; i++)
    110110        {
    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)),
    112112                    Ogre::ColourValue(colour.r, colour.g, colour.b, alpha));
    113113            angle += increment;
    114114        }
    115115
    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)
    123128    {
    124129        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++)
    150138            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,
    155142            float alpha)
    156143    {
    157144        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        {
    190157            addQuadIndices(index + i, i + 1 < segmentsCount ? index + i + 1 : index,
    191158                    i + 1 < segmentsCount ? (segmentsCount + 1) + index + i + 1 : (segmentsCount + 1) + index, (segmentsCount + 1) + index + i);
    192159        }
     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);
    193190    }
    194191
     
    301298    }
    302299
    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);
    315330    }
    316331
     
    329344    }
    330345
    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)
    332347    {
    333348        const IcoSphere& sphere = this->getIcoSphere(radius);
    334349
    335         int 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;
    342357            trianglesIndex += sphere.addToVertices(&triangleVertices, centre, Ogre::ColourValue(colour.r, colour.g, colour.b, fillAlpha), radius);
    343358            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);
    344365        }
    345366    }
  • code/trunk/src/libraries/tools/DebugDrawer.h

    r10190 r10191  
    3535
    3636            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
    3941            void drawQuad(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, bool isFilled = false);
    4042            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);
    4244            void drawTetrahedron(const Ogre::Vector3& centre, float scale, const Ogre::ColourValue& colour, bool isFilled = false);
    4345
     
    8688            void buildFilledCuboid(const Ogre::Vector3* vertices, const Ogre::ColourValue& colour, float alpha = 1.0f);
    8789
    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);
    9092
    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);
    9398
    9499            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.