10SLines::SLines(
const Ogre::ColourValue& defaultColour,
bool dashed,
bool disableDepth) : SimpleRenderable()
12 colour = defaultColour;
14 mRenderOp.vertexData =
new Ogre::VertexData();
15 mRenderOp.indexData = 0;
16 mRenderOp.vertexData->vertexCount = 0;
17 mRenderOp.vertexData->vertexStart = 0;
18 mRenderOp.operationType = Ogre::RenderOperation::OT_LINE_LIST;
19 mRenderOp.useIndexes =
false;
23 if (!_material_created)
25 Ogre::StringVector resourceGroups = Ogre::ResourceGroupManager::getSingletonPtr()->getResourceGroups();
26 if(std::find(resourceGroups.begin(), resourceGroups.end(), SO3_INTERNAL_RESOURCE_GROUP) == resourceGroups.end())
27 Ogre::ResourceGroupManager::getSingletonPtr()->createResourceGroup(SO3_INTERNAL_RESOURCE_GROUP);
29 Ogre::MaterialPtr autocolour = Ogre::MaterialManager::getSingleton().create(std::string(SO3_INTERNAL_RESOURCE_GROUP)+
"/LineAuto", SO3_INTERNAL_RESOURCE_GROUP);
30 autocolour->setReceiveShadows(
false);
31 autocolour->getTechnique(0)->setLightingEnabled(
true);
32 autocolour->getTechnique(0)->getPass(0)->setVertexProgram(
"SO3/VS/LINECUSTOMCOLOR");
33 autocolour->getTechnique(0)->getPass(0)->setFragmentProgram(
"SO3/FP/LINECUSTOMCOLOR");
35 Ogre::MaterialPtr autocolournodepth = Ogre::MaterialManager::getSingleton().create(std::string(SO3_INTERNAL_RESOURCE_GROUP) +
"/LineAutoNoDepth", SO3_INTERNAL_RESOURCE_GROUP);
36 autocolournodepth->setReceiveShadows(
false);
37 autocolournodepth->getTechnique(0)->setLightingEnabled(
true);
38 autocolournodepth->getTechnique(0)->setDepthFunction(Ogre::CMPF_ALWAYS_PASS);
39 autocolournodepth->getTechnique(0)->getPass(0)->setVertexProgram(
"SO3/VS/LINECUSTOMCOLOR");
40 autocolournodepth->getTechnique(0)->getPass(0)->setFragmentProgram(
"SO3/FP/LINECUSTOMCOLOR");
41 _material_created =
true;
44 setCastShadows(
false);
45 std::string matName = (disableDepth) ?
"/LineAutoNoDepth" :
"/LineAuto";
46 Ogre::MaterialPtr linemat = Ogre::MaterialManager::getSingleton().getByName(std::string(SO3_INTERNAL_RESOURCE_GROUP) + matName, SO3_INTERNAL_RESOURCE_GROUP);
48 setCustomParameter(0, Ogre::Vector4(colour.r, colour.g, colour.b, colour.a));
189 if (_drawn || _points.size() < 2)
195 mRenderOp.vertexData->vertexCount = (_points.size() * 2) - 2;
197 Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
198 Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
201 bind->unsetAllBindings();
204 decl->removeAllElements();
205 size_t currOffset = 0;
208 decl->addElement(0, currOffset, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
209 currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT3);
211 decl->addElement(0, currOffset, Ogre::VET_FLOAT2, Ogre::VES_TEXTURE_COORDINATES, 0);
212 currOffset += Ogre::VertexElement::getTypeSize(Ogre::VET_FLOAT2);
215 Ogre::HardwareVertexBufferSharedPtr vbuf;
216 vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(0),
217 mRenderOp.vertexData->vertexCount,
218 Ogre::HardwareBuffer::HBU_DYNAMIC);
219 bind->setBinding(0, vbuf);
223 unsigned int size = (
unsigned int)_points.size();
224 unsigned char* pVert =
static_cast<unsigned char*
>(vbuf->lock(Ogre::HardwareBuffer::HBL_WRITE_ONLY));
225 for(
unsigned int i = 0; i < size; i++)
228 decl->getElement(0)->baseVertexPointerToElement(pVert, &pFloat);
229 *pFloat++ = _points[i].x;
230 *pFloat++ = _points[i].y;
231 *pFloat++ = _points[i].z;
238 pVert += vbuf->getVertexSize();
241 if ((i != 0) && (i < size - 1))
244 decl->getElement(0)->baseVertexPointerToElement(pVert, &pFloat);
245 *pFloat++ = _points[i].x;
246 *pFloat++ = _points[i].y;
247 *pFloat++ = _points[i].z;
254 pVert += vbuf->getVertexSize();
264 if (_drawn || _points.empty())
269 mRenderOp.vertexData->vertexCount = _points.size();
271 Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration;
272 Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding;
275 bind->unsetAllBindings();
278 decl->removeAllElements();
279 decl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION);
281 Ogre::HardwareVertexBufferSharedPtr vbuf;
282 vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer(decl->getVertexSize(0),
283 mRenderOp.vertexData->vertexCount,
284 Ogre::HardwareBuffer::HBU_DYNAMIC);
285 bind->setBinding(0, vbuf);
289 unsigned int size = (
unsigned int)_points.size();
290 unsigned char* pVert =
static_cast<unsigned char*
>(vbuf->lock(Ogre::HardwareBuffer::HBL_WRITE_ONLY));
291 for(
unsigned int i = 0; i < size; i++)
294 decl->getElement(0)->baseVertexPointerToElement(pVert, &pFloat);
295 *pFloat++ = _points[i].x;
296 *pFloat++ = _points[i].y;
297 *pFloat = _points[i].z;
300 pVert += vbuf->getVertexSize();
309 Ogre::Vector3 vMin, vMax, vMid, vDist;
310 vMin = mBox.getMinimum();
311 vMax = mBox.getMaximum();
312 vMid = ((vMin - vMax) * 0.5) + vMin;
313 vDist = cam->getDerivedPosition() - vMid;
315 return vDist.squaredLength();