Library tutorials & articles
Introduction to Direct 3D
- Introduction
- Project Generation
- Defining the Direct3D class
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.cppvoid CDirect3dView::ProcessGeometry()
{
mD3DEngine.Render();
}
Step 3: Use the Class Wizard to build a message map method for OnInitialUpdate
for the following reasons
- To Instantiate the DirectInput class. The DirectInput class captures all keyboard, mouse, and joystick events.
- To create the DirectGraphics Devices. The DirectGraphic Devices allow the application to manage system and video card resources through apis.
- To Create the DirectMusic class. The DirectMusic class initializes and loads music segments to be played.
- To Create a Timer event running at maximum speed.
- 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
- The include directivs for the directinput, direct3d, and directmusic
- 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
- Arrow key events control camera movement
- 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);
}
Related articles
Related discussion
-
conting repeated words
by Slicksim (2 replies)
-
Can somebody help: CAsyncSOcket class (Client-server networking)
by Mohammad Rastkar (3 replies)
-
custom progress bar in a datagridview with threading
by konikula (1 replies)
-
Calling C++ DLL from C#
by Thushan Fernando (1 replies)
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!
Where can I find out the headers?
include "cdxinput.h"
include "dsnEngine.h"
include "music.h"
Joseph
This thread is for discussions of Introduction to Direct 3D.