#include "IndirectRadarEffect.h"
#include <osg/Geode>
#include <osg/Billboard>
#include <osg/Geometry>
#include <iostream>
namespace RadarEffect
{
osg::ref_ptr<osg::Node> createTracingWave(float radius, float height, osg::Vec4& startColor, osg::Vec4& endColor)
{
osg::ref_ptr<osg::Geode> geode = new osg::Geode;
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
geom->setVertexArray(vertices.get());
geom->setColorArray(colors.get());
geom->setColorBinding(osg::Geometry::BIND_PER_VERTEX);
geom->setNormalArray(normals.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
normals->push_back(osg::Vec3(0.0, -1.0, 0.0));
//下后面,保证定点是逆时针
vertices->push_back(osg::Vec3(radius, 0.0, -radius));
vertices->push_back(osg::Vec3(radius, height, -radius));
vertices->push_back(osg::Vec3(-radius, height, -radius));
vertices->push_back(osg::Vec3(-radius, 0.0, -radius));
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
colors->push_back(startColor);
//下前面
vertices->push_back(osg::Vec3(radius, 0.0, -radius));
vertices->push_back(osg::Vec3(-radius, 0.0, -radius));
vertices->push_back(osg::Vec3(-radius, -height, -radius));
vertices->push_back(osg::Vec3(radius, -height, -radius));
colors->push_back(startColor);
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
//左后面
vertices->push_back(osg::Vec3(-radius, 0.0, -radius));
vertices->push_back(osg::Vec3(-radius, height, -radius));
vertices->push_back(osg::Vec3(-radius, height, radius));
vertices->push_back(osg::Vec3(-radius, 0.0, radius));
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
colors->push_back(startColor);
//左前面
vertices->push_back(osg::Vec3(-radius, 0.0, -radius));
vertices->push_back(osg::Vec3(-radius, 0.0, radius));
vertices->push_back(osg::Vec3(-radius, -height, radius));
vertices->push_back(osg::Vec3(-radius, -height, -radius));
colors->push_back(startColor);
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
//上后面
vertices->push_back(osg::Vec3(-radius, 0.0, radius));
vertices->push_back(osg::Vec3(radius, 0.0, radius));
vertices->push_back(osg::Vec3(radius, height, radius));
vertices->push_back(osg::Vec3(-radius, height, radius));
colors->push_back(startColor);
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
//上前面
vertices->push_back(osg::Vec3(-radius, 0.0, radius));
vertices->push_back(osg::Vec3(-radius, -height, radius));
vertices->push_back(osg::Vec3(radius, -height, radius));
vertices->push_back(osg::Vec3(radius, 0.0, radius));
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
colors->push_back(startColor);
//右后面
vertices->push_back(osg::Vec3(radius, 0.0, radius));
vertices->push_back(osg::Vec3(radius, 0.0, -radius));
vertices->push_back(osg::Vec3(radius, height, -radius));
vertices->push_back(osg::Vec3(radius, height, radius));
colors->push_back(startColor);
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
//右前面
vertices->push_back(osg::Vec3(radius, 0.0, radius));
vertices->push_back(osg::Vec3(radius, -height, radius));
vertices->push_back(osg::Vec3(radius, -height, -radius));
vertices->push_back(osg::Vec3(radius, 0.0, -radius));
colors->push_back(startColor);
colors->push_back(endColor);
colors->push_back(endColor);
colors->push_back(startColor);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 0, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 4, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 8, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 12, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 16, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 20, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 24, 4));
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::QUADS, 28, 4));
geode->addDrawable(geom.get());
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
//开启混合
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
return geode.release();
}
//画正弦波
osg::ref_ptr<osg::Node> SincreateTracingWave(osg::Vec3 startPos,osg::Vec3 endPos, float radius, float height, osg::Vec4& startColor, osg::Vec4& endColor,int mul)
{
//osg::ref_ptr<osg::Billboard> geode = new osg::Billboard;
osg::ref_ptr<osg::Geode>geode=new osg::Geode;
osg::ref_ptr<osg::Geometry> geom = new osg::Geometry;
osg::ref_ptr<osg::Vec3Array> vertices = new osg::Vec3Array;
osg::ref_ptr<osg::Vec4Array> colors = new osg::Vec4Array;
osg::ref_ptr<osg::Vec3Array> normals = new osg::Vec3Array;
geom->setVertexArray(vertices.get());
geom->setColorArray(colors.get());
geom->setColorBinding(osg::Geometry::BIND_OVERALL);
geom->setNormalArray(normals.get());
geom->setNormalBinding(osg::Geometry::BIND_OVERALL);
normals->push_back(osg::Vec3(0.0, -1.0, 0.0));
//加入正弦波的所有顶点
double number=200;//一个周期内的采点数,数越大正弦波越精细
double stepX=osg::PI*2/number;//x采点的步长
double x=0;
vertices->push_back(osg::Vec3(x, 0.0,0.0));//加入起始点(0.0,0.0,0.0)
osg::Vec3 temp=endPos-startPos;
double distance=temp.length();//求出两点之间的距离
int r=mul*ceil(distance/(osg::PI*2));//算出所需的周期数,此处乘以10是为了增加单位长度内波形数,最后要缩放10倍,以保持两点间距离不变
for(int i=0;i<number*r;i++)
{
x+=stepX;
vertices->push_back(osg::Vec3(x, 0.0,sin(x)*height));
}
vertices->push_back(osg::Vec3(osg::PI*2*r, 0.0,0.0));
colors->push_back(startColor);
geom->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::LINE_STRIP, 0,vertices->size()));
osg::ref_ptr<osg::LineWidth> linwidth=new osg::LineWidth;
linwidth->setWidth(radius);
geom->getOrCreateStateSet()->setAssociatedModes(linwidth.get(),osg::StateAttribute::ON);
geode->addDrawable(geom.get());
geode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF);
geode->getOrCreateStateSet()->setMode(GL_RESCALE_NORMAL, osg::StateAttribute::ON);
//开启混合
geode->getOrCreateStateSet()->setMode(GL_BLEND, osg::StateAttribute::ON);
//geode->setMode(osg::Billboard::POINT_ROT_EYE);
//geode->setMode(osg::Billboard::AXIAL_ROT);
//temp.normalize();
//geode->setAxis(temp);
return geode.release();
}
///单个跟踪波束回调类
///主要实现思想是:在step个回合内,波束到达终点,然后每次都去计算当前点与终点之间剩余的step数
///然后去得出本次需要前进的距离数
tracingWaveCallback::tracingWaveCallback()
{
}
tracingWaveCallback::tracingWaveCallback(int waveID, osg::Vec3& beginPos, osg::Vec3& endPos, int step, float radius, float height, osg::Vec4& startColor, osg::Vec4& endColor,int kind):
_beginPos(beginPos), _endPos(endPos), _currentPos(beginPos),
_step(step), _sizeStep(1.0 / step), _currentStep(step),
_radius(radius), _height(height),
_startColor(startColor), _endColor(endColor),
_firstAddWave(true), _removeOnce(true), _kind(kind),
_waveID(waveID), _currentCount(0)
{
if(kind==1)_currentSize=0.0;//由小到大的雷达波
if(kind==2)_currentSize=1.0;//由大到小的雷达波
if(kind==3)_current
没有合适的资源?快使用搜索试试~ 我知道了~
用OSG实现的实时仿真的雷达波效果
共53个文件
svn-base:13个
user:6个
manifest:4个
3星 · 超过75%的资源 需积分: 43 278 下载量 32 浏览量
2012-04-07
22:21:57
上传
评论 16
收藏 2.72MB RAR 举报
温馨提示
基于OSG实现的雷达波的实时仿真,有直线传播方式和正弦波方式两种,有各种参数可以调节。
资源推荐
资源详情
资源评论
收起资源包目录
RadarEffect(包含有正弦波,由小到大,由大到小,不变多种情况).rar (53个子文件)
RadarEffect(包含有正弦波,由小到大,由大到小,不变多种情况)
RaderEffectDll.suo 28KB
.svn
tmp
props
prop-base
text-base
props
dir-prop-base 46B
entries 528B
prop-base
RaderEffectDll.suo.svn-base 53B
text-base
RaderEffectDll.sln.svn-base 1KB
RaderEffectDll.suo.svn-base 19KB
RaderEffectDll
RaderEffectDll.vcproj.QingyiZhang-PC.Qingyi Zhang.user 1KB
RaderEffectDll.vcproj.WangCheng-PC.WangCheng.user 1KB
Debug
RaderEffectDll.dll.intermediate.manifest 621B
IndirectRadarEffect.obj 815KB
RaderEffectDll.dll.embed.manifest 663B
vc90.pdb 2.6MB
vc90.idb 1011KB
RaderEffect.obj 153KB
BuildLog.htm 12KB
mt.dep 65B
RaderEffectDll.dll.embed.manifest.res 728B
RaderEffect.cpp 1KB
.svn
tmp
props
prop-base
text-base
props
dir-prop-base 40B
entries 1KB
prop-base
text-base
RaderEffectDll.vcproj.svn-base 4KB
RaderEffect.cpp.svn-base 990B
RadarEffect.h.svn-base 1KB
IndirectRadarEffect.h.svn-base 2KB
RaderEffectDll.vcproj.QingyiZhang-PC.Qingyi Zhang.user.svn-base 1KB
export.h.svn-base 897B
IndirectRadarEffect.cpp.svn-base 8KB
RadarEffect.h 2KB
RaderEffectDll.vcproj.VRSERVER.VRLab.user 1KB
RaderEffectDll.vcproj 4KB
IndirectRadarEffect.h 3KB
IndirectRadarEffect.cpp 16KB
export.h 897B
RaderEffectDll.sln 1KB
RaderEffectDll.ncb 5.44MB
TestEffect
Debug
TestEffect.exe.intermediate.manifest 621B
vc90.pdb 5.08MB
vc90.idb 1.41MB
TestEffect.exe.embed.manifest.res 728B
BuildLog.htm 6KB
mt.dep 65B
main.obj 576KB
TestEffect.exe.embed.manifest 663B
.svn
tmp
props
prop-base
text-base
props
dir-prop-base 40B
entries 665B
prop-base
text-base
TestEffect.vcproj.svn-base 4KB
TestEffect.vcproj.QingyiZhang-PC.Qingyi Zhang.user.svn-base 1KB
main.cpp.svn-base 2KB
TestEffect.vcproj 4KB
main.cpp 3KB
TestEffect.vcproj.WangCheng-PC.WangCheng.user 1KB
TestEffect.vcproj.VRSERVER.VRLab.user 1KB
TestEffect.vcproj.QingyiZhang-PC.Qingyi Zhang.user 1KB
共 53 条
- 1
事业有成的爱
- 粉丝: 5
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
- 1
- 2
- 3
- 4
前往页