// 3DToolsDlg.cpp : implementation file // #include "stdafx.h" #include "Traffic3D.h" #include "3DToolsDlg.h" #include "R3DEngine\\R3DEngine.h" #include #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // C3DToolsDlg dialog C3DToolsDlg::C3DToolsDlg(CWnd* pParent /*=NULL*/) : CDialog(C3DToolsDlg::IDD, pParent) { //{{AFX_DATA_INIT(C3DToolsDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT } void C3DToolsDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(C3DToolsDlg) // NOTE: the ClassWizard will add DDX and DDV calls here //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(C3DToolsDlg, CDialog) //{{AFX_MSG_MAP(C3DToolsDlg) ON_BN_CLICKED(IDC_TEST3D, OnTest3d) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // C3DToolsDlg message handlers void C3DToolsDlg::OnTest3d() { R3DfxHardware my3DCard; // from now on, the global pointer R3DHW can be used. if(R3DHW->InitHardware()==0) return; // start up 3D card AfxBeginThread((AFX_THREADPROC)Test3DThread, NULL); // start testing 3D in a thread //Test3DThread(NULL); } // This is the UINT Test3DThread( LPVOID pParam ) { // This tests the 3D hardware by initialising it, drawing a rotating cube and closing again R3DHW->ActivateTextures(); R3DTexture Tex1; R3DTexture WheelTex; R3DTexture TyreTex; Tex1.Load("c:\\3dfx\\test code\\tourlogo.3df"); WheelTex.Load("c:\\3dfx\\textures\\wheel.3df"); TyreTex.Load("c:\\3dfx\\textures\\tread.3df"); R3DVector tv[10]; // triangle 1 tv[0].SetPosition(180.f, 175.f, 0.f); tv[1].SetPosition(50.f, 50.f, 0.f); tv[2].SetPosition(130.f, 125.f, 0.f); // triangle 2 (part of myModel) tv[3].SetPosition(460.f, 360.f, 30.f); tv[4].SetPosition(460.f, 300.f, 30.f); tv[5].SetPosition(500.f, 330.f, 30.f); // cube tv[6].SetPosition(400.f, 300.f, 0.f); tv[7].SetPosition(460.f, 360.f, 60.f); // rectangle tv[8].SetPosition(50.f, 400.f, 0.f); tv[9].SetPosition(120.f, 470.f, 0.f); R3DCylinder Cyl; Cyl.SetPosition(tv[2], 40.f, 125.f); R3DTriangle Tri2(tv[3], tv[4], tv[5]); R3DCuboid Cube; Cube.SetPosition(tv[6], tv[7]); R3DRectangle Square; Square.SetPosition(tv[8], tv[9]); Cyl.SetupTexture(1.f, 6.4f); Cyl.SetTexture(WheelTex, TyreTex); Cyl.Move(tv[1]); Tri2.SetTexture(Tex1); Cube.SetTexture(Tex1); Square.SetTexture(Tex1); R3DGroup myModel; // combines the cube and the small triangle myModel.AddTail(&Cube); myModel.AddTail(&Tri2); // add the cube and the triangle CTime startTime=CTime::GetCurrentTime(); // start the clock... for(int x=0; x<=360; x++) { R3DHW->BufferClear(); Cyl.Draw(); Square.Draw(); myModel.Draw(); R3DHW->BufferSwap(); Cyl.RotateY(tv[0], 1); // rotate about first vertex Cyl.Spin(10.f); // spin it too! Square.RotateX(tv[8], 1); myModel.RotateX(tv[5], 1); } for(x=0; x<=360; x++) { R3DHW->BufferClear(); Cyl.Draw(); Square.Draw(); myModel.Draw(); R3DHW->BufferSwap(); Cyl.RotateZ(tv[0], 1); // rotate about first vertex Square.RotateY(tv[8], 1); myModel.RotateY(tv[5], 1); } for(x=0; x<=360; x++) { R3DHW->BufferClear(); Cyl.Draw(); Square.Draw(); myModel.Draw(); R3DHW->BufferSwap(); Cyl.RotateX(tv[0], 1); // rotate about first vertex Cyl.Spin(-10.f); // spin the other way! Square.RotateZ(tv[8], 1); myModel.RotateZ(tv[5], 1); } CTime endTime=CTime::GetCurrentTime(); // stop the clock CTimeSpan elapsedTime=endTime - startTime; // measure the difference R3DHW->CloseHardware(); // switch off the 3D card LONG seconds=elapsedTime.GetTotalSeconds(); // the timespan in seconds float framespeed=1080.f/(float)seconds; // work out frames per second CString message; message.Format("Frames per second: %f", framespeed); AfxMessageBox(message, MB_ICONINFORMATION); // display frames per second message box return 0; }