由于您在该平面上有一个 2D 图像,因此您显然希望匹配其坐标系。为此,请确定图片的单位向量。即取3d坐标B对于任意 x>0 的图片位置 (x,0),并从中减去 3d 坐标A为图片的原点 (0,0)。所得向量B − A会描述积极的一面x你的图像的方向。对y方向。然后对这两个向量进行归一化。这意味着将它们除以长度 sqrt(x²+y²+z²),但 D3Dx 有一个函数D3DXVec3Normalize http://msdn.microsoft.com/en-us/library/bb205515%28v=vs.85%29.aspx为了这。我们将生成的 3d 向量称为X and Y。计算x and y任意 3D 点的坐标p,只需减去原点A from p,即计算向量p − A。然后计算结果和单位向量之间的点积X and Y。这将为您提供两个数字:所需的坐标。这是因为点积可用于计算正交投影。
将其翻译成D3Dx http://msdn.microsoft.com/en-us/library/bb172965%28VS.85%29.aspx,它应该类似于以下内容。由于我从未使用过它,因此可能会有错误。
D3DXVECTOR3 *p; // input point
D3DXVECTOR3 a, b, c, ab, ac, ap; // helper vectors
FLOAT x, y; // output coordinates
imagePosTo3D(&a, 0, 0); // a = origin of image
imagePosTo3D(&b, 1, 0); // b = anywhere on positive x axis, perhaps a corner
imagePosTo3D(&c, 0, 1); // c = anywhere on positive y axis, perhaps a corner
D3DXVec3Subtract(&ab, &b, &a); // ab = b - a
D3DXVec3Subtract(&ac, &c, &a); // ac = c - a
D3DXVec3Normalize(&ab, &ab); // ab = ab / |ab|
D3DXVec3Normalize(&ac, &ac); // ac = ac / |ac|
// the above has to be done once for the image, the code below for every p
D3DXVec3Subtract(&ap, p, &a); // ap = p - a
x = D3DXVec3Dot(&ab, &ap); // x = ab∙ap
y = D3DXVec3Dot(&ac, &ap); // y = ac∙ap