84 lines
1.7 KiB
C++
84 lines
1.7 KiB
C++
|
|
#include "effects/DottedLine.h"
|
|||
|
|
|
|||
|
|
#include <algorithm>
|
|||
|
|
#include <math.h>
|
|||
|
|
#include <osg/Drawable>
|
|||
|
|
#include <osg/Geometry>
|
|||
|
|
#include <osg/CullFace>
|
|||
|
|
#include <osg/Depth>
|
|||
|
|
#include <osg/LineWidth>
|
|||
|
|
|
|||
|
|
DottedLine::DottedLine(ElectricWave* pElectricWave)
|
|||
|
|
: TrackWave(pElectricWave),width_(10),m_i(1)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
DottedLine::~DottedLine(void)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>
|
|||
|
|
void DottedLine::SetWidth(int nWidth)
|
|||
|
|
{
|
|||
|
|
width_ = nWidth;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD>ÿ<EFBFBD><C3BF><EFBFBD>
|
|||
|
|
int DottedLine::GetWidth(void)
|
|||
|
|
{
|
|||
|
|
return (width_);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʼ<EFBFBD><CABC><EFBFBD>յ<EFBFBD>
|
|||
|
|
void DottedLine::SetStartAndEnd(const osg::Vec3d& vStart, const osg::Vec3d& vEnd)
|
|||
|
|
{
|
|||
|
|
TrackWave::SetStartAndEnd(vStart, vEnd);
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڵ<EFBFBD>
|
|||
|
|
temp_ = vEnd - vStart;
|
|||
|
|
temp_.normalize();;
|
|||
|
|
height_ = temp_;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void DottedLine::CreateSingleVertex(double index, osg::Vec3dArray* pVertexArray)
|
|||
|
|
{
|
|||
|
|
double fHeight = index * (m_fLoopHeight + m_fSpaceHeight) + m_fLoopHeight + m_fdHeight;
|
|||
|
|
|
|||
|
|
if (((fHeight - m_fLoopHeight) >= m_fHeight) || ((fHeight - m_fLoopHeight) <= -m_fHeight))
|
|||
|
|
{
|
|||
|
|
fHeight -= m_fHeight;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
double ftemp = fHeight;
|
|||
|
|
//<2F>ж<EFBFBD>ֵ<EFBFBD><D6B5>Ч
|
|||
|
|
if (ftemp >= m_fHeight )
|
|||
|
|
{
|
|||
|
|
ftemp = m_fHeight;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
osg::Vec3d vTop = height_ * ftemp;
|
|||
|
|
ftemp = fHeight - m_fLoopHeight;
|
|||
|
|
|
|||
|
|
osg::Vec3d vBotton = height_ * ftemp;
|
|||
|
|
pVertexArray->push_back(vTop + m_vStart);
|
|||
|
|
pVertexArray->push_back(vBotton + m_vStart );
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
void DottedLine::CreatePrimitiveSet(osg::Geometry* pGeometry, int nStart, int nCount)
|
|||
|
|
{
|
|||
|
|
pGeometry->removePrimitiveSet(0, pGeometry->getNumPrimitiveSets());
|
|||
|
|
pGeometry->addPrimitiveSet(new osg::DrawArrays(GL_LINES, 0, nCount));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
void DottedLine::SetStateSet(osg::StateSet* pStateSet)
|
|||
|
|
{
|
|||
|
|
TrackWave::SetStateSet(pStateSet);
|
|||
|
|
|
|||
|
|
osg::LineWidth* pLineWidth = new osg::LineWidth(width_);
|
|||
|
|
pStateSet->setAttributeAndModes(pLineWidth);
|
|||
|
|
|
|||
|
|
}
|