数据实体:

 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. C#安全API

    Bouncycastle库C#版 官网地址为:http://www.bouncycastle.org/csharp/. http://blog.csdn.net/popozhu/article/det ...

  2. [IT新应用]存储入门-文件级存储及块级别存储的选择

    http://www.techrepublic.com/blog/the-enterprise-cloud/block-level-storage-vs-file-level-storage-a-co ...

  3. [项目机会]citrix 虚拟桌面对于java等高CPU占用率如何解决

    citrix 虚拟桌面对于java等高CPU占用率如何解决 问题1:java等客户端对于虚拟桌面cpu影响较大,但是有些用户的确需要使用java支持的程序,是否可以通过其他途径来解决? 问题2:对于其 ...

  4. 【Objective-C】Windows下Objective-C开发环境配置

    [Objective-C]Windows下Objective-C开发环境配置 ftp://ftpmain.gnustep.org/pub/gnustep/binaries/windows/   最近打 ...

  5. 达内培训:php在线端口扫描器

    达内培训:php在线端口扫描器 [来源] 达内    [编辑] 达内   [时间]2012-12-21 这个扫描器很简单.就是用了一个数组来定义端口的相关信息,原理就是用fsockopen函数连接,如 ...

  6. VPN服务器环境搭建

    一.VPN服务器环境说明 操作系统:CentOS release 6.4 (Final) 本地网卡: 复制代码 代码如下: # ifconfig em1 Link encap:Ethernet HWa ...

  7. laravel authorize(授权)

    1.方法一  直接在AuthServiceProvider 中定义闭包,比较灵活 namespace App\Providers; ... class AuthServiceProvider exte ...

  8. 拼写纠正 Artificial Intelligence: A Modern Approach

    Artificial Intelligence: A Modern Approach http://mindhacks.cn/2008/09/21/the-magical-bayesian-metho ...

  9. 关于C和C++动态链接库的几个问题

    问题: 1.写一段C++程序,编译成动态链接库后,C程序怎么访问? 2.写一段C程序,编译成动态链接库后,C++程序怎么访问? 3.写一个类,编译成动态链接库后,里面的public变量能否访问? 对于 ...

  10. Sandbox 文件存放规则

    文档1, document2,  document3 一.文件路径介绍 <Application_Home>/AppName.app : 1) This is the bundle dir ...