游戏开发论坛

 找回密码
 立即注册
搜索
12
返回列表 发新帖
楼主: iverson

物体的世界坐标如何变换到屏幕坐标?

[复制链接]

59

主题

984

帖子

1200

积分

金牌会员

Rank: 6Rank: 6

积分
1200
发表于 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 -_-#

0

主题

228

帖子

285

积分

中级会员

Rank: 3Rank: 3

积分
285
发表于 2008-1-17 10:52:00 | 显示全部楼层

Re:物体的世界坐标如何变换到屏幕坐标?

clayman
正解
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-19 21:54

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表