本文是在上一篇博客基于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();
}
实现效果:
首先在 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);
}