源码:

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SlimDX;
using RGeos.SlimScene.Core;
using SlimDX.Direct3D9;
using System.Drawing; namespace RGeos.SlimScene.Renderable
{
public class Axis : IRenderable
{
public bool IsOn = true;
public bool IsInitialize = false;
public Mesh mMeshArrow = null;
public Mesh mMeshStick = null;
private Material material;//定义材质变量
private Material materialStick;//定义材质变量
public void Initialize(DrawArgs drawArgs)
{
if (IsOn && !IsInitialize)
{
mMeshArrow = Mesh.CreateCylinder(drawArgs.Device, 1.5f, 0.0f, 5.0f, , );
mMeshStick = Mesh.CreateCylinder(drawArgs.Device, 0.5f, 0.5f, 10.0f, , );
LoadTexturesAndMaterials(drawArgs);
}
IsInitialize = true;
}
private void LoadTexturesAndMaterials(DrawArgs drawArgs)//导入贴图和材质
{
material = new Material();
material.Diffuse = Color.Red;
material.Ambient = Color.White;
material.Specular = Color.Yellow;
material.Power = 15.0F; materialStick = new Material();
materialStick.Diffuse = Color.Yellow;
materialStick.Ambient = Color.White;
materialStick.Specular = Color.Yellow;
materialStick.Power = 15.0F;
}
public void Update(DrawArgs drawArgs)
{
if (IsOn && !IsInitialize)
{
Initialize(drawArgs);
}
} public void Render(DrawArgs drawArgs)
{
Matrix world = drawArgs.Device.GetTransform(TransformState.World);
int currentColorOp = drawArgs.Device.GetTextureStageState(, TextureStage.ColorOperation);
int lightCur = drawArgs.Device.GetRenderState(RenderState.Lighting);
try
{
drawArgs.Device.SetRenderState(RenderState.Lighting, true);
drawArgs.Device.EnableLight(, true);
AxisX(drawArgs);
AxisY(drawArgs);
AxisZ(drawArgs); }
catch (Exception)
{
}
finally
{
drawArgs.Device.EnableLight(, false);
drawArgs.Device.SetTextureStageState(, TextureStage.ColorOperation, currentColorOp);
drawArgs.Device.SetTransform(TransformState.World, world);
drawArgs.Device.SetRenderState(RenderState.Lighting, lightCur);
} } public void AxisX(DrawArgs drawArgs)
{
Light light = new Light();
light.Type = LightType.Spot;
light.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light); //drawArgs.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Red.ToArgb()).ToArgb()); drawArgs.Device.Material = material; Matrix MoveModel = Matrix.Translation(new Vector3(12.5f, 0f, 0f));
MoveModel = Matrix.RotationY((float)Math.PI / ) * MoveModel;//右乘
Matrix tmp = Matrix.RotationZ((float)mAngle);
tmp = tmp * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp = MoveModel * tmp;
drawArgs.Device.SetTransform(TransformState.World, tmp);
//设置顶点格式
mMeshArrow.DrawSubset(); Light light2 = new Light();
light2.Type = LightType.Directional;
light2.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light2); drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Red.ToArgb()).ToArgb()); drawArgs.Device.Material = materialStick; Matrix MoveModel2 = Matrix.Translation(new Vector3(, , ));
MoveModel2 = Matrix.RotationY((float)Math.PI / ) * MoveModel2;
Matrix tmp2 = Matrix.RotationZ((float)mAngle);
tmp2 = tmp2 * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp2 = MoveModel2 * tmp2;
drawArgs.Device.SetTransform(TransformState.World, tmp2);
mMeshStick.DrawSubset();
} public void AxisY(DrawArgs drawArgs)
{ Light light = new Light();
light.Type = LightType.Spot;
light.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light); //drawArgs.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Green.ToArgb()).ToArgb()); drawArgs.Device.Material = material; Matrix MoveModel = Matrix.Translation(new Vector3(0f, 12.5f, 0f));
MoveModel = Matrix.RotationX((float)-Math.PI / ) * MoveModel;//右乘
Matrix tmp = Matrix.RotationZ((float)mAngle);
tmp = tmp * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp = MoveModel * tmp;
drawArgs.Device.SetTransform(TransformState.World, tmp);
//设置顶点格式
mMeshArrow.DrawSubset(); Light light2 = new Light();
light2.Type = LightType.Directional;
light2.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light2); drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Green.ToArgb()).ToArgb()); drawArgs.Device.Material = materialStick; Matrix MoveModel2 = Matrix.Translation(new Vector3(, , ));
MoveModel2 = Matrix.RotationX((float)-Math.PI / ) * MoveModel2;
Matrix tmp2 = Matrix.RotationZ((float)mAngle);
tmp2 = tmp2 * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp2 = MoveModel2 * tmp2;
drawArgs.Device.SetTransform(TransformState.World, tmp2);
mMeshStick.DrawSubset();
} public void AxisZ(DrawArgs drawArgs)
{ Light light = new Light();
light.Type = LightType.Spot;
light.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light); //drawArgs.Device.SetTextureStageState(0, TextureStage.ColorOperation, TextureOperation.SelectArg1);
drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Blue.ToArgb()).ToArgb()); drawArgs.Device.Material = material; Matrix MoveModel = Matrix.Translation(new Vector3(0f, 0f, 12.5f));
// MoveModel = Matrix.RotationX((float)Math.PI) * MoveModel;//右乘
Matrix tmp = Matrix.RotationZ((float)mAngle);
tmp = tmp * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp = MoveModel * tmp;
drawArgs.Device.SetTransform(TransformState.World, tmp);
//设置顶点格式
mMeshArrow.DrawSubset(); Light light2 = new Light();
light2.Type = LightType.Directional;
light2.Diffuse = Color.White;
light.Direction = new Vector3(mPosition.X, mPosition.Y + , mPosition.Z + );
drawArgs.Device.SetLight(, light2); drawArgs.Device.SetRenderState(RenderState.Ambient, Color.FromArgb(Color.Blue.ToArgb()).ToArgb()); drawArgs.Device.Material = materialStick; Matrix MoveModel2 = Matrix.Translation(new Vector3(, , ));
// MoveModel2 = Matrix.RotationX((float)Math.PI) * MoveModel2;
Matrix tmp2 = Matrix.RotationZ((float)mAngle);
tmp2 = tmp2 * Matrix.Translation(mPosition.X, mPosition.Y, mPosition.Z);
tmp2 = MoveModel2 * tmp2;
drawArgs.Device.SetTransform(TransformState.World, tmp2);
mMeshStick.DrawSubset();
} public void Dispose()
{
if (mMeshArrow != null && !mMeshArrow.Disposed)
{
mMeshArrow.Dispose();
mMeshArrow = null;
}
if (mMeshStick != null && !mMeshStick.Disposed)
{
mMeshStick.Dispose();
mMeshStick = null;
}
IsInitialize = false;
} public double mAngle
{
get;
set;
} public Vector3 mPosition
{
get;
set;
} public void SetTransform(Vector3 position)
{
mPosition = position;
} public void SetRotateZ(double angle)
{
mAngle = angle;
}
}
}

