源码:

 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. 如何安装ESXi的补丁

    1.进入维护模式 2.通过vSphere Client上传补丁 3.开SSH后使用Putty连接 4.esxcli software vib install -d="/vmfs/volume ...

  2. HttpRequestDeviceUtils

    import javax.servlet.http.HttpServletRequest;public class HttpRequestDeviceUtils { /**Wap网关Via头信息中特有 ...

  3. SQL Server访问MySql

    使用环境:操作系统:window7数据库:SQL Server2005.MySql5.01.在安装了SQL Server的服务器上安装MySql的ODBC驱动:下载链接:http://dev.mysq ...

  4. windows上在linux客户端上传小文件lrzsz

    yum install lrzsz 即可 rz上传,会打开本地图形化界面直接上传 基于centos系统,其他系统请找对应 的源码包编译 一下

  5. [ZZ] [siggraph10]color enhancement and rendering in film and game productio

    原文link:<color enhancement and rendering in film and game production> 是siggraph 2010,“Color Enh ...

  6. mysql执行完select后,释放游标

    内存释放 在我们执行完SELECT语句后,释放游标内存是一个很好的习惯. .可以通过PHP函数mysql_free_result()来实现内存的释放. 以下实例演示了该函数的使用方法. 2.mysql ...

  7. 随机(Random)

    随机(Random)随机是智能的基础,人工智能的很多技术都需要用到随机,因此有必要把这个提到前面谈谈一考虑基于C/C++,般我们都是使用的rand ()等函数实现随机,当然我们也有吊炸天的boost库 ...

  8. mysqli_query($link,'SET group_concat_max_len=8192');

    mysqli_query($link,'SET group_concat_max_len=8192'); $sql = 'SELECT GROUP_CONCAT(w) FROM ---'; mysql ...

  9. General protection fault Exceptions in Linux/IA32 Systems

    Computer Systems A Programmer's Perspective Second Edition Exception number Description Exception cl ...

  10. anti-pattern - Hard coding

    https://en.wikipedia.org/wiki/Hard_coding Considered an anti-pattern, hard coding requires the progr ...