⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gmodviewerview.cpp

📁 liu7788414
💻 CPP
📖 第 1 页 / 共 2 页
字号:
					}
			}
		}

		OpenModelFrameCount = 1;
		m_ModelCount++;
		m_render3D.LoadModel(File, m_ModelCount-1);
		if( m_ModelCount > MODEL_MAX )
		{
			MessageBox("Error: Models count exceeds 20, no more files could be open", "ERROR!", MB_OK);
			return;
		}
		pModelData[m_ModelCount-1].curFrame = 0;
		pModelData[m_ModelCount-1].FrameCount = OpenModelFrameCount;
		pModelData[m_ModelCount-1].DisplayMode = DSP_NORMAL;
		pModelData[m_ModelCount-1].Hide = 0;


		strcpy(pModelData[m_ModelCount-1].ModelName, "");
		strcpy(pModelData[m_ModelCount-1].ModelName, modename);

		if( m_ModelCount == 1 )
		{
			m_curModel = 0;

			if( pModelData[m_curModel].FrameCount > 1 )
				bRotateActor = true;
			else
				bRotateActor = false;
		}
		if( Page->m_hWnd )
			Page->AddModel(pModelData[m_ModelCount-1].ModelName);

		Invalidate();
	}
	
}

void SetViewMatrix()
{
	m_viewMat.LookAt(pG3D->GetEye(), m_lookat, m_up);
}


void CGModViewerView::UpdateView()
{
	if(pG3D!=NULL)
	{
		CMatrix44 trm(m_viewMat);
		trm.Inverse();
		Vector4s eye;
		eye.x=trm.get(0,3);
		eye.y=trm.get(1,3);
		eye.z=trm.get(2,3);

		pG3D->SetEye(&eye);

		pG3D->SetMatrix(1, &m_viewMat);

	}

}

void GetCurLookAt()
{
	CMatrix44 mat(&m_viewMat);
	Vector4s vet;

	mat.Inverse();
	vet=mat.Transform(Vector4s(0,0,1024));
	m_lookat = vet-pG3D->GetEye();
}

void CGModViewerView::UpdateWorldMat(int id) 
{
	m_matWorld.Identity();
	CRender3D::GetWorldMat(&pModelData[id].Pos, &pModelData[id].Rot, &m_matWorld);
};//(&m_vPos, &m_vRot, &m_matWorld);};

////////////////////////////////////////////////////////////////////////////////////
// up down influence hormat
void CompMatrix()
{
	m_viewMat=m_VerMat;
	m_viewMat.PostMultiply(&m_HorMat);
	m_viewMat.PostMultiply(&m_origin);

}

void CGModViewerView::CompMatrix()
{
	m_viewMat=m_VerMat;
	m_viewMat.PostMultiply(&m_HorMat);
	m_viewMat.PostMultiply(&m_origin);

	UpdateView();
}


void CGModViewerView::MoveUp(int distance)
{

	CMatrix44 mat;
	mat.DefTranslate(0,-distance,0);
	mat.PostMultiply(&m_origin);
	CMatrix44 m_tmpOrigin(&m_origin);
	m_origin=mat;

	CompMatrix();
}


void CGModViewerView::MoveDown(int distance)
{
	MoveUp(-distance);
}


// others influence vermat
void CGModViewerView::MoveLeft(int distance)
{
	CMatrix44 mat;
	mat.DefTranslate(distance,0,0);
	mat.PostMultiply(&m_HorMat); 
	CMatrix44 m_tmpHorMat(m_HorMat);
	m_HorMat=mat;

	CompMatrix();
}


void CGModViewerView::MoveRight(int distance)
{
	MoveLeft(-distance);
}


void CGModViewerView::MoveForward(int distance)
{
	CMatrix44 mat;
	mat.DefTranslate(0,0,-distance);
	mat.PostMultiply(&m_HorMat); 
	CMatrix44 m_tmpHorMat(m_HorMat);
	m_HorMat=mat;

	CompMatrix();
}


void CGModViewerView::MoveBackward(int distance)
{
	MoveForward(-distance);
}


void CGModViewerView::RotateUp(int angle)
{
	CMatrix44 mat;
	mat.DefRotateX(angle);
	mat.PostMultiply(&m_VerMat); 
	CMatrix44 m_tmpVerMat(m_VerMat);
	m_VerMat=mat;

	CompMatrix();
}

void CGModViewerView::RotateDown(int angle)
{
	RotateUp(-angle);
}

void CGModViewerView::RotateLeft(int angle)
{
	if( bRotateActor )
	{
		pModelData[m_curModel].Rot.z += angle;
		if( pModelData[m_curModel].Rot.z > 2048 )
			pModelData[m_curModel].Rot.z -= 2048;
		else if( pModelData[m_curModel].Rot.z < -2048 )
			pModelData[m_curModel].Rot.z += 2048;
	}
	else{
		CMatrix44 mat;
		mat.DefRotateY(-angle);
		mat.PostMultiply(&m_HorMat); 
		CMatrix44 m_tmpHorMat(m_HorMat);
		m_HorMat=mat;

		CompMatrix();
	}
}