结果:

[3D]绘制XYZ小坐标轴的更多相关文章

  1. Matlab绘图基础——利用axes(坐标系图形对象)绘制重叠图像 及 一图多轴(一幅图绘制多个坐标轴)

    描述 axes在当前窗口中创建一个包含默认属性坐标系 axes('PropertyName',propertyvalue,...)创建坐标系时,同时指定它的一些属性,没有指定的使用DefaultAxe ...

  2. 3D深色金属哥特3D项目工具小图标icon高清设计素材

    3D深色金属哥特3D项目工具小图标icon高清设计素材

  3. 3D教育类小图标_三维立体学习类icon图标素材

    3D教育类小图标_三维立体学习类icon图标素材

  4. Three.js 实现3D开放世界小游戏:阿狸的多元宇宙 🦊

    声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 2545光年之外的开普勒1028星系,有一颗色彩斑斓的宜居星球 ,星际移民 ...

  5. Three.js 实现3D全景侦探小游戏🕵️

    背景 你是嘿嘿嘿侦探社实习侦探️,接到上级指派任务,到甄开心小镇调查市民甄不戳宝石失窃案,根据线人流浪汉老石‍提供的线索,小偷就躲在小镇,快把他找出来,帮甄不戳寻回失窃的宝石吧! 本文使用 Three ...

  6. HTML5 3D Google搜索 小盒子 大世界

    HTML5真是能让人想象万千,居然动起了Google搜索的主意,它利用HTML5技术将Google搜索放到了一个小盒子里,弄起了3D搜索.随着鼠标移动,HTML5 3D搜索盒子也就转动,非常立体.点击 ...

  7. canvas绘制多角形小练习

    <!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  8. 【转】 Camera模仿3D效果的小例子(图片无限旋转)

    import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactor ...

  9. [3D]绘制线

    数据实体: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ...

随机推荐

  1. MAC环境下 nodejs 4.5.0 卸载

    MAC 环境下,我之前的删除 node 环境如果是用brew 安装的 node.js 4.4 之前的版本.可以网上参考其他方法,我之前的帖子也有之前的删除方法.参考帖子: http://www.cnb ...

  2. cordova -v 报错,必须用sodu cordova -v

    问题来源:MAC Caption EI 安装nodejs 4.5.0 之后,用命令:sudo npm install -g cordova ionic 安装cordova 和 ionic 然后用命令: ...

  3. A trip through the Graphics Pipeline 2011_02

    Welcome back. Last part was about vertex shaders, with some coverage of GPU shader units in general. ...

  4. Bootstrap页面布局17 - BS选项卡

    代码结构: <div class='container-fluid'> <h2 class='page-header'>Bootstrap 选项卡</h2> < ...

  5. 微信自定义菜单说php json_encode不转义中文汉字的方法

    http://blog.csdn.net/qmhball/article/details/45690017 最近在开发微信自定义菜单. 接口比较简单,就是按微信要求的格式post一段json数据过去就 ...

  6. 原创:CentOS6.4配置solr 4.7.2+IK分词器

    本文原创,转载请注明出处 相关资源下载:http://pan.baidu.com/s/1pJPpiqv 1.首先说明一下 solr是java语言开发的企业级应用服务器,所以你首先安装好jdk,配置好j ...

  7. Neteaset News

    到了中后期了,新浪微博结束就可以找工作了,坚持住,最困难的一周 前天为了敲网易新闻,一直敲到了快五点,我想丽丽一个女生都那么拼,我怎么不行?知乎上一个哥们虽然年年第一,上台只讲一句话,nothing ...

  8. find principles

    Computer Science An Overview _J. Glenn Brookshear _11th Edition In this chapter we explore the probl ...

  9. P1371 NOI元丹

    luogu月赛的题 本来想爆搜,但是经过ly大佬的点拨,明白这是一个dp. 我们定义dp[n]为从n开始的可行串的数目,具体如下:如果n为'I',则是从n开始有多少个I,如果n为'O',既是从n开始有 ...

  10. ArcGIS Server 服务迁移、恢复

    服务迁移与恢复 如果服务可以迁移,那么备份迁移所需文件,即可恢复原服务,所以"服务的迁移与恢复"."服务的备份"问题可以汇总为一个问题"怎样迁移服务. ...