WPF3D如何操纵在平行的平面物体到照相机 [英] WPF3D How to manipulate objects in a plane parallel to the camera

查看:184
本文介绍了WPF3D如何操纵在平行的平面物体到照相机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想提出的一个WPF应用程序。我使用了很多 3DTools 。我有一个四面体,在它里面,一个立方体。我想移动的立方体在三维方向。

I am making a application in WPF. I am using a lot the 3DTools. I have a tetrahedron and, inside it, a cube. I want to move the cube in 3D directions.

我的四面体,集中在(0,0,0)旋转使用轨迹球(编程,我有一个透明的边框在我的视口捕获的事件)。

My tetrahedron, centered in the (0,0,0) rotates using a Trackball (programmatically, I have a transparent border over my viewport to capture the events).

在使用者的应用程序认为更自然的方式移动立方体内最好始终移动它在2D平面(平行于屏幕)。所以,如果我想更深入的移动它在屏幕上,我只是旋转四面体和移动的Y轴,例如。我想这可能是一个很好的解决方案。

The users for the application think the more naturally way to move the cube inside it is to move it always in a 2D plane (parallel to the screen). So, if I want to move it deeper in the screen, I just rotate the tetrahedron and move it in Y axis, for example. I think this can be a good solution.

我有问题,我想帮忙解决,那么:第一,当我提出我的四面体(轨迹球内)轨迹球貌似将所有的系统坐标。我这样说是因为我画轴调试的目的,这些轴正在也旋转。但事实却并非如此 - 他们正在就因为是轨迹球中的对象(是吗?)。 修改其实我觉得轨迹球内部的坐标系是真正改变。当我移动Y-X轴立方体,我的行为确定。但是,如果我把一点点,并尝试在Z轴移动,我看到它得到(远离摄像机)大(靠近摄像机)和更小的。 =(

I have to problems, and I would like help to solve then: first, when I move my tetrahedron (inside the Trackball) the Trackball looks like moving all the system coordinates. I say this because I draw axis for debug purpose, and those axis are being rotate also. But this is not true - they are moving just because are objects inside the trackball (right?). EDIT Actually, I think the coordinate system inside the trackball are really changing. When I move the cube in Y-X axis, I behaves ok. But if I turn a little bit, and try to move in the Z axis, I see it getting bigger (closer to camera) and smaller (far from camera). =(

所以我的问题是如何定义一个平面上,不会通过轨迹球?可旋转对我来说,答案看起来像好的,我把它定义轨迹球之外,但是,正如我所说的(和3DTools文件说)我已经在我的视区的边界。所以我不知道如何来处理这个问题。

So my questions is how to define a plane which will not be rotate by trackball? For me the answer looks something like "ok, just define it outside the track ball" but, as I said (and 3DTools documentation say) I have a border over my viewport... So I do not know how to handle this.

我在一组ScreenSpaceLines3D的tetraedron。我将不得不继续立方体里面。我的第二个问题是如何到我跟踪它的四面体的顶点的位置旋转?我真的很失望,当Position属性给了我原来的位置,没有别的。我应该保持矩阵变换,然后应用到我的观点,当我需要呢?

My tetraedron in a set of ScreenSpaceLines3D. I will have to keep the cube inside it. My second question is how to I trace the positions of the vertex of the tetrahedron of it being rotated? I got really disappointed when the Position property gave me the original positions and nothing else. Should I keep the matrix transformations and apply then to my points when I need then?

对不起,长文本,但我真的卡在这个没有那么多的编程问题。我知道在WPF中,我还是有一些欠缺的概念。

Sorry for long text, but I really stuck in this not so much programming questions. I am knew in WPF, I still have some lacks of concepts.

在此先感谢,

佩德罗

推荐答案

我会怎么做,然后尽量使自己的机器人(创建新类的替代轨迹球手从3DTools)做这些。例如,在过去我曾缩放/平移,旋转围绕一个目标,自由旋转,自由移动,旋转对象,转换对象等等......所有这样做简单的矩阵/矢量操作。

What I'd do is then try to make your own manipulators (create new classes that replace TrackBall Manipulator from 3DTools) to do these. For instance, in the past I have made Zoom/pan, Rotate around a target, Free rotate, Free move, Rotate object, Translate object etc... all by doing simple matrix / vector manipulations.

有关你的榜样,你需要做的就是计算是正交至CAMERA>目标和世界矢量之间的飞机正常。这会给你一个载体,其为水货顶部的摄像头,像一个本地的X轴,如果你正在寻找到屏幕上。使用这种载体可以约束在这个方向上的多维数据集的议案。

For your example, what you need to do is calculate the normal which is orthogonal to the plane between Camera->Target and the world up vector. this will give you a vector which is "parallel" top the camera, like a local X-Axis if you are looking into the screen. Using this vector you can constrain the motion of the cube in this direction.

要做到这一点,计算从相机矢量V的目标。这是通过从摄像机位置减去对象位置来实现的。然后,计算一个矢量在横盘整理翻译如下:

To do this, compute the vector V from camera to target. This is achieved by substracting the object location from the camera location. Then, calculate a vector to translate in sideways as follows:

由于您的相机的矢量目标,V =喜,YJ,ZK
  正常化的向量,V'=喜,YJ,ZK /开方(十一^ 2 + YJ ^ 2 + ZK ^ 2)
  让U =全球世界矢量U = 0,0,1

Given a vector of your camera to target, v = xi, yj, zk
Normalise the vector, v' = xi, yj, zk / sqrt(xi^2 + yj^2 + zk^2)
Let U = global world up vector u = 0, 0, 1

那么我们可以计算R =水平向量平行于摄像机的视线方向

Then we can compute R = Horizontal Vector that is parallel to the camera's view direction

R = v' ^ U, where ^ is the cross product, given by   
 a ^ b = (a2b3 - a3b2)i + (a3b1 - a1b3)j + (a1b2 - a2b1)k 

这会给你一个载体,看起来像这样。

This will give you a vector that looks like this.

现在你知道这个向量R,当你移动鼠标左/右,你可以使用这个翻译的对象。例如,在伪code:

Now you know this vector R, when you move the mouse left/right you can use this to translate the object. For instance, in pseudocode:

// Pseudocode
onMouseMove()
{
    // Using calculation for R vector above
    Vector r = calulateVector();

    // Assuming passed in the number of points to translate 
    // (or some derivative of mousemove)
    let int pts = mousePointsMovedLeftOrRight;

    // Perform a translate in direction of R
    Vector targetPosition = TargetObject.PositionVector;
    targetPosition.X += r.X * pts;
    targetPosition.Y += r.Y * pts;
    targetPosition.Z += r.Z * pts;
}

我有我的笔记本电脑code在家里可以做到这一点(它的OpenGL的,但同样的原则 - 提供对象和相机的各种操作在三维空间)。请随时联系我/如果你想了解更多的评论。

I've got code on my laptop at home which can do this (It's OpenGL but same principle - provides various manipulations of objects and camera in 3D space). Please feel free to contact me/comment if you want to know more.

最好的问候,

这篇关于WPF3D如何操纵在平行的平面物体到照相机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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