|
|
发表于 2008-1-16 19:21:00
|
显示全部楼层
Re:物体的世界坐标如何变换到屏幕坐标?
point p = (x,y,z);
wvp = worldMatrix * viewMatrix * projectionMatrix;
p'(x,y,z,w) = mul(p,wvp);
now you get p' in 4D space
screenCoord.x = p'.x / p'.w;
screenCoord.y = -p'.y / p'.w;
now you get p in 2D screen space range form [-1,1], so far it's the same as graphics pipline transform.
screenCoord.x = screenCoord.x/2.0f + 0.5f
screenCoord.y = screenCoord.y/2.0f + 0.5f
now you get p range form [0,1];
wndPos.x = screenCoord.x * wndWidth;
wndPos.y = screenCoord.y * wndHeight;
done......
by the way, in XNA you can use the Viewport.Project method as a shortcut for this. i'm not sure if dx have a similar method -_-# |
|