旋转3D对象DirectX VB .NET [英] Rotating 3D object DirectX VB .NET

查看:90
本文介绍了旋转3D对象DirectX VB .NET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,我是DirectX的入门者,现在我正在编写一个小型3D演示应用程序,其中有一个对象,目标是用鼠标围绕X和Y轴旋转该对象,这是我的代码:

Hi guys I''m a begginer in DirectX and now I''m writing a small 3D demo app where you have an object and the goal is to rotate this object around X and Y axes with the mouse, this is my code:

device.Transform.World = Matrix.RotationY(0 - _
(Control.MousePosition.X / int3DSpeed))'rotate around Y
device.Transform.World = Matrix.RotationX(0 - _
(Control.MousePosition.Y / int3DSpeed))'rotate around X




问题在于VB仅执行第一个分配:




The problem is that VB is executing only the first assignment:

device.Transform.World = Matrix.RotationY(0 - _
(Control.MousePosition.X / int3DSpeed))'rotate around Y


第二个:


and the second one:

device.Transform.World = Matrix.RotationX(0 - _
(Control.MousePosition.Y / int3DSpeed))'rotate around X


总是被忽略.

我的代码有什么问题,如何才能同时在X和Y轴上旋转对象?


is always ignored.

What is wrong with my code, how can I rotate the object on X and Y axes simultaneously?

推荐答案

让我解释一下发生的事情:您分配了两个同一对象device.Transform.World的值不同,第一个语句中的一个值,第二个语句中的另一个值.这样,只有第二条语句才有效,而第一条语句的结果将丢失.

我不知道你为什么觉得第二句话被忽略了.实际上,忽略"是第一个,更确切地说,没有任何作用.我认为您只是误解了轮换的结果.删除第一个语句并进行检查.

什么都不会被忽略,您可以通过在调试器中运行此代码片段轻松看到.在发出任何语句并提出问题之前,请始终在调试器下运行有问题的代码.

对于组合变换,它是通过矩阵乘法获得的.

—SA
Let me explain this obvious thing about what happens: you assign two different values to the same object device.Transform.World, one value in first statement, another value in second statement. In this way, only the second statement has effect, the result of first one is lost.

I have no idea why do you feel that the second statement is ignored. In fact, "ignored" is the first one, more exactly, has no effect. I think you just misinterpreted the result of rotation. Remove first statement and check it up.

Nothing is ignored, which you can easily see by running this code fragment under debugger. Please always run you code in question under debugger before making any statements and asking questions.

As to combined transform, it is obtained via matrix multiplication.

—SA


试试这个

Try this

device.Transform.World = Matrix.Multiply(Matrix.RotationY(0 - (Control.MousePosition.X / int3DSpeed)), Matrix.RotationX(0 - (Control.MousePosition.Y / int3DSpeed)))


这篇关于旋转3D对象DirectX VB .NET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