Changeset 3130 for code/branches/pch/src/orxonox/tools/DynamicLines.cc
- Timestamp:
- Jun 9, 2009, 7:51:00 PM (15 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
code/branches/pch/src/orxonox/tools/DynamicLines.cc
r3117 r3130 1 /* 2 * ORXONOX - the hottest 3D action shooter ever to exist 3 * > www.orxonox.net < 4 * 5 * 6 * License notice: 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public License 10 * as published by the Free Software Foundation; either version 2 11 * of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * GNU General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public License 19 * along with this program; if not, write to the Free Software 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 21 * 22 * Author: 23 * Baxissimo, Emmeran, DWORD, EtherDrive (OGRE Wiki) 24 * Co-authors: 25 * ... 26 * 27 */ 28 1 29 #include "DynamicLines.h" 2 #include <Ogre.h> 30 3 31 #include <cassert> 4 32 #include <cmath> 5 33 6 using namespace Ogre; 34 namespace Ogre 35 { 36 enum 37 { 38 POSITION_BINDING, 39 TEXCOORD_BINDING 40 }; 7 41 8 namespace orxonox 9 {10 enum { 11 POSITION_BINDING,12 TEXCOORD_BINDING13 }; 42 DynamicLines::DynamicLines(OperationType opType) 43 { 44 initialize(opType,false); 45 setMaterial("BaseWhiteNoLighting"); 46 mDirty = true; 47 } 14 48 15 DynamicLines::DynamicLines(OperationType opType) 16 { 17 initialize(opType,false); 18 setMaterial("BaseWhiteNoLighting"); 19 mDirty = true; 49 DynamicLines::~DynamicLines() 50 { 51 } 52 53 void DynamicLines::setOperationType(OperationType opType) 54 { 55 mRenderOp.operationType = opType; 56 } 57 58 RenderOperation::OperationType DynamicLines::getOperationType() const 59 { 60 return mRenderOp.operationType; 61 } 62 63 void DynamicLines::addPoint(const Vector3 &p) 64 { 65 mPoints.push_back(p); 66 mDirty = true; 67 } 68 69 void DynamicLines::addPoint(Real x, Real y, Real z) 70 { 71 mPoints.push_back(Vector3(x,y,z)); 72 mDirty = true; 73 } 74 75 const Vector3& DynamicLines::getPoint(unsigned short index) const 76 { 77 assert(index < mPoints.size() && "Point index is out of bounds!!"); 78 return mPoints[index]; 79 } 80 81 unsigned short DynamicLines::getNumPoints(void) const 82 { 83 return (unsigned short)mPoints.size(); 84 } 85 86 void DynamicLines::setPoint(unsigned short index, const Vector3 &value) 87 { 88 assert(index < mPoints.size() && "Point index is out of bounds!!"); 89 90 mPoints[index] = value; 91 mDirty = true; 92 } 93 94 void DynamicLines::clear() 95 { 96 mPoints.clear(); 97 mDirty = true; 98 } 99 100 void DynamicLines::update() 101 { 102 if (mDirty) 103 fillHardwareBuffers(); 104 } 105 106 void DynamicLines::createVertexDeclaration() 107 { 108 VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration; 109 decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION); 110 } 111 112 void DynamicLines::fillHardwareBuffers() 113 { 114 int size = mPoints.size(); 115 116 prepareHardwareBuffers(size,0); 117 118 if (!size) 119 { 120 mBox.setExtents(Vector3::ZERO,Vector3::ZERO); 121 mDirty=false; 122 return; 123 } 124 125 Vector3 vaabMin = mPoints[0]; 126 Vector3 vaabMax = mPoints[0]; 127 128 HardwareVertexBufferSharedPtr vbuf = 129 mRenderOp.vertexData->vertexBufferBinding->getBuffer(0); 130 131 Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD)); 132 for (int i = 0; i < size; i++) 133 { 134 *prPos++ = mPoints[i].x; 135 *prPos++ = mPoints[i].y; 136 *prPos++ = mPoints[i].z; 137 138 if (mPoints[i].x < vaabMin.x) 139 vaabMin.x = mPoints[i].x; 140 if (mPoints[i].y < vaabMin.y) 141 vaabMin.y = mPoints[i].y; 142 if (mPoints[i].z < vaabMin.z) 143 vaabMin.z = mPoints[i].z; 144 145 if (mPoints[i].x > vaabMax.x) 146 vaabMax.x = mPoints[i].x; 147 if (mPoints[i].y > vaabMax.y) 148 vaabMax.y = mPoints[i].y; 149 if (mPoints[i].z > vaabMax.z) 150 vaabMax.z = mPoints[i].z; 151 } 152 vbuf->unlock(); 153 154 mBox.setExtents(vaabMin, vaabMax); 155 156 mDirty = false; 157 } 158 159 /* 160 void DynamicLines::getWorldTransforms(Matrix4 *xform) const 161 { 162 // return identity matrix to prevent parent transforms 163 *xform = Matrix4::IDENTITY; 164 } 165 */ 166 167 /* 168 const Quaternion &DynamicLines::getWorldOrientation(void) const 169 { 170 return Quaternion::IDENTITY; 171 } 172 173 const Vector3 &DynamicLines::getWorldPosition(void) const 174 { 175 return Vector3::ZERO; 176 } 177 */ 20 178 } 21 22 DynamicLines::~DynamicLines()23 {24 }25 26 void DynamicLines::setOperationType(OperationType opType)27 {28 mRenderOp.operationType = opType;29 }30 31 RenderOperation::OperationType DynamicLines::getOperationType() const32 {33 return mRenderOp.operationType;34 }35 36 void DynamicLines::addPoint(const Vector3 &p)37 {38 mPoints.push_back(p);39 mDirty = true;40 }41 void DynamicLines::addPoint(Real x, Real y, Real z)42 {43 mPoints.push_back(Vector3(x,y,z));44 mDirty = true;45 }46 const Vector3& DynamicLines::getPoint(unsigned short index) const47 {48 assert(index < mPoints.size() && "Point index is out of bounds!!");49 return mPoints[index];50 }51 unsigned short DynamicLines::getNumPoints(void) const52 {53 return (unsigned short)mPoints.size();54 }55 void DynamicLines::setPoint(unsigned short index, const Vector3 &value)56 {57 assert(index < mPoints.size() && "Point index is out of bounds!!");58 59 mPoints[index] = value;60 mDirty = true;61 }62 void DynamicLines::clear()63 {64 mPoints.clear();65 mDirty = true;66 }67 68 void DynamicLines::update()69 {70 if (mDirty) fillHardwareBuffers();71 }72 73 void DynamicLines::createVertexDeclaration()74 {75 VertexDeclaration *decl = mRenderOp.vertexData->vertexDeclaration;76 decl->addElement(POSITION_BINDING, 0, VET_FLOAT3, VES_POSITION);77 }78 79 void DynamicLines::fillHardwareBuffers()80 {81 int size = mPoints.size();82 83 prepareHardwareBuffers(size,0);84 85 if (!size) {86 mBox.setExtents(Vector3::ZERO,Vector3::ZERO);87 mDirty=false;88 return;89 }90 91 Vector3 vaabMin = mPoints[0];92 Vector3 vaabMax = mPoints[0];93 94 HardwareVertexBufferSharedPtr vbuf =95 mRenderOp.vertexData->vertexBufferBinding->getBuffer(0);96 97 Real *prPos = static_cast<Real*>(vbuf->lock(HardwareBuffer::HBL_DISCARD));98 {99 for(int i = 0; i < size; i++)100 {101 *prPos++ = mPoints[i].x;102 *prPos++ = mPoints[i].y;103 *prPos++ = mPoints[i].z;104 105 if(mPoints[i].x < vaabMin.x)106 vaabMin.x = mPoints[i].x;107 if(mPoints[i].y < vaabMin.y)108 vaabMin.y = mPoints[i].y;109 if(mPoints[i].z < vaabMin.z)110 vaabMin.z = mPoints[i].z;111 112 if(mPoints[i].x > vaabMax.x)113 vaabMax.x = mPoints[i].x;114 if(mPoints[i].y > vaabMax.y)115 vaabMax.y = mPoints[i].y;116 if(mPoints[i].z > vaabMax.z)117 vaabMax.z = mPoints[i].z;118 }119 }120 vbuf->unlock();121 122 mBox.setExtents(vaabMin, vaabMax);123 124 mDirty = false;125 }126 127 /*128 void DynamicLines::getWorldTransforms(Matrix4 *xform) const129 {130 // return identity matrix to prevent parent transforms131 *xform = Matrix4::IDENTITY;132 }133 */134 /*135 const Quaternion &DynamicLines::getWorldOrientation(void) const136 {137 return Quaternion::IDENTITY;138 }139 140 const Vector3 &DynamicLines::getWorldPosition(void) const141 {142 return Vector3::ZERO;143 }144 */145 }
Note: See TracChangeset
for help on using the changeset viewer.