源码:

 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. HTML5 3D Google搜索 小盒子 大世界

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

  3. canvas绘制多角形小练习

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

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

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

  5. [3D]绘制线

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

  6. canvas绘制简单小铅笔

    对应HTML <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <ti ...

  7. Android布局绘制常见小问题

    一些网上分享的整理 1.Android设置Selector不同状态下颜色及图片 Selector常用状态: android:state_selected 控件选中状态,可以为true或false an ...

  8. Qt Creator中的3D绘图及动画教程(参照NeHe)

    Qt Creator中的3D绘图及动画教程(参照NeHe) http://blog.csdn.net/cly116/article/details/47184729 刚刚学习了Qt Creator,发 ...

  9. &lt;数据可视化&gt;Matplotlib(2D+3D)

    1.Matplotlib介绍(2D) Matplotlib 是 Python 2D-绘图领域使用最广泛的套件.它能让使用者很轻松地将数据图形化,并且提供多样化的输出格式. pylab 是 matplo ...

随机推荐

  1. win7里边使用telnet命令为什么提示telnet不是内部或外部命令,也不是可运行的程序或批处理文件

    Win7默认没有安装telnet功能,所以你直接用telnet命令是用不了的:你可以去“控制面板”-->“程序”(在左下角)--->“打开或关闭Windows功能”,勾上“telnet客户 ...

  2. AngularJs-指令和控制器交互

    前言: 前段时间我们学习了angular的指令,他通过ECMA的方式创建元素,可以让我们共用这些元素,我们也知道可以通过 link的方法给这个指令添加一些动作事件,本节,我们将写入和让angular的 ...

  3. xcode7.3 iTunes Store operation failed问题

    升级了7.3,真心的不好用啊,bug一堆,写个代码,引入的类根本找不到,必须要command+b 重新编译一遍,现在连提交appstore都有问题. 果断用了 Application Loader上传 ...

  4. 【转】Android开发学习笔记:EditText的属性介绍

    原文网址:http://liangruijun.blog.51cto.com/3061169/627350 原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追 ...

  5. Struts2-整理笔记(三)结果处理跳转、获得servletAPI原生

    在struts2中有很多种跳转方式如下是在struts-default.xml截取的一段源码,常用的跳转有 转发:dispatcher.重定向:redirect.转发到Action:chain.重定向 ...

  6. ProjectA: 多元非线性回归

    https://www.youtube.com/watch?v=n9XycstdPYs&t=907s

  7. jar包安装到本地仓库

    mvn install:install-file -Dfile=hm_test.jar -DgroupId=com.TEST -DartifactId=hm_test -Dversion=1.0 -D ...

  8. vsftpd安装配置以及常见问题解决

    vsftpd安装配置以及踩坑解决办法,Centos7 nginx已经配置成功了,但是使用http始终没办法访问到图片,那么你来对地方了(在文章末尾是原因) 配置nginx教程:http://blog. ...

  9. QQ 客服设置

    不说那么多了. 目前可以通过此方式实现添加的效果 <a target="_blank" href="http://wpa.qq.com/msgrd?v=3& ...

  10. ORM PHP 学习记录

    ORM:object relation mapping,即对象关系映射,简单的说就是对象模型和关系模型的一种映射.为什么要有这么一个映射?很简单,因为现在的开发语言基本都是oop的,但是传统的数据库却 ...