3D 物体的透视
我正在将我们的一个旧应用程序从 vb6 更新为 c#,在此过程中必须重新创建原始程序员设计的自定义控件。该控件只是获取一个对象(矩形或圆锥形)的尺寸,并以 3D 形式放置该对象的轮廓草图(我认为技术上是 2.5D)。当然,控制或算法的代码无处可寻。
事先对此一无所知,除了视角之外,我几乎复制了所有内容。我正在使用我在另一个答案中找到的代码。
}
double w = 400;
double h = 250;
double t = 0.6; // tilt angle
double X = w / 2 - x;
double Y = h / 2 - y;
double a = h / (h + Y * Math.Sin(t));
double u = a * X + w / 2;
double v = a * Y * Math.Cos(t) + h / 2;
}
我需要帮助的最后一个部分是将视角从左向右旋转约 30 度,这样我就不会直视。
感谢您的任何帮助。
I am updating one of our older apps from vb6 to c# and in the process have to recreate a custom control that the original programmer designed. The control simply took the dimensions of an object, rectangular or conical, and placed an outline sketch of the object in 3D (2.5D technically I think). Of course, the code for the control or the algorithim is nowhere to be had.
Knowing nothing about this before hand I have gotten pretty much everything replicated except the perspective. I am using this code that I found on another answer here.
}
double w = 400;
double h = 250;
double t = 0.6; // tilt angle
double X = w / 2 - x;
double Y = h / 2 - y;
double a = h / (h + Y * Math.Sin(t));
double u = a * X + w / 2;
double v = a * Y * Math.Cos(t) + h / 2;
}
The last piece I need help with though is turning the perspective about 30 degrees left-to-right so I'm not looking at straight on.
Thanks for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如评论者所说:你应该使用矩阵来让你的生活变得轻松。
通过将两个矩阵(一个旋转矩阵和一个透视矩阵)相乘可以轻松完成旋转:
用于运行代码你必须做一些事情:
实现一个 C# 矩阵,或者从其他地方获取它。 这里是一个很好的实现矩阵的来源。
As the commenter says: You should use matrices to make your live easy.
Rotation could be easily done by multiplying the 2 matrices, a rotation matrix and a perspective matrix this way:
For running the code you have to do some things:
Implement a C# matrix, or get it from anywhere else. Here is a excellent source for implementing matrices.