[3D]绘制XYZ小坐标轴
源码:
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小坐标轴的更多相关文章
- Matlab绘图基础——利用axes(坐标系图形对象)绘制重叠图像 及 一图多轴(一幅图绘制多个坐标轴)
		描述 axes在当前窗口中创建一个包含默认属性坐标系 axes('PropertyName',propertyvalue,...)创建坐标系时,同时指定它的一些属性,没有指定的使用DefaultAxe ... 
- 3D深色金属哥特3D项目工具小图标icon高清设计素材
		3D深色金属哥特3D项目工具小图标icon高清设计素材 
- 3D教育类小图标_三维立体学习类icon图标素材
		3D教育类小图标_三维立体学习类icon图标素材 
- Three.js 实现3D开放世界小游戏:阿狸的多元宇宙 🦊
		声明:本文涉及图文和模型素材仅用于个人学习.研究和欣赏,请勿二次修改.非法传播.转载.出版.商用.及进行其他获利行为. 背景 2545光年之外的开普勒1028星系,有一颗色彩斑斓的宜居星球 ,星际移民 ... 
- Three.js 实现3D全景侦探小游戏🕵️
		背景 你是嘿嘿嘿侦探社实习侦探️,接到上级指派任务,到甄开心小镇调查市民甄不戳宝石失窃案,根据线人流浪汉老石提供的线索,小偷就躲在小镇,快把他找出来,帮甄不戳寻回失窃的宝石吧! 本文使用 Three ... 
- HTML5 3D Google搜索 小盒子 大世界
		HTML5真是能让人想象万千,居然动起了Google搜索的主意,它利用HTML5技术将Google搜索放到了一个小盒子里,弄起了3D搜索.随着鼠标移动,HTML5 3D搜索盒子也就转动,非常立体.点击 ... 
- canvas绘制多角形小练习
		<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ... 
- 【转】 Camera模仿3D效果的小例子(图片无限旋转)
		import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactor ... 
- [3D]绘制线
		数据实体: using System; using System.Collections.Generic; using System.Linq; using System.Text; using Sy ... 
随机推荐
- replication set复制集
			replication set复制集 介绍 replicattion set 多台服务器维护相同的数据副本,提高服务器的可用性,总结下来有以下好处: 数据备份与恢复 读写分离 MongoDB 复制集 ... 
- DS实验题 sights
			算法与数据结构实验题 6.3 sights ★实验任务 美丽的小风姑娘打算去旅游散心,她走进了一座山,发现这座山有 n 个景点, 由于山路难修,所以施工队只修了最少条的路,来保证 n 个景点联通,娇弱 ... 
- [转]PHP高效率写法(详解原因)
			1.尽量静态化: 如果一个方法能被静态,那就声明它为静态的,速度可提高1/4,甚至我测试的时候,这个提高了近三倍. 当然了,这个测试方法需要在十万级以上次执行,效果才明显. 其实静态方法和非静 ... 
- 自动配置IP地址.bat
			※※※※※※※※※※※※※※※※※※※※※※※※※※※※ @echo ※ ※ @echo ... 
- lvs简单配置
			负载均衡服务器将会用到两块网卡,eth0为公网地址(此处将局域网ip作为公网地址),IP地址为192.168.1.104,eth0:1,IP地址为192.168.2.1在负载均衡器上添加一个ip别名, ... 
- DDL DML DCL SQL
			https://dev.mysql.com/doc/refman/5.7/en/glossary.html#glos_ddl SQL The Structured Query Language tha ... 
- Delphi 中的哈希表(二)—— TStringHash
			unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms ... 
- delphi 高版本可执行程序减小的办法
			选菜单里的 Project -> Options.. (Shift+Ctrl+F11)出现Project Options for Project1.exe窗口,在左边选 Packages出现如下 ... 
- BLE-NRF51822教程19-Battery Service
			Battery Service是有关电池特性方面的服务,如果需要它,在初始化时将它加入到蓝牙协议栈. 如果通过ble_bas_battery_level_update(),电池电量将会通知,Batte ... 
- Redis学习笔记(6)-SortedSet
			package cn.com; import java.util.HashMap; import java.util.Map; import java.util.Set; import redis.c ... 
