XNA--Object Transformation
来源:互联网 发布:网络视频 编辑:程序博客网 时间:2024/05/17 18:28
A transformation is stored in a matrix (which is a 4 × 4 matrix of floats). The transformation thatstores the position and orientation of an object in your game is called theWorld matrix, as it defines where and how the object is positioned in your world. Other than World matrices, you also need the camera’s View and Projection matrices to transform 3D positions to 2D screen coordinates.
// Translate Vector3 translate; // Rotate around the (X, Y, Z) world axes Vector3 rotate; // Scale the X, Y, Z axes Vector3 scale; bool needUpdate; // Store the combination of the transformations Matrix matrix; public Vector3 Translate { get { return translate; } set { translate = value; needUpdate = true; } } public Vector3 Rotate { get { return rotate; } set { rotate = value; needUpdate = true; } } public Vector3 Scale { get { return scale; } set { scale = value; needUpdate = true; } } public Matrix Matrix { get { if (needUpdate) { // Compute the final matrix (Scale * Rotate * Translate) matrix = Matrix.CreateScale(scale) * Matrix.CreateRotationY(MathHelper.ToRadians(rotate.Y)) * Matrix.CreateRotationX(MathHelper.ToRadians(rotate.X)) * Matrix.CreateRotationZ(MathHelper.ToRadians(rotate.Z)) * Matrix.CreateTranslation(translate); needUpdate = false; } return matrix; } }The combination of these three transformations is called theworld transformation, as it uniquely defines where and how an object is positioned in the 3D world. You can set and retrieve this matrix attribute through the Matrix property, and it is recalculated whenever the translate, rotate, or scale transformation is updated.
Notice that the object’s world transformation matrix is calculated by multiplyingthe scale, rotation, and translation transformations of the object, in this order. Because the matrix product is not commutative,the order in which you combine the transformations is very important.
- XNA--Object Transformation
- XNA
- XNA
- Transformation
- BI 7.0 New Features - Transformation - Object oriented ABAP
- XNA游戏:Hello XNA
- XNA是什么?
- XNA 起步
- XNA简介
- XNA概述
- xna gui
- xna介绍
- XNA+Webcam
- XNA Framework
- XNA outofVideoMemoryException
- XNA--Camera
- XNA Shader
- XNA 互動式遊戲設計
- 团队的灵魂与鬼魂
- overview of the TableView API
- win7 计算器的用法
- Java集合框架总结
- android 虚拟机
- XNA--Object Transformation
- Linux内核的Oops问题详解
- 动态链接库的创建及使用
- C# BufferedStream 与MemoryStream 的区别
- 性能测试新手误区
- 重构36计(25-30)
- virtual destructor问题
- Linux ssh 配置
- vc 消息映射宏的种类