void CGModViewerView::RotateRight(int angle)
{
	RotateLeft(-angle);
}

extern CPropPage     *Page;
void CGModViewerView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) 
{
	// TODO: Add your message handler code here and/or call default
	int step = m_CameraAdjustStep;

	switch( nChar )
	{
	case VK_LEFT:
		MoveLeft(step);		
		break;
	case VK_RIGHT:
		MoveRight(step);		
		break;
	case VK_NUMPAD1:
		MoveUp(step);
		break;
	case VK_NUMPAD7:
		MoveDown(step);
		break;
	case VK_UP:
		MoveForward(step);
		break;
	case VK_DOWN:
		MoveBackward(step);
		break;
	case VK_NUMPAD2:
		RotateUp(step);
		break;
	case VK_NUMPAD8:
		RotateDown(step);
		break;
	case VK_NUMPAD4:
		RotateRight(step);
		break;
	case VK_NUMPAD6:
		RotateLeft(step);
		break;
	case VK_NUMPAD0:
		OnSkeleton();
		break;
	}
	Invalidate();
	if( Page->m_hWnd )
	{
		Page->UpdateModel();
		Page->Invalidate();
	}
//	need_erase = false;

	CView::OnKeyDown(nChar, nRepCnt, nFlags);
}

void *CGModViewerView::Converto24bits(void *pSrc, int bufsize)
{
	unsigned short *buf = (unsigned short *)pSrc;

	byte *pDst,*p;
	byte r,g,b;

	pDst = (byte *)MALLOC(bufsize*3/sizeof(unsigned short));
	p = pDst;

	for( int j=0; j< bufsize/2; j++, p++ )
	{
		r = RCOLOR(buf[j]);
		g = GCOLOR(buf[j]);
		b = BCOLOR(buf[j]);
		*p++ = b;
		*p++ = g;
		*p = r;
	}
	return pDst;
}

BOOL CGModViewerView::OnEraseBkgnd(CDC* pDC) 
{
	// TODO: Add your message handler code here and/or call default
	if( need_erase )
		return CView::OnEraseBkgnd(pDC);
	else{
		need_erase = true;
		return 0;//CView::OnEraseBkgnd(pDC);
	}
}

void CGModViewerView::OnSetFocus(CWnd* pOldWnd) 
{
	CView::OnSetFocus(pOldWnd);
	
	need_erase = true;
	// TODO: Add your message handler code here
	Invalidate();
	
}

void CGModViewerView::OnPlayAnim() 
{
	// TODO: Add your command handler code here
	if( pModelData[m_curModel].FrameCount > 1 )
		bPlayAnim = true;
}

void CGModViewerView::OnStopAnim() 
{
	// TODO: Add your command handler code here
	bPlayAnim = false;
	need_erase = true;
	Invalidate();
}

void CGModViewerView::OnSkeleton() 
{
	// TODO: Add your command handler code here
	pG3D->m_skeleton = !pG3D->m_skeleton;
	for( int i=0; i<m_ModelCount; i++ )
	{
		if( pG3D->m_skeleton )
			pModelData[i].DisplayMode = DSP_WIRE;
		else
			pModelData[i].DisplayMode = DSP_NORMAL;
	}
	Invalidate();
}

void CGModViewerView::OnFrameNext() 
{
	// TODO: Add your command handler code here
	pModelData[m_curModel].curFrame++;
	if( pModelData[m_curModel].curFrame >= pModelData[m_curModel].FrameCount )
		pModelData[m_curModel].curFrame=0;
	Invalidate();
	if( Page->m_hWnd )
	{
		Page->m_CurFrame = pModelData[m_curModel].curFrame;
		Page->UpdateData(FALSE);
		Page->Invalidate();
	}

}

void CGModViewerView::OnFramePrev() 
{
	// TODO: Add your command handler code here
	if( pModelData[m_curModel].curFrame )
	{
		pModelData[m_curModel].curFrame--;
		if( pModelData[m_curModel].curFrame < 0 )
			pModelData[m_curModel].curFrame = 0;
		
		Invalidate();
		if( Page->m_hWnd )
		{
			Page->m_CurFrame = pModelData[m_curModel].curFrame;
			Page->UpdateData(FALSE);
			Page->Invalidate();
		}
	}
}

void CGModViewerView::OnFileNew() 
{
	// TODO: Add your command handler code here
	if( m_ModelCount )
	{
		ReleaseGlobalResource();
		FirstTimeInit();
		Invalidate();
		if( Page->m_hWnd )
		{
			Page->RemoveAll();
			Page->UpdateData(FALSE);
			Page->Invalidate();
		}
	}
}

void CGModViewerView::ReleaseGlobalResource()
{
	SMemory->ResetHeap();
	SMemory->ResetStack();
	m_render3D.ReleaseModel();
	m_render3D.GetG3d()->ReleaseTextures();

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -