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)
|
|
{
|
|
}
|
|
|
|
// 设置宽度
|
|
void DottedLine::SetWidth(int nWidth)
|
|
{
|
|
width_ = nWidth;
|
|
}
|
|
|
|
// 获得宽度
|
|
int DottedLine::GetWidth(void)
|
|
{
|
|
return (width_);
|
|
}
|
|
|
|
// 设置起始和终点
|
|
void DottedLine::SetStartAndEnd(const osg::Vec3d& vStart, const osg::Vec3d& vEnd)
|
|
{
|
|
TrackWave::SetStartAndEnd(vStart, vEnd);
|
|
|
|
// 设置向量节点
|
|
temp_ = vEnd - vStart;
|
|
temp_.normalize();;
|
|
height_ = temp_;
|
|
}
|
|
|
|
// 获得数据
|
|
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;
|
|
//判断值有效
|
|
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));
|
|
}
|
|
|
|
// 获得属性
|
|
void DottedLine::SetStateSet(osg::StateSet* pStateSet)
|
|
{
|
|
TrackWave::SetStateSet(pStateSet);
|
|
|
|
osg::LineWidth* pLineWidth = new osg::LineWidth(width_);
|
|
pStateSet->setAttributeAndModes(pLineWidth);
|
|
|
|
}
|