2

I am trying to make a simple game engine but I got stuck at a point when I tried to map a 2D mouse coordinate to a 3D coordinate in my world. The basic game has a plane that serves as the ground as it is going to be (hopefully with time) an RTS gameengine.

My problem is that I can't really come up with anything useful. The plane is located at the 0,-100,-300 points and is about 1000x1000 in size. My camera is at 0,0,0 and the scene is rotated at 60 degreesto give the impression of a "bird eye" cam.

I was thinking about the trigonometric equations, using that I know the height of my camera and the angle and possibly calculating the distance will give me the right coords but this is just an idea.

Can somebody please give me some advice?

4

1 回答 1

0

您可以通过简单的光线投射来做到这一点。

首先,使用gluUnProject可以获得m鼠标指针的 2D 窗口坐标对应的 3D 世界坐标。

给定相机位置e = (0, 0, 0),您可以计算鼠标光线方向 r = m - e

现在,给定p平面上的一个点和平面法线n,您可以计算鼠标射线与平面的交点

于 2012-11-03T13:35:31.660 回答