我正在将我们的旧应用程序之一从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度,所以我不是直视。
感谢您的帮助。
答案 0 :(得分:0)
正如评论者所说:你应该使用矩阵让你的生活变得轻松。
通过以下方式将2个矩阵,旋转矩阵和透视矩阵相乘可以轻松完成旋转:
// We don't have a view matrix here
Matrix4x4 modelProjection = Matrix4x4.Perspective(400, 250, Math.PI / 4) * Matrix4x4.RotationX(degree);
// Get a specifics point position, use x and y to determine the screen position and z for the z-order
Vector3 screenPosition = modelProjection * myPosition; // myPosition is a Vector3
要运行代码,您必须执行以下操作: 实现C#矩阵,或从其他任何地方获取它。 Here是实现矩阵的绝佳来源。