基于MFC的透视投影算法实现

基于 M F C MFC MFC的透视投影算法实现

本文是在上一篇博客基于MFC的平行投影算法实现的基础上实现透视投影中的一点透视。

两种方法实现

一、添加事件处理程序实现

设置 I D ID ID I D _ Y i d i a n t o u s h i ID\_Yidiantoushi ID_Yidiantoushi,添加事件处理程序 O n Y i d i a n t o u s h i ( ) OnYidiantoushi() OnYidiantoushi()

void CParallelProjectionView::OnYidiantoushi()
{
     
	// TODO: 在此添加命令处理程序代码
	bianhuan1[0][0] = 1, bianhuan1[0][1] = 0, bianhuan1[0][2] = 0, bianhuan1[0][3] = 0;
	bianhuan1[1][0] = 0, bianhuan1[1][1] = 1, bianhuan1[1][2] = 0, bianhuan1[1][3] = 0;
	bianhuan1[2][0] = 0, bianhuan1[2][1] = 0, bianhuan1[2][2] = 0, bianhuan1[2][3] = -0.4;
	bianhuan1[3][0] = 0.8, bianhuan1[3][1] = -1.6, bianhuan1[3][2] = 0, bianhuan1[3][3] = 1.8;
	matx_N4(lifang, bianhuan1, jieguo);
	mydraw();
}

实现效果:

基于MFC的透视投影算法实现_第1张图片

二、利用系统响应函数实现

首先在 V i e w View View类中声明double my_z;然后在 O n C r e a t e ( ) OnCreate() OnCreate()函数中赋值my_z = -0.4;最后再利用类向导添加消息中的 W M _ L B U T T O N D B L C L K WM\_LBUTTONDBLCLK WM_LBUTTONDBLCLK处理函数。实现双击鼠标左键来改变投影中心离投影面的距离。

void CParallelProjectionView::OnLButtonDblClk(UINT nFlags, CPoint point)
{
     
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (my_z >= -0.6)
	{
     
		my_z += 0.05;
		if (my_z >= -0.0)
			my_z = -0.6;
	}
	RedrawWindow();
	//一点透视变换矩阵
	bianhuan1[0][0] = 1, bianhuan1[0][1] = 0, bianhuan1[0][2] = 0,bianhuan1[0][3] = 0;
	bianhuan1[1][0] = 0, bianhuan1[1][1] = 1, bianhuan1[1][2] = 0, bianhuan1[1][3] = 0;
	bianhuan1[2][0] = 0, bianhuan1[2][1] = 0, bianhuan1[2][2] = 0, bianhuan1[2][3] = my_z;
	bianhuan1[3][0] = 0.8, bianhuan1[3][1] = -1.6, bianhuan1[3][2] = 0, bianhuan1[3][3] = 1.8;
	matx_N4(lifang, bianhuan1, jieguo);
	mydraw();
	CView::OnLButtonDblClk(nFlags, point);
}

实现效果:
基于MFC的透视投影算法实现_第2张图片

你可能感兴趣的:(计算机图形学)