OpenGL二维世界坐标和屏幕坐标系之间的转换

ScreenToWorld2D

glm::vec3 xxxCamera2D::ScreenToWorld2D(glm::vec3 screen_pt)//screen point-->(x,y,0)
{
   
	glm::vec3 normalized_screen_pt;

	glm::vec3 world_pt;
	float degree = PI / 2;
	glm::vec3 pt;
	/*方法1:使用矩阵
	前提:世界坐标系固定,求得旋转至屏幕坐标中心为原点的屏幕坐标系的变换矩阵,再求逆*/
	/*Step1:比例伸缩,求伸缩矩阵*/
	glm::vec4 world_center_pt(0);
	glm::vec3 vec_scale(m_fWidth / GetViewWidth(), 1, m_fHeight / GetViewHeight());
	glm::mat4 M_scale = glm::scale(vec_scale);
	/*Step2:平移到m_Eye坐标,求平移矩阵*/
	glm::mat4 M_translate = glm::translate(m_Eye);
	/*Step3:绕Y轴旋转,求旋转矩阵*/
	glm::vec3 normal(0, 1, 0);
	glm::mat4 M_rotate;
	glm::mat4 M_convert;
	glm::mat4 M_convert_inverse;
	/*Screen中心为原点的screen_pt坐标*/
	glm::vec3 converted_screen_center(m_fWidth / 2, 0, m_fHeight / 2);
	glm::vec3 converted_screen_pt;
	converted_screen_pt = (glm::vec3)(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值