您的位置:首页 > 其它

在3D中, 将世界坐标映射为屏幕上的坐标点

2010-12-07 11:04 337 查看
首先介绍Ogre中的方法:



Vector3 tartgetpos;
	Ogre::Matrix4 viewMat = mCamera->getViewMatrix();
	Ogre::Matrix4 projMat = mCamera->getProjectionMatrix(); 
	Ogre::Vector3 screenPos = projMat * viewMat * tartgetpos;
	float x = (screenPos.x + 1.0f)/ 2.0f;
	float y = -1*(screenPos.y - 1.0f) / 2.0f;




再谈谈直接使用OpenGL的方法:



Vector3 pos(...); //物体的位置
double xfpcoord[3]; 
gluProject(pos.x,pos.y,pos.z,cam_model_mat,cam_proj_mat,cam_viewport,&xfpcoord[0],&xfpcoord[1],&xfpcoord[2]);


参数解释一下,

cam_model_mat: camera model matrix

cam_proj_mat: camera projection matrix

cam_viewport: camera viewport

xfpcoord[0]: 屏幕X

xfpcoord[1]: 屏幕Y
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: