Line3D.cpp
Go to the documentation of this file.
00001 #include "Line3D.h"
00002 
00003 #define MAX(a,b) ((a > b) ? a : b)
00004 
00005 Line3D::Line3D(void)
00006 {
00007    mRenderOp.vertexData = new VertexData();
00008    mDrawn = false;
00009 
00010    this->setMaterial("BaseWhiteNoLighting");
00011 }
00012 
00013 Line3D::~Line3D(void)
00014 {
00015    delete mRenderOp.vertexData;
00016 }
00017 
00018 void Line3D::addPoint(const Vector3 &p)
00019 {
00020    mPoints.push_back(p);
00021 }
00022 
00023 const Vector3 &Line3D::getPoint(unsigned short index) const
00024 {
00025    assert(index < mPoints.size());
00026 
00027    return mPoints[index];
00028 }
00029 
00030 unsigned short Line3D::getNumPoints(void) const
00031 {
00032    return (unsigned short)mPoints.size();
00033 }
00034 
00035 void Line3D::updatePoint(unsigned short index, const Vector3 &value)
00036 {
00037    assert(index < mPoints.size() && "Point index is out of bounds!!");
00038 
00039    mPoints[index] = value;
00040 }
00041 
00042 void Line3D::drawLine(Vector3 &start, Vector3 &end)
00043 {
00044    if(mPoints.size())
00045       mPoints.clear();
00046 
00047    mPoints.push_back(start);
00048    mPoints.push_back(end);
00049 
00050    drawLines();
00051 }
00052 
00053 void Line3D::drawLines(void)
00054 {
00055    if(mDrawn)
00056       return;
00057    else
00058       mDrawn = true;
00059 
00060    // Initialization stuff
00061    mRenderOp.indexData = 0;
00062    mRenderOp.vertexData->vertexCount = mPoints.size();
00063    mRenderOp.vertexData->vertexStart = 0;
00064    mRenderOp.operationType = RenderOperation::OT_LINE_STRIP; // OT_LINE_LIST, OT_LINE_STRIP
00065    mRenderOp.useIndexes = false;
00066 
00067    VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;
00068    VertexBufferBinding *bind = mRenderOp.vertexData->vertexBufferBinding;
00069 
00070    decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);
00071 
00072    HardwareVertexBufferSharedPtr vbuf =
00073       HardwareBufferManager::getSingleton().createVertexBuffer(
00074          decl->getVertexSize(POSITION_BINDING),
00075          mRenderOp.vertexData->vertexCount,
00076          HardwareBuffer::HBU_STATIC_WRITE_ONLY);
00077 
00078    bind->setBinding(POSITION_BINDING, vbuf);
00079 
00080    // Drawing stuff
00081    int size = mPoints.size();
00082    Vector3 vaabMin = mPoints[0];
00083    Vector3 vaabMax = mPoints[0];
00084 
00085    Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));
00086 
00087    for(int i = 0; i < size; i++)
00088    {
00089       *prPos++ = mPoints[i].x;
00090       *prPos++ = mPoints[i].y;
00091       *prPos++ = mPoints[i].z;
00092 
00093       if(mPoints[i].x < vaabMin.x)
00094          vaabMin.x = mPoints[i].x;
00095       if(mPoints[i].y < vaabMin.y)
00096          vaabMin.y = mPoints[i].y;
00097       if(mPoints[i].z < vaabMin.z)
00098          vaabMin.z = mPoints[i].z;
00099 
00100       if(mPoints[i].x > vaabMax.x)
00101          vaabMax.x = mPoints[i].x;
00102       if(mPoints[i].y > vaabMax.y)
00103          vaabMax.y = mPoints[i].y;
00104       if(mPoints[i].z > vaabMax.z)
00105          vaabMax.z = mPoints[i].z;
00106    }
00107 
00108    vbuf->unlock();
00109 
00110    mBox.setExtents(vaabMin, vaabMax);
00111 }
00112 
00113 Real Line3D::getSquaredViewDepth(const Camera *cam) const
00114 {
00115    Vector3 vMin, vMax, vMid, vDist;
00116    vMin = mBox.getMinimum();
00117    vMax = mBox.getMaximum();
00118    vMid = ((vMin - vMax) * 0.5) + vMin;
00119    vDist = cam->getDerivedPosition() - vMid;
00120 
00121    return vDist.squaredLength();
00122 }
00123 
00124 Real Line3D::getBoundingRadius(void) const
00125 {
00126    return Math::Sqrt(MAX(mBox.getMaximum().squaredLength(), mBox.getMinimum().squaredLength()));
00127    //return mRadius;
00128 }
00129 /*
00130 void Line3D::getWorldTransforms(Matrix4 *xform) const
00131 {
00132    // return identity matrix to prevent parent transforms
00133    *xform = Matrix4::IDENTITY;
00134 }
00135 */
00136 const Quaternion &Line3D::getWorldOrientation(void) const
00137 {
00138    return Quaternion::IDENTITY;
00139 }
00140 
00141 const Vector3 &Line3D::getWorldPosition(void) const
00142 {
00143    return Vector3::ZERO;
00144 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Properties Friends Defines


cop_rviz_plugin
Author(s): U. Klank, Josh Faust
autogenerated on Thu May 23 2013 10:50:43