Library tutorials & articles

Introduction to Direct 3D

Project Generation

Project Generation

  • Press File
  • Press New
  • Select "Project Workspace"
  • Select MFC Application
  • Call the project "Direct3D"
  • Step 1 select "Multiple Document"
  • Press Next
  • Step 2 Press Next
  • Step 3 Press Next
  • Step 4 Press Next
  • Step 5 Press Next
  • Step 6 Press Finish and Ok

Implementing the DirectSound,Direct3D,DirectInput classes

Step 1: Add the following header and pragma defines to direct3dview.cpp

#include <dinput.h>
#include <basetsd.h>

#pragma comment ( lib, "dxguid.lib" ) /* guiid definitions */
//#if DIRECTINPUT_VERSION == 0x0800
//#pragma comment ( lib, "dinput8.lib" )
//#else
#pragma comment ( lib, "dinput.lib" )
#pragma comment ( lib, "dsound.lib" )
#pragma comment ( lib, "winmm.lib" )
#pragma comment ( lib, "strmbase.lib")
//Direct3D libraries.
#pragma comment ( lib, "d3d8.lib")
#pragma comment ( lib, "d3dx8.lib")
#pragma comment ( lib, "dxerr8.lib" )


Step 2: Create a Method called ProcessGeometry. Add void ProcessGeometry to the direct3dview.h file. Insert source into direct3dview.cpp

void CDirect3dView::ProcessGeometry()
{
     mD3DEngine.Render();
}


Step 3: Use the Class Wizard to build a message map method for OnInitialUpdate for the following reasons

  1. To Instantiate the DirectInput class. The DirectInput class captures all keyboard, mouse, and joystick events.
  2. To create the DirectGraphics Devices. The DirectGraphic Devices allow the application to manage system and video card resources through apis.
  3. To Create the DirectMusic class. The DirectMusic class initializes and loads music segments to be played.
  4. To Create a Timer event running at maximum speed.
  5. Insert the following source into direct3dview.cpp

void CDirect3dView::OnInitialUpdate()
{
   CView::OnInitialUpdate();    #ifdef _WIN64
       HINSTANCE hInst = (HINSTANCE) GetWindowLongPtr( AfxGetMainWnd()->m_hWnd, GWLP_HINSTANCE );
   #else
       HINSTANCE hInst = (HINSTANCE) GetWindowLong( AfxGetMainWnd()->m_hWnd, GWL_HINSTANCE );
   #endif

   mDIInput.Create(hInst,AfxGetMainWnd()->m_hWnd);

   mD3DEngine.InitializeEngine(AfxGetMainWnd()->m_hWnd);
   mD3DEngine.EnvironmentSetup();

   mDXMusic.Create(AfxGetMainWnd()->m_hWnd);
   SetTimer( 0, 0, NULL );
}

Add the following source into direct3dview.h

  1. The include directivs for the directinput, direct3d, and directmusic
  2. Class variables for directinput, direct3d, and directmusic

#include "cdxinput.h"
#include "dsnEngine.h"
#include "music.h"

   Public
   CDXInput mDIInput;
   //3D Engine
   D3DEngine mD3DEngine;
   //Music Manager
   DXMusic mDXMusic;



Step 4 Add Source code to the WM_TIMER method OnTimer

  1. Arrow key events control camera movement
  2. Keys 1 and 2 play music segments

void CDirect3dView::OnTimer(UINT nIDEvent)
{
   // TODO: Add your message handler code here and/or call default
   long MouseX, MouseY;
   HRESULT hr;

   mDIInput.Update();

   mDIInput.GetMouseDeltas(&MouseX, &MouseY);


   if(mDIInput.GetKeyState(CDXKEY_UPARROW))
   {
       mD3DEngine.AdvanceCamera();
   }

   if(mDIInput.GetKeyState(CDXKEY_DOWNARROW))
   {
       mD3DEngine.RetreatCamera();
   }

   if(mDIInput.GetKeyState(CDXKEY_LEFTARROW))
   {
       mD3DEngine.CameraLeft();
   }

   if(mDIInput.GetKeyState(CDXKEY_RIGHTARROW))
   {
       mD3DEngine.CameraRight();
   }

   if(mDIInput.GetKeyState(CDXKEY_LEFTCTRL) || mDIInput.GetKeyState(CDXKEY_RIGHTCTRL))
   {
   }
   if(mDIInput.GetKeyState(CDXKEY_1))
   {
       hr = mDXMusic.g_pMusicSegments[0]->Play( DMUS_SEGF_DEFAULT, mDXMusic.g_p3DAudiopath );
   }
   if (mDIInput.GetKeyState(CDXKEY_2))
   {
       hr = mDXMusic.g_pMusicSegments[1]->Play( DMUS_SEGF_DEFAULT | DMUS_SEGF_SECONDARY,
                                                         mDXMusic.g_p3DAudiopath );
   }

   ProcessGeometry();
   
   CView::OnTimer(nIDEvent);
}

Comments

  1. 02 Aug 2004 at 09:40

    Where can I find out the headers?


    include "cdxinput.h"


    include "dsnEngine.h"


    include "music.h"



    Joseph

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Introduction to Direct 3D.

Leave a comment

Sign in or Join us (it's free).

AddThis

Related discussion

Events coming up

  • Dec 6

    Developing AJAX Web Applications with Castle Monorail

    London, United Kingdom

    Monorail is the model-view-controller engine of the Castle Project, bringing many of the best ideas of Ruby on Rails to the .NET world. In this talk, David De Florinier and Gojko Adzic show how Monorail makes it easy to develop .NET based AJAX applications, and how to use the Castle Project to build Web 2.0 applications effectively. Come to this session if you are a .NET web developer. Everyone is welcome!