[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 ...
随机推荐
- [转自51CTO]ITIL与ISO20000的关系
ITIL它不是一个服务管理标准,而更应该说是一种结构化的方法或流程框架.基于这种方法和框架,已经有越来越多的IT服务管理标准被开发出来了.在这些基于ITIL的IT服务管理标准中,最突出的要属英国标准B ...
- YII 查找View的5种方式
别名开头,路径指定view文件@app/views/site/about.php //开头,使用 app目录下面的views//site/about.php /开头,使用当前Module中的views ...
- CSS3 Transform——transform-origin
2012年9月,W3C组织发布了CSS3变形工作草案.CSS3变形允许CSS把元素转变为2D 或3D空间,这个草案包括了CSS3 2D变形和CSS3 3D变形. CSS3变形是一些效果的集合,比如平移 ...
- ASP.NET MVC3系列页面缓存、缓存依赖SQL(真实项目注意细节)
缓存依赖数据库 第一步 1通过vs里面带的命令提示窗口. 2或者.NET Framework 版本 4(64 位系统)条件,%windir%\Microsoft.NET\Framework64\v4. ...
- Unity4.5版本DLL库名字问题
背景 在unity4.2版本中可以在Android中使用的so链接库,在Unity4.5中使不了-- [DllImport("libclient.so", EntryPoint ...
- 打造 PHP版本 1password
以前注册很多网站密码都使用简单密码,但是由于今年频繁曝出密码不安全问题,所以要使用更加复杂的密码.但是好多个账号,密码也不能设置成一样的,防止一个被盗全部不安全了,记密码就成了意见很头疼的事情. 在手 ...
- css文件内引用外部资源文件的相对路径
1.default.css文件内容(位于css文件夹下): .ClassName .ClassName .ClassName .page-sidebar .sidebar-search .submit ...
- pro10
1.本次课学习到的知识点: 什么是数组?为什么要使用数组?如何定义数组? 如何引用数组元素? 2. 实验过程中遇到的问题及解决方法: 在最后一个试验中,在输出最大小标那里进行了仔细的思考,刚开始思考应 ...
- Mongo中更新总结
mongo中的更新其实也可以当做添加来使用 mongo中跟新有几种方式 save.update.upsert 执行save的时候如果这个文档有_id这个参数,save 会调用 upsert,否则会调用 ...
- Java高级之虚拟机垃圾回收机制
博客出自:http://blog.csdn.net/liuxian13183,转载注明出处! All Rights Reserved ! 区别于C语言手动回收,Java自动执行垃圾回收,但为了执行高效 ...