📄 gmodviewerview.cpp
字号:
// GModViewerView.cpp : implementation of the CGModViewerView class
//
#include "stdafx.h"
#include "GModViewer.h"
#include "GModViewerDoc.h"
#include "GModViewerView.h"
#include "3d\Mesh.h"
#include "system\ResFile.h"
#include "system\Gfx.h"
#include "3d\Render3d.h"
#include "PropPage.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CGModViewerView
IMPLEMENT_DYNCREATE(CGModViewerView, CView)
BEGIN_MESSAGE_MAP(CGModViewerView, CView)
//{{AFX_MSG_MAP(CGModViewerView)
ON_COMMAND(ID_FILE_OPEN, OnGMODFileOpen)
ON_WM_KEYDOWN()
ON_WM_ERASEBKGND()
ON_WM_SETFOCUS()
ON_COMMAND(ID_PLAY_ANIM, OnPlayAnim)
ON_COMMAND(ID_STOP_ANIM, OnStopAnim)
ON_COMMAND(ID_SKELETON, OnSkeleton)
ON_COMMAND(ID_Frame_Next, OnFrameNext)
ON_COMMAND(ID_Frame_Prev, OnFramePrev)
ON_COMMAND(ID_FILE_NEW, OnFileNew)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CGModViewerView construction/destruction
unsigned int m_nTimer;
CResFile *pResFile;
CGraphics3D *pG3D;
CSimpleMemory *SMemory;
CGfx *pGfx;
CRender3D m_render3D;
CRenderTarget *m_pTarget;
unsigned short* pData;
char ResFileName[MAX_PATH];
CGModViewerView::CGModViewerView()
{
// TODO: add construction code here
InitOK = false;
SMemory = new CSimpleMemory();
if(SMemory == NULL || !SMemory->Init(GLOBAL_MEMORY_SIZE, LOCAL_MEMORY_SIZE))
{
return;
}
pData = (unsigned short *)MALLOC(SCREEN_WIDTH*SCREEN_HEIGHT*sizeof(unsigned short));
pGfx = new CGfx();
pGfx->SetVideoBmp(pGfx->CreateNativeBmp(pData, SCREEN_WIDTH, SCREEN_HEIGHT, true));
pResFile = new CResFile();
STRCPY(ResFileName,"..\\res\\");
/* if(!pResFile->Open(RES_FILE))
{
return false;
}
*/
pG3D = new CGraphics3D();
m_render3D.SetEngine();
FirstTimeInit();
}
CGModViewerView::~CGModViewerView()
{
//ReleaseGlobalResource();
if(pResFile)
{
delete pResFile;
pResFile = NULL;
}
if(pGfx)
{
delete pGfx;
pGfx = NULL;
}
if(SMemory)
{
delete SMemory;
SMemory = NULL;
}
if( pG3D )
{
delete pG3D;
pG3D = NULL;
}
if( pData )
{
FREE(pData);
pData = NULL;
}
}
BOOL CGModViewerView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
//Global Variables
//Vector4s m_eye;
Vector4s m_lookat;
Vector4s m_up;
CMatrix44 m_viewMat;
// camera view
CMatrix44 m_origin;
CMatrix44 m_HorMat;
CMatrix44 m_VerMat;
bool need_erase = true;
int iZoomValue = 100;
bool bPlayAnim = false;
bool bRotateActor = false;
DWORD rgbCurrent=0;
int m_ModelCount = 0;
int m_curModel;
bool bHaveBGMod = false;
int m_CameraAdjustStep = 20;
ModelData pModelData[MODEL_MAX];
int OpenModelFrameCount;
CMatrix44 m_matWorld;
extern CPropertySheet *dlgPropertySheet;
extern CPropPage *Page;
void GetCurLookAt();
void SetViewMatrix();
/////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////
// CGModViewerView drawing
void CGModViewerView::OnDraw(CDC* pDC)
{
CGModViewerDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
if( !m_ModelCount )
return;
CRender3D *pR3d = &m_render3D;
//camera
UpdateView();
//render
pR3d->StartRender3D(); //Milo;forRender3D
int draw_w, draw_h;
draw_w = SCREEN_WIDTH * iZoomValue / 100;
draw_h = SCREEN_HEIGHT * iZoomValue / 100;
CRect rect;
GetClientRect(&rect);
// Find a centerpoint for the bitmap in the client area
int nX = rect.left + 1;//(rect.Width() - draw_w) / 2;
int nY = rect.top + 1;//(rect.Height() - draw_h) / 2;
//Draw Models
for( int i=0; i < m_ModelCount; i++ )
{
if( pModelData[i].Hide )
continue;
pG3D->m_skeleton = 0;
pG3D->m_renderParam = 0;
if( pModelData[i].DisplayMode == DSP_WIRE )
pG3D->m_skeleton = 1;
else if( pModelData[i].DisplayMode == DSP_TRANS )
pG3D->m_renderParam = RP_TRANSPARENT;
else if( pModelData[i].DisplayMode == DSP_COLORKEY )
pG3D->m_renderParam = RP_COLORKEY;
UpdateWorldMat(i);
if( i==m_curModel && bPlayAnim )
{
pModelData[i].curFrame++;
if( pModelData[i].curFrame >= pModelData[i].FrameCount )
pModelData[i].curFrame = 0;
pR3d->RenderModel(i, &m_matWorld, pModelData[i].curFrame);
//Update curFrame in property sheet
if( Page->m_hWnd )
{
Page->m_CurFrame = pModelData[i].curFrame;
Page->UpdateData(FALSE);
Page->Invalidate();
}
need_erase = false;
}
else
pR3d->RenderModel(i, &m_matWorld, pModelData[i].curFrame);
}
CClientDC dc(this);
pR3d->EndRender3D(); //Milo;forRender3D
byte *p24bData = (byte *)Converto24bits((void *)pData, SCREEN_WIDTH*SCREEN_HEIGHT*sizeof(unsigned short));
int new_size = SCREEN_WIDTH*SCREEN_HEIGHT*sizeof(byte)*3;
BITMAPINFO bmpInfo;
memset(&bmpInfo, 0, sizeof(bmpInfo));
bmpInfo.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmpInfo.bmiHeader.biWidth = SCREEN_WIDTH;
bmpInfo.bmiHeader.biHeight = -SCREEN_HEIGHT; // top-down image
bmpInfo.bmiHeader.biPlanes = 1;
bmpInfo.bmiHeader.biBitCount = 24;//16;
bmpInfo.bmiHeader.biCompression = BI_RGB;
bmpInfo.bmiHeader.biSizeImage = new_size;//SCREEN_WIDTH*SCREEN_HEIGHT*sizeof(unsigned short);
//
// Do the StretchDIBits.
//
int iRet = StretchDIBits(dc.m_hDC,
// destination rectangle
nX, nY, draw_w, draw_h,
// source rectangle
0, 0, SCREEN_WIDTH, SCREEN_HEIGHT,
p24bData,//pData,
&bmpInfo,
DIB_RGB_COLORS,
SRCCOPY);
FREE(p24bData);
}
/////////////////////////////////////////////////////////////////////////////
// CGModViewerView printing
BOOL CGModViewerView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CGModViewerView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CGModViewerView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CGModViewerView diagnostics
#ifdef _DEBUG
void CGModViewerView::AssertValid() const
{
CView::AssertValid();
}
void CGModViewerView::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CGModViewerDoc* CGModViewerView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGModViewerDoc)));
return (CGModViewerDoc*)m_pDocument;
}
#endif //_DEBUG
bool CGModViewerView::FirstTimeInit()
{
pG3D->SetEye(&Vector4s(0,-500,100,0));
m_lookat = Vector4s(0,100,0,0);
m_up = Vector4s(0,0,1024,0);
m_ModelCount = 0;
m_curModel = 0;
MEMSET(pModelData, 0, sizeof(ModelData)*MODEL_MAX);
m_render3D.SetModelCount(MODEL_MAX);
m_origin.LookAt(Vector4s(0,-500,100),Vector4s(0,100,0),Vector4s(0,0,100));
m_VerMat.LoadIdentity();
m_HorMat.LoadIdentity();
CompMatrix();
SetViewMatrix();
InitOK = true;
bHaveBGMod = false;
return true;
}
void CGModViewerView::OnGMODFileOpen()
{
// TODO: Add your command handler code here
OPENFILENAMEA ofn;
strcpy(File, "\0");
ZeroMemory(&ofn, sizeof(OPENFILENAMEA));
ofn.lStructSize = sizeof(OPENFILENAMEA);
// ofn.hwndOwner = ;
ofn.lpstrFile = File;
ofn.nMaxFile = sizeof(char) * 8192;
ofn.lpstrFilter = "GMod Text (*.gmod)\0*.gmod\0All Files\0*.*\0\0";
//ofn.lpstrInitialDir = appToAnsi( *(GLastDir[eLASTDIR_UNR]) );
ofn.lpstrDefExt = "gmod";
GetOpenFileName(&ofn);
if( strlen(File) != 0 )
{
//get model name
int ch = '\\';
char modename[32];
strlwr(File);
char *p = strrchr(File, ch);
if( p )
{
p++;
char *q = strstr(File, ".gmod");
if( q )
{
strncpy(modename, p, q-p);
modename[q-p]=0;
if( strstr(modename, "bg"))
if( !bHaveBGMod && strlen(modename) <= 3 )
bHaveBGMod = true;
else if( strlen(modename) <= 3 )
{
MessageBox("Error: Can't open more than one scene GMOD", "ERROR!", MB_OK);
return;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -