数据实体:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using SlimDX;
using RGeos.SlimScene.Core; namespace RGeos.Framework.OTL.Geometries
{ /// <summary>
/// LineString.
/// </summary>
public class LineString
{
public Point3d[] Coordinates = null;
public Color Color = Color.Yellow;
public float LineWidth = 1.0f;
public bool Visible = true;
public bool Remove = false;
public RenderableObject ParentRenderable = null; public BoundingBox GetBoundingBox()
{
if (Coordinates == null || Coordinates.Length == )
return new BoundingBox(); double minX = Coordinates[].X;
double maxX = Coordinates[].X;
double minY = Coordinates[].Y;
double maxY = Coordinates[].Y;
double minZ = Coordinates[].Z;
double maxZ = Coordinates[].Z; for (int i = ; i < Coordinates.Length; i++)
{
if (Coordinates[i].X < minX)
minX = Coordinates[i].X;
if (Coordinates[i].X > maxX)
maxX = Coordinates[i].X; if (Coordinates[i].Y < minY)
minY = Coordinates[i].Y;
if (Coordinates[i].Y > maxY)
maxY = Coordinates[i].Y; if (Coordinates[i].Z < minZ)
minZ = Coordinates[i].Z;
if (Coordinates[i].Z > maxZ)
maxZ = Coordinates[i].Z;
} return new BoundingBox(new Vector3(
(float)maxY, (float)minY, (float)minX), new Vector3((float)maxX, (float)minZ, (float)maxZ));
}
} }

LineString

渲染对象

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RGeos.SlimScene.Core;
using SlimDX.Direct3D9;
using SlimDX; namespace RGeos.Framework.OTL.Geometries
{
public class RenderableLineString : RenderableObject
{
#region Static Members
#endregion #region Private Members
double m_distanceAboveSurface = ;
Point3d[] m_points = null;
CustomVertex.PositionColoredTextured[] m_wallVertices = null; CustomVertex.PositionColored[] m_topVertices = null;
CustomVertex.PositionColored[] m_bottomVertices = null;
CustomVertex.PositionColored[] m_sideVertices = null; System.Drawing.Color m_lineColor = System.Drawing.Color.Black;
float m_verticalExaggeration = ;
double m_minimumDisplayAltitude = ;
double m_maximumDisplayAltitude = double.MaxValue;
string m_imageUri = null;
Texture m_texture = null;
System.Drawing.Color m_polygonColor = System.Drawing.Color.Black;
bool m_outline = true;
float m_lineWidth = 1.0f;
bool m_extrude = false;
AltitudeMode m_altitudeMode = AltitudeMode.Absolute;
long m_numPoints = ;
#endregion /// <summary>
/// Boolean indicating whether or not the line needs rebuilding.
/// </summary>
public bool NeedsUpdate = true; public bool Extrude
{
get { return m_extrude; }
set { m_extrude = value; }
} public AltitudeMode AltitudeMode
{
get { return m_altitudeMode; }
set { m_altitudeMode = value; }
} public System.Drawing.Color LineColor
{
get { return m_lineColor; }
set
{
m_lineColor = value;
NeedsUpdate = true;
}
} public float LineWidth
{
get { return m_lineWidth; }
set
{
m_lineWidth = value;
NeedsUpdate = true;
}
} public double DistanceAboveSurface
{
get { return m_distanceAboveSurface; }
set
{
m_distanceAboveSurface = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public System.Drawing.Color PolygonColor
{
get { return m_polygonColor; }
set
{
m_polygonColor = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public bool Outline
{
get { return m_outline; }
set
{
m_outline = value;
if (m_topVertices != null)
{
NeedsUpdate = true;
//UpdateVertices();
}
}
} public Point3d[] Points
{
get
{
// if the array size is correct just return it
if (m_numPoints == m_points.LongLength)
return m_points; // return an array the correct size.
Point3d[] points = new Point3d[m_numPoints];
for (int i = ; i < m_numPoints; i++)
{
points[i] = m_points[i];
}
return points;
}
set
{
m_points = value;
m_numPoints = m_points.LongLength;
NeedsUpdate = true;
}
} public long NumPoints
{
get { return m_numPoints; }
} public double MinimumDisplayAltitude
{
get { return m_minimumDisplayAltitude; }
set { m_minimumDisplayAltitude = value; }
} public double MaximumDisplayAltitude
{
get { return m_maximumDisplayAltitude; }
set { m_maximumDisplayAltitude = value; }
} public override byte Opacity
{
get
{
return base.Opacity;
}
set
{
base.Opacity = value;
if (m_topVertices != null)
{
UpdateVertices();
}
}
} public RenderableLineString(string name, World parentWorld, Point3d[] points, System.Drawing.Color lineColor)
: base(name, parentWorld)
{
m_points = points;
m_lineColor = lineColor;
m_polygonColor = lineColor;
m_numPoints = m_points.LongLength; // RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
} public RenderableLineString(string name, World parentWorld, Point3d[] points, string imageUri)
: base(name, parentWorld)
{
m_points = points;
m_imageUri = imageUri;
m_numPoints = m_points.LongLength; // RenderPriority = WorldWind.Renderable.RenderPriority.LinePaths;
} public override void Dispose()
{
if (m_texture != null && !m_texture.Disposed)
{
m_texture.Dispose();
m_texture = null;
} if (m_lineString != null)
{
m_lineString.Remove = true;
m_lineString = null;
}
NeedsUpdate = true;
} public override void Initialize(DrawArgs drawArgs)
{
if (m_points == null)
{
isInitialized = true;
return;
} if (m_imageUri != null)
{
//load image
//if (m_imageUri.ToLower().StartsWith("http://"))
//{
// string savePath = string.Format("{0}\\image", ConfigurationLoader.GetRenderablePathString(this));
// System.IO.FileInfo file = new System.IO.FileInfo(savePath);
// if (!file.Exists)
// {
// WorldWind.Net.WebDownload download = new WorldWind.Net.WebDownload(m_imageUri); // if (!file.Directory.Exists)
// file.Directory.Create(); // download.DownloadFile(file.FullName, WorldWind.Net.DownloadType.Unspecified);
// } // m_texture = ImageHelper.LoadTexture(file.FullName);
//}
//else
//{
// m_texture = ImageHelper.LoadTexture(m_imageUri);
//}
} UpdateVertices(); isInitialized = true;
} /// <summary>
/// Adds a point to the line at the end of the line.
/// </summary>
/// <param name="point">The Point3d object to add.</param>
public void AddPoint(Point3d point)
{
// if the array is too small grow it.
if (m_numPoints >= m_points.LongLength)
{
long growSize = m_points.LongLength / ;
if (growSize < ) growSize = ; Point3d[] points = new Point3d[m_points.LongLength + growSize]; for (int i = ; i < m_numPoints; i++)
{
points[i] = m_points[i];
}
m_points = points;
}
m_points[m_numPoints] = point;
m_numPoints++;
NeedsUpdate = true;
} private void UpdateVertices()
{
try
{
// m_verticalExaggeration = World.Settings.VerticalExaggeration; UpdateTexturedVertices(); if (m_lineString != null && m_outline && m_wallVertices != null && m_wallVertices.Length > m_topVertices.Length)
{
UpdateOutlineVertices();
} NeedsUpdate = false;
}
catch (Exception ex)
{
Utility.Log.Write(ex);
}
} private void UpdateOutlineVertices()
{
m_bottomVertices = new CustomVertex.PositionColored[m_numPoints];
m_sideVertices = new CustomVertex.PositionColored[m_numPoints * ]; for (int i = ; i < m_numPoints; i++)
{
m_sideVertices[ * i] = m_topVertices[i]; Vector3 xyzVertex = new Vector3(
m_wallVertices[ * i + ].Position.X,
m_wallVertices[ * i + ].Position.Y,
m_wallVertices[ * i + ].Position.Z); m_bottomVertices[i].Position.X = xyzVertex.X;
m_bottomVertices[i].Position.Y = xyzVertex.Y;
m_bottomVertices[i].Position.Z = xyzVertex.Z;
m_bottomVertices[i].Color = m_lineColor.ToArgb(); m_sideVertices[ * i + ] = m_bottomVertices[i];
}
} LineString m_lineString = null;
private void UpdateTexturedVertices()
{
if (m_altitudeMode == AltitudeMode.ClampedToGround)
{
if (m_lineString != null)
{
m_lineString.Remove = true;
m_lineString = null;
} m_lineString = new LineString();
m_lineString.Coordinates = Points;
m_lineString.Color = LineColor;
m_lineString.LineWidth = LineWidth;
m_lineString.ParentRenderable = this;
// this.World.ProjectedVectorRenderer.Add(m_lineString); if (m_wallVertices != null)
m_wallVertices = null; return;
} if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
{
m_wallVertices = new CustomVertex.PositionColoredTextured[m_numPoints * ];
} float textureCoordIncrement = 1.0f / (float)(m_numPoints - );
// m_verticalExaggeration = World.Settings.VerticalExaggeration;
int vertexColor = m_polygonColor.ToArgb(); m_topVertices = new CustomVertex.PositionColored[m_numPoints]; for (int i = ; i < m_numPoints; i++)
{
double terrainHeight = ; Vector3 xyzVertex = new Vector3((float)m_points[i].X, (float)m_points[i].Y, (float)m_points[i].Z); m_topVertices[i].Position.X = xyzVertex.X;
m_topVertices[i].Position.Y = xyzVertex.Y;
m_topVertices[i].Position.Z = xyzVertex.Z;
m_topVertices[i].Color = m_lineColor.ToArgb(); if (m_extrude || m_altitudeMode == AltitudeMode.RelativeToGround)
{
m_wallVertices[ * i].Position.X = xyzVertex.X;
m_wallVertices[ * i].Position.Y = xyzVertex.Y;
m_wallVertices[ * i].Position.Z = xyzVertex.Z;
m_wallVertices[ * i].Color = vertexColor;
m_wallVertices[ * i].Tu = i * textureCoordIncrement;
m_wallVertices[ * i].Tv = 1.0f; m_wallVertices[ * i + ].Position.X = xyzVertex.X;
m_wallVertices[ * i + ].Position.Y = xyzVertex.Y;
m_wallVertices[ * i + ].Position.Z = xyzVertex.Z;
m_wallVertices[ * i + ].Color = vertexColor;
m_wallVertices[ * i + ].Tu = i * textureCoordIncrement;
m_wallVertices[ * i + ].Tv = 0.0f;
}
}
} public override bool PerformSelectionAction(DrawArgs drawArgs)
{
return false;
} public override void Update(DrawArgs drawArgs)
{
if (drawArgs.WorldCamera.Distance >= m_minimumDisplayAltitude && drawArgs.WorldCamera.Distance <= m_maximumDisplayAltitude)
{
if (!isInitialized)
Initialize(drawArgs); if (NeedsUpdate)
UpdateVertices();
} } public override void Render(DrawArgs drawArgs)
{
if (!isInitialized || drawArgs.WorldCamera.Distance < m_minimumDisplayAltitude || drawArgs.WorldCamera.Distance > m_maximumDisplayAltitude)
{
return;
} try
{
if (m_lineString != null)
return; int currentCull = drawArgs.Device.GetRenderState(RenderState.CullMode);
drawArgs.Device.SetRenderState(RenderState.CullMode, Cull.None); if (m_wallVertices != null)
{
drawArgs.Device.SetRenderState(RenderState.ZEnable, true); if (m_texture != null && !m_texture.Disposed)
{
drawArgs.Device.SetTexture(, m_texture);
drawArgs.Device.SetTextureStageState(, TextureStage.AlphaOperation, TextureOperation.Modulate);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Add);
drawArgs.Device.SetTextureStageState(, TextureStage.AlphaArg1, TextureArgument.Texture);
}
else
{
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
} drawArgs.Device.VertexFormat = CustomVertex.PositionColoredTextured.Format; drawArgs.Device.DrawUserPrimitives(PrimitiveType.TriangleStrip, m_wallVertices.Length - , m_wallVertices); if (m_outline)
{ drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
drawArgs.Device.VertexFormat = CustomVertex.PositionColored.Format;
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - , m_topVertices); if (m_bottomVertices != null)
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_bottomVertices.Length - , m_bottomVertices); if (m_sideVertices != null)
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineList, m_sideVertices.Length / , m_sideVertices); }
}
else
{
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, TextureOperation.Disable);
drawArgs.Device.VertexFormat = CustomVertex.PositionColored.Format;
drawArgs.Device.DrawUserPrimitives(PrimitiveType.LineStrip, m_topVertices.Length - , m_topVertices);
} drawArgs.Device.SetTransform(TransformState.World, drawArgs.WorldCamera.WorldMatrix);
drawArgs.Device.SetRenderState(RenderState.CullMode, currentCull);
}
catch//(Exception ex)
{
//Utility.Log.Write(ex);
}
}
}
}

RenderableLineString

使用方法:

 private void tspPolyline_Click(object sender, EventArgs e)
{
Point3d[] pts=new Point3d[];
Point3d pt1=new Point3d(,,);
Point3d pt2=new Point3d(,,);
Point3d pt3=new Point3d(,,);
Point3d pt4=new Point3d(,,);
Point3d pt5=new Point3d(,,);
pts[]=pt1;
pts[]=pt2;
pts[]=pt3;
pts[]=pt4;
pts[]=pt5;
RenderableLineString rend = new RenderableLineString("Hello", null, pts, Color.White);
rend.IsOn = true;
rend.RenderPriority = RenderPriority.Custom;
mSceneControl.CurrentWorld.RenderableObjects.ChildObjects.Add(rend);
}

[3D]绘制线的更多相关文章

  1. Unity3D研究院之游戏对象的访问绘制线与绘制面详解(十七)

    一眨眼学习Unity3D 也有一段时间了,基本已经拿下了这套游戏引擎,回过头来想想以前写的RPG 游戏引擎,越来越发现以前写的就是垃圾.人果然是要不断学习与不断进步,好好学习,天天向上.哇咔咔- 加油 ...

  2. 《每周一点canvas动画》——3D点线与水波动画

    <每周一点canvas动画>--差分函数的妙用 每周一点canvas动画代码文件 好像上次更新还是十一前,这唰唰唰的就过去大半个月了,现在才更新实在不好意思.这次我们不涉及canvas 3 ...

  3. R绘图 第六篇:绘制线图(ggplot2)

    线图是由折线构成的图形,线图是把散点从左向右用直线连接起来而构成的图形,在以时间序列为x轴的线图中,可以看到数据增长的趋势. geom_line(mapping = NULL, data = NULL ...

  4. 3D 室内装修线设计软件

    3D 室内装修线设计软件 WebGL & canvas https://threejs.org/ xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用 ...

  5. 3D车道线检测:Gen-LaneNet

    3D车道线检测:Gen-LaneNet Gen-LaneNet: A Generalized and Scalable Approach for 3D Lane Detection 论文链接:http ...

  6. canvas绘制线和矩形

    ###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...

  7. unity绘制线和绘制面

    绘制线条代码,其实就是指定至少两个点,然后赋予贴图即可,不废话,上代码: using UnityEngine; using System.Collections; public class LineT ...

  8. [3D]绘制XYZ小坐标轴

    源码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Slim ...

  9. Marble 绘制线

    #include <QtGui/QApplication> #include <marble/MarbleWidget.h> #include <marble/GeoPa ...

随机推荐

  1. 虚拟机下CentOS找不到网卡eth0的解决方法

    1. vi /etc/sysconfig/network-scripts/ifcfg-eth0 2. 将其中的ONBOOT属性改成yes即可   2015-8-3更新: 今天发现通过VirtualBo ...

  2. Beetl2.2使用说明书20151201

    李家智<xiandafu@126.com> Table of Contents 1. 什么是Beetl 2. 基本用法 2.1. 从GroupTemplate开始 2.2. 模板基础配置 ...

  3. Grunt教程——初涉Grunt

    前端自动化,这样的一个名词听起来非常的有吸引力,向往力.当今时代,前端工程师需要维护的代码变得及为庞大和复杂,代码维护.打包.发布等流程也 变得极为繁琐,同时浪费的时间和精力也越来越多,当然人为的错误 ...

  4. PowerCmd-cmd命令行管理工具

    缘由 看了大漠在慕课网关于angular的讲解,用到了PowerCmd.就百度一下准备下载,很小很实用的工具,发现有人总结了.备忘 http://www.cnblogs.com/xing901022/ ...

  5. 【翻译】CEDEC2013 BANDAI NAMCO 了解游戏格斗动画中的身体运动结构和原理

    CEDEC搬运工程开始~   这篇会议PPT的作者 元梅幸司曾经就职在TECMO参与开发了死或生2,3[ DEAD OR ALIVE],忍龙「NINJA GAIDEN」后来加入NAMCO(现在是BAN ...

  6. Windows与Linux/Mac系统时间不一致的解决方法

    Windows与Linux/Mac系统时间不一致的解决方法 分类: linux2012-02-12 14:25 1691人阅读 评论(1) 收藏 举报 windowsubuntusystemlinux ...

  7. HAProxy安装及初步使用

    1.yum安装wget http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpmrpm -ivh epel-r ...

  8. Arrays.toString Arrays.asList

    import java.util.Arrays; public class TestCalc{ public static void main(String[] args) { ,,,,,,,}; / ...

  9. android导入项目出现R文件不能生成

    关于原因网上有好多,比如 1.有时候eclipse不自动编译,把project clean一下,让R.java重新生成   2.选择菜单  Project >> Clean ,前提是勾选上 ...

  10. Java高级之内存模型分析

    博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 下文是博主感悟,请带着怀疑性的态度阅读! 需要了解基本变量所占 ...