[3D]绘制线
数据实体:
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]绘制线的更多相关文章
- Unity3D研究院之游戏对象的访问绘制线与绘制面详解(十七)
一眨眼学习Unity3D 也有一段时间了,基本已经拿下了这套游戏引擎,回过头来想想以前写的RPG 游戏引擎,越来越发现以前写的就是垃圾.人果然是要不断学习与不断进步,好好学习,天天向上.哇咔咔- 加油 ...
- 《每周一点canvas动画》——3D点线与水波动画
<每周一点canvas动画>--差分函数的妙用 每周一点canvas动画代码文件 好像上次更新还是十一前,这唰唰唰的就过去大半个月了,现在才更新实在不好意思.这次我们不涉及canvas 3 ...
- R绘图 第六篇:绘制线图(ggplot2)
线图是由折线构成的图形,线图是把散点从左向右用直线连接起来而构成的图形,在以时间序列为x轴的线图中,可以看到数据增长的趋势. geom_line(mapping = NULL, data = NULL ...
- 3D 室内装修线设计软件
3D 室内装修线设计软件 WebGL & canvas https://threejs.org/ xgqfrms 2012-2020 www.cnblogs.com 发布文章使用:只允许注册用 ...
- 3D车道线检测:Gen-LaneNet
3D车道线检测:Gen-LaneNet Gen-LaneNet: A Generalized and Scalable Approach for 3D Lane Detection 论文链接:http ...
- canvas绘制线和矩形
###canvas绘制矩形 HTML中的元素canvas只支持一种原生的图形绘制:矩形.所有其他的图形的绘制都至少需要生成一条路径 1.绘制矩形 canvas提供了三种方法绘制矩形: ----> ...
- unity绘制线和绘制面
绘制线条代码,其实就是指定至少两个点,然后赋予贴图即可,不废话,上代码: using UnityEngine; using System.Collections; public class LineT ...
- [3D]绘制XYZ小坐标轴
源码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Slim ...
- Marble 绘制线
#include <QtGui/QApplication> #include <marble/MarbleWidget.h> #include <marble/GeoPa ...
随机推荐
- OC中属性及方法
1.声明式属性 a.实例变量 b.声明属性 自动生成setter/getter方法 .h ->@property 属性类型 属性名; .m ...
- git基础及分支
关于版本控制 git是一种分布版本控制系统,每一主机都保存了完整副本.必杀技是分支. 在Windows可安装git客户端msysgit. git基础 第一次看progit觉得有点不懂,不懂版本控制,一 ...
- cURL 学习笔记与总结(2)网页爬虫、天气预报
例1.一个简单的 curl 获取百度 html 的爬虫程序(crawler): spider.php <?php /* 获取百度html的简单网页爬虫 */ $curl = curl_init( ...
- Bit-Value Type
https://dev.mysql.com/doc/refman/5.7/en/bit-type.html MySQL 5.7 Reference Manual / ... / Bit-Val ...
- C#数组的排序
对于数组的排序有好多种方法,上面这种是最常规的方法,当然在Array类中有两个方法就是专门来完成排序的,一会我们再来看这两方法,下面我们还是来看一下语法吧,只要搞懂语法了,就可以自己随便排序了. 冒泡 ...
- 微信公众账号开发教程(三) 实例入门:机器人(附源码) ——转自http://www.cnblogs.com/yank/p/3409308.html
一.功能介绍 通过微信公众平台实现在线客服机器人功能.主要的功能包括:简单对话.查询天气等服务. 这里只是提供比较简单的功能,重在通过此实例来说明公众平台的具体研发过程.只是一个简单DEMO,如果需要 ...
- Redis学习笔记(4)-List
package cn.com; import java.util.List; import redis.clients.jedis.Jedis; import redis.clients.jedis. ...
- 介绍UDF,以及完成大小写的转换
一:概述 1.UDF 用户自定义函数,用java实现自定义的需求 2.UDF的类型 udf:一进一出 udaf:多进一出 udtf:一进多出 3.udf的实现步骤 继承UDF类 实现evaluate的 ...
- java中关于集合的知识点梳理
一:概述 1.集合的特点 只存储对象,集合长度是可变的,集合可以存储不同类型的对象. 2.集合框架 Collection List | | Set ArrayList Linked ...
- C++ 实现 发送HTTP Get/Post请求 good
1.简述 最近简单看了一下关于HTTP请求方面的知识,之前一直用Qt来实现,有专门HTTP请求的QNetworkAccessManager类来处理,实现也比较简单,这里主要讲解一下用C++代码来实现H ...