Link to home
Start Free TrialLog in
Avatar of generalcam
generalcam

asked on

DirectXFramework

I need help with the errors below this code that is attached. I have included the header file and the cpp file.  Can anyone please assist me with these errors.

 //////////////////////////////////////////////////////////////////////////
// Name:	DirectXFramework.h
// Date:	April 2nd, 2010
// Author:	Kyle Lauing [klauing@devry.edu] or [kylelauing@gmail.com]
// Purpose: This file is used to create a very simple framework for using
//			DirectX 9 for the GSP 381 course for DeVry University.
// Disclaimer:	
//			Copyright © 2010 by DeVry Educational Development Corporation.
//			All rights reserved.  No part of this work may be reproduced 
//			or used in any form or by any means – graphic, electronic, or 
//			mechanical, including photocopying, recording, Web distribution 
//			or information storage and retrieval systems – without the 
//			prior consent of DeVry Educational Development Corporation.
//////////////////////////////////////////////////////////////////////////
#pragma once
#include <stdio.h>
#include <vector>
#pragma comment(lib, "winmm.lib")
//////////////////////////////////////////////////////////////////////////
// Direct3D 9 headers and libraries required
//////////////////////////////////////////////////////////////////////////
#include <d3d9.h>
#include <d3dx9.h>
#include <DxErr.h>
#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "dxerr.lib")

//////////////////////////////////////////////////////////////////////////
// DirectInput headers and libraries
//////////////////////////////////////////////////////////////////////////
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#pragma comment(lib, "dinput8.lib")
#pragma comment(lib, "dxguid.lib")

//////////////////////////////////////////////////////////////////////////
// To DEBUG D3D correctly:
//&#9;Go to the Start Menu, Find Microsoft DirectX SDK (June 2010).
//  Go to the DirectX Control Panel.
//  In Direct3D 9 settings, Increase the Debug Output Level to the Max
//  Turn on debugging flags for Maximum validation, Break on Memory Leaks, etc.
//////////////////////////////////////////////////////////////////////////

// If in DEBUG mode, turn on D3D_DEBUG_INFO flag enable DXTrace, and d3dx9d.lib (debug version)
#if defined(DEBUG) | defined(_DEBUG)
&#9;#ifndef D3D_DEBUG_INFO
&#9;&#9;#define D3D_DEBUG_INFO
&#9;#endif

&#9;#pragma comment(lib, "d3dx9d.lib")
#else
&#9;#pragma comment(lib, "d3dx9.lib")
#endif

// Macro to release COM objects fast and safely
#define SAFE_RELEASE(x) if(x){x->Release(); x = 0;}

// HRESULT macro that prints an error window
#ifndef HR
#define HR(x)&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;\
&#9;&#9;{                                                   \
&#9;&#9;HRESULT hr = x;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;    \
&#9;&#9;if(FAILED(hr))&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;    \
&#9;&#9;&#9;{                                               \
&#9;&#9;&#9;&#9;MessageBox(m_hWnd, DXGetErrorDescription(hr), DXGetErrorString(hr), MB_OK);&#9;/*DXTraceA(__FILE__, __LINE__, hr, DXGetErrorStringA(hr), TRUE);*/&#9;    \
&#9;&#9;&#9;}                                               \
&#9;&#9;}                                                   
#endif

 class CDirectXFramework
{
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Application Variables
&#9;//////////////////////////////////////////////////////////////////////////
&#9;HWND&#9;&#9;&#9;&#9;m_hWnd;&#9;&#9;&#9;// Handle to the window
&#9;bool&#9;&#9;&#9;&#9;m_bVsync;&#9;&#9;// Boolean for vertical syncing
&#9;int&#9;&#9;&#9;&#9;&#9;m_width;&#9;&#9;// Window width
&#9;int&#9;&#9;&#9;&#9;&#9;m_height;&#9;&#9;// Window height
&#9;RECT&#9;&#9;&#9;&#9;screenRect;&#9;&#9;// RECT for the entire size of window

&#9;float&#9;&#9;&#9;&#9;m_currTime;&#9;&#9;// Time to render current frame
&#9;float&#9;&#9;&#9;&#9;m_prevTime;&#9;&#9;// Time to render previous frame
&#9;int&#9;&#9;&#9;&#9;&#9;m_FPS;&#9;&#9;&#9;// Frames per second
&#9;float&#9;&#9;&#9;&#9;m_elapsedTime;&#9;// ms per frame
&#9;float               m_fRotation;    // Rotation variable for Cube 2
&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Direct3D Variables
&#9;//////////////////////////////////////////////////////////////////////////
&#9;IDirect3D9*&#9;&#9;&#9;  m_pD3DObject;&#9;// Direct3D 9 Object
&#9;IDirect3DDevice9*&#9;  m_pD3DDevice;&#9;// Direct3D 9 Device
&#9;D3DPRESENT_PARAMETERS m_D3Dpp;&#9;&#9;// Device Presentation Parameters
&#9;D3DCAPS9&#9;&#9;&#9;  m_D3DCaps;&#9;// Device Capabilities
&#9;D3DXCOLOR&#9;&#9;&#9;  m_clearColor; // Back-buffer Clear Color

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// View and Projection Matrices
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Set these 3 component to initialize the view matrix (camera)
&#9;D3DXVECTOR3 m_eyePos;
&#9;D3DXVECTOR3 m_lookAt;
&#9;D3DXVECTOR3 m_upVec;
&#9;D3DXVECTOR3 m_pyramidTranslation;
&#9;D3DXVECTOR3 m_pyramidRotation;
&#9;
&#9;// View matrix
&#9;D3DXMATRIX m_viewMat;
&#9;D3DXMATRIX WITMat;

&#9;// Projection matrix
&#9;D3DXMATRIX m_projMat;

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Vertex Declaration and Vertex and Index Buffers
&#9;//////////////////////////////////////////////////////////////////////////
&#9;struct Vertex
&#9;{
&#9;&#9;D3DXVECTOR3 position;
&#9;&#9;D3DXVECTOR3 normal;
&#9;&#9;D3DXVECTOR2 uv;
&#9;};

&#9;
&#9;// Cube data (Vertex and Index array)
&#9;// Could use 8, but cannot texture or define valid normals correctly
&#9;Vertex m_cubeVerts[24];&#9;
&#9;WORD m_cubeIndices[36];

&#9;// Pyramid data
&#9;Vertex m_pyramidVerts[16];&#9;
&#9;WORD m_pyramidIndices[18];
&#9;

&#9;IDirect3DVertexDeclaration9*&#9;m_pD3DVertexDecl;

&#9;// Tri Grcube

&#9;IDirect3DIndexBuffer9* m_pD3DIndexBuffer;
&#9;IDirect3DVertexBuffer9* m_pD3DVertexBuffer;
&#9;IDirect3DVertexBuffer9* m_pD3DVertexBufferPyramid;
&#9;IDirect3DVertexBuffer9* m_pD3DIndexBufferPyramid;

&#9;std::vector<Vertex>&#9;&#9;&#9;&#9;m_triGridVerts;
&#9;std::vector<DWORD>&#9;&#9;&#9;&#9;m_triGridIndices;
&#9;int &#9;&#9;&#9;&#9;&#9;&#9;&#9;m_numVerts;
&#9;int &#9;&#9;&#9;&#9;&#9;&#9;&#9;m_numTris;

&#9;/////////////////////////////////////////////////////////////////////////
    // D3DXMesh - Used for D3DXCreate functions and .x files
    /////////////////////////////////////////////////////////////////////////

        ID3DXBuffer*            m_pXMaterials;
       
        ID3DXBuffer*            m_pXEffects;
       

        //////////////////////////////////////////////////////////////////////////
        // Lighting, Material, Textures
        //////////////////////////////////////////////////////////////////////////
        D3DLIGHT9                       m_Light;
        D3DMATERIAL9&#9;&#9;&#9;&#9;&#9;m_Material;
        D3DMATERIAL9&#9;&#9;&#9;&#9;&#9;m_Material[2];
        //////////////////////////////////////////////////////////////////////////
        // Effects
        //////////////////////////////////////////////////////////////////////////
        ID3DXEffect*&#9;&#9;&#9;&#9;&#9;m_pEffect;
        ID3DXBuffer*            m_pEffectError;
        D3DXHANDLE                      m_hTech;


    //////////////////////////////////////////////////////////////////////////
&#9;// Font Variables
&#9;//////////////////////////////////////////////////////////////////////////
&#9;ID3DXFont*&#9;&#9;&#9;m_pD3DFont;&#9;&#9;// Font Object

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Sprite Variables
&#9;//////////////////////////////////////////////////////////////////////////
&#9;ID3DXSprite*&#9;&#9;m_pD3DSprite;&#9;// Sprite Object
&#9;IDirect3DTexture9*&#9;m_pTexture;&#9;&#9;// Texture Object for a sprite
&#9;//D3DXIMAGE_INFO&#9;&#9;m_imageInfo;&#9;// File details of a texture

&#9;IDirect3DTexture9*&#9;m_pTexture2;&#9;// Second sprite image
&#9;//D3DXIMAGE_INFO&#9;&#9;m_imageInfo2;&#9;// File details of 2nd texture


&#9;// A structure of sprite information to use for sprites, so we can initialize
&#9;// values for each sprite in the init, and use them in the render() function
&#9;struct SpriteObject
&#9;{
&#9;&#9;D3DXVECTOR3 position;&#9;// Translation
&#9;&#9;float rotation;&#9;&#9;&#9;// Z rotation
&#9;&#9;float scale;&#9;&#9;&#9;// Uniform scaling (x and y value the same)
&#9;&#9;D3DCOLOR color;&#9;&#9;&#9;// Color modulation
&#9;};

&#9;SpriteObject spriteObj[6];&#9;// Array of sprite values to be used

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// DirectInput
&#9;//////////////////////////////////////////////////////////////////////////
&#9;IDirectInput8*&#9;&#9; m_pDIObject;&#9;// DirectInput Object
&#9;IDirectInputDevice8* m_pDIKeyboard;&#9;// Keyboard Device
&#9;IDirectInputDevice8* m_pDIMouse;&#9;// Mouse Device 

public:
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Init and Shutdown are preferred to constructors and destructor,
&#9;// due to having more control when to explicitly call them when global.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;CDirectXFramework(void);
&#9;~CDirectXFramework(void);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;Init
&#9;// Parameters:&#9;HWND hWnd - Handle to the window for the application
&#9;//&#9;&#9;&#9;&#9;HINSTANCE hInst - Handle to the application instance
&#9;//&#9;&#9;&#9;&#9;bool bWindowed - Boolean to control windowed or full-screen
&#9;// Return:&#9;&#9;void
&#9;// Description:&#9;Ran once at the start.  Initialize DirectX components and 
&#9;//&#9;&#9;&#9;&#9;variables to control the application.  
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void Init(HWND& hWnd, HINSTANCE& hInst, bool bWindowed);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;Update
&#9;// Parameters:&#9;float elapsedTime - Time that has elapsed since the last
&#9;//&#9;&#9;&#9;&#9;&#9;update call.
&#9;// Return:&#9;&#9;void
&#9;// Description: Runs every frame, use dt to limit functionality called to
&#9;//&#9;&#9;&#9;&#9;a certain amount of elapsed time that has passed.  Used 
&#9;//&#9;&#9;&#9;&#9;for updating variables and processing input commands prior
&#9;//&#9;&#9;&#9;&#9;to calling render.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void Update(float dt);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;Render
&#9;// Parameters:&#9;float elapsedTime - Time that has elapsed since the last
&#9;//&#9;&#9;&#9;&#9;&#9;render call.
&#9;// Return:&#9;&#9;void
&#9;// Description: Runs every frame, use dt to limit functionality called to
&#9;//&#9;&#9;&#9;&#9;a certain amount of elapsed time that has passed.  Render
&#9;//&#9;&#9;&#9;&#9;calls all draw call to render objects to the screen.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void Render(float dt);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;Shutdown
&#9;// Parameters:&#9;void
&#9;// Return:&#9;&#9;void
&#9;// Description:&#9;Runs once at the end of an application.  Destroy COM 
&#9;//&#9;&#9;&#9;&#9;objects and deallocate dynamic memory.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void Shutdown();

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Skinned Animation Functions
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void DrawBoundingBoxes();
&#9;void CDirectXFramework::GenTriGrid(int numVertRows, int numVertCols, float dx, float dz, const D3DXVECTOR3& center, 
&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;   std::vector<Vertex>& verts, std::vector<DWORD>& indices);

&#9;void CDirectXFramework::soundsInit();
&#9;void CDirectXFramework::videosInit();

&#9;void CDirectXFramework::initWindow(HWND& hWnd, bool bWindowed);
&#9;void CDirectXFramework::initViewProjAndMatrices();
&#9;void CDirectXFramework::initVertexDecl();
&#9;void CDirectXFramework::initTriGrid();
&#9;void CDirectXFramework::initBasicMeshes();
&#9;void CDirectXFramework::initStaticXMeshes();
&#9;void CDirectXFramework::initLights();
&#9;void CDirectXFramework::initMaterials();
&#9;void CDirectXFramework::initTextures();
&#9;void CDirectXFramework::initShaderEffects();
&#9;void CDirectXFramework::initFonts();
&#9;void CDirectXFramework::initDirectInput(HWND& hWnd, HINSTANCE& hInst);
&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;isDeviceLost
&#9;// Parameters:&#9;void
&#9;// Return:&#9;&#9;bool
&#9;// Description:&#9;If the device is lost due to various reasons (Alt+Tab in
&#9;//&#9;&#9;&#9;&#9;full-screen mode, etc.) this function will return true,
&#9;//&#9;&#9;&#9;&#9;so that it can be restored.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;bool isDeviceLost();

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;onLostDevice
&#9;// Parameters:&#9;void
&#9;// Return:&#9;&#9;bool
&#9;// Description:&#9;If a device has been lost, clean up COM objects that must
&#9;//&#9;&#9;&#9;&#9;be reallocated during the onResetDevice()
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void onLostDevice();

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Name:&#9;&#9;onResetDevice
&#9;// Parameters:&#9;void
&#9;// Return:&#9;&#9;bool
&#9;// Description:&#9;If a device has been restored, reinitialize COM objects
&#9;//&#9;&#9;&#9;&#9;that were lost.
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void onResetDevice();

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Accessors
&#9;//////////////////////////////////////////////////////////////////////////
&#9;int getResolutionWidth() {return m_width;}
&#9;int getResolutionHeight() {return m_height;}

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Modifiers
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void setResolution(int w, int h) 
&#9;{
&#9;&#9;m_width = w; 
&#9;&#9;m_height = h;
&#9;&#9;if(m_pD3DDevice)
&#9;&#9;{
&#9;&#9;&#9;m_D3Dpp.BackBufferWidth = m_width;
&#9;&#9;&#9;onLostDevice(); 
&#9;&#9;&#9;HR(m_pD3DDevice->Reset(&m_D3Dpp));
&#9;&#9;&#9;onResetDevice();
&#9;&#9;
&#9;&#9;}
&#9;}
};


//////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////
// Name:&#9;DirectXFramework.cpp
// Date:&#9;April 2nd, 2010
// Author:&#9;Kyle Lauing [klauing@devry.edu] or [kylelauing@gmail.com]
// Purpose: This file is used to create a very simple framework for using
//&#9;&#9;&#9;DirectX 9 for the GSP 381 course for DeVry University.
// Disclaimer:&#9;
//&#9;&#9;&#9;Copyright © 2010 by DeVry Educational Development Corporation.
//&#9;&#9;&#9;All rights reserved.  No part of this work may be reproduced 
//&#9;&#9;&#9;or used in any form or by any means – graphic, electronic, or 
//&#9;&#9;&#9;mechanical, including photocopying, recording, Web distribution 
//&#9;&#9;&#9;or information storage and retrieval systems – without the 
//&#9;&#9;&#9;prior consent of DeVry Educational Development Corporation.
//////////////////////////////////////////////////////////////////////////
#include "DirectXFramework.h"
#include <math.h>

CDirectXFramework::CDirectXFramework(void)
{
&#9;// Init or NULL objects before use to avoid any undefined behavior
&#9;m_bVsync&#9;&#9;&#9;&#9;= false;
&#9;m_pD3DObject&#9;&#9;&#9;= 0;
&#9;m_pD3DDevice&#9;&#9;&#9;= 0;
&#9;m_pD3DFont&#9;&#9;&#9;&#9;= 0;&#9;&#9;
&#9;m_pDIObject&#9;&#9;&#9;&#9;= 0;&#9;
&#9;m_pDIKeyboard&#9;&#9;&#9;= 0;&#9;
&#9;m_pDIMouse&#9;&#9;&#9;&#9;= 0;&#9;
&#9;m_currTime&#9;&#9;&#9;&#9;= 0;
&#9;m_prevTime&#9;&#9;&#9;&#9;= 0;
&#9;m_fRotation&#9;&#9;&#9;&#9;= 0.0f;
&#9;m_pyramidTranslation&#9;= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
&#9;m_pyramidRotation&#9;&#9;= D3DXVECTOR3(0.0f, 0.0f, 0.0f);
&#9;m_pyramidScaling&#9;&#9;= 1.0f;
&#9;
}

CDirectXFramework::~CDirectXFramework(void)
{
&#9;// If Shutdown is not explicitly called correctly, call it when 
&#9;// this class is destroyed or falls out of scope as an error check.
&#9;Shutdown();
}

void CDirectXFramework::Init(HWND& hWnd, HINSTANCE& hInst, bool bWindowed)
{
&#9;m_hWnd = hWnd;

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Direct3D Foundations - D3D Object, Present Parameters, and D3D Device
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Create the D3D Object
&#9;m_pD3DObject = Direct3DCreate9(D3D_SDK_VERSION);

&#9;// Find the width and height of window using hWnd and GetWindowRect()
&#9;RECT rect;
&#9;GetWindowRect(hWnd, &rect);
&#9;int width = rect.right - rect.left;
&#9;int height = rect.bottom - rect.top;

&#9;// Set D3D Device presentation parameters before creating the device
&#9;D3DPRESENT_PARAMETERS D3Dpp;
&#9;ZeroMemory(&D3Dpp, sizeof(D3Dpp));  // NULL the structure's memory

&#9;D3Dpp.hDeviceWindow&#9;&#9;&#9;&#9;&#9;= hWnd;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Handle to the focus window
&#9;D3Dpp.Windowed&#9;&#9;&#9;&#9;&#9;&#9;= bWindowed;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Windowed or Full-screen boolean
&#9;D3Dpp.AutoDepthStencilFormat&#9;&#9;= D3DFMT_D24S8;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Format of depth/stencil buffer, 24 bit depth, 8 bit stencil
&#9;D3Dpp.EnableAutoDepthStencil&#9;&#9;= TRUE;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Enables Z-Buffer (Depth Buffer)
&#9;D3Dpp.BackBufferCount&#9;&#9;&#9;&#9;= 1;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Change if need of > 1 is required at a later date
&#9;D3Dpp.BackBufferFormat&#9;&#9;&#9;&#9;= D3DFMT_X8R8G8B8;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Back-buffer format, 8 bits for each pixel
&#9;D3Dpp.BackBufferHeight&#9;&#9;&#9;&#9;= height;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Make sure resolution is supported, use adapter modes
&#9;D3Dpp.BackBufferWidth&#9;&#9;&#9;&#9;= width;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// (Same as above)
&#9;D3Dpp.SwapEffect&#9;&#9;&#9;&#9;&#9;= D3DSWAPEFFECT_DISCARD;&#9;&#9;&#9;&#9;&#9;// Discard back-buffer, must stay discard to support multi-sample
&#9;D3Dpp.PresentationInterval&#9;&#9;&#9;= m_bVsync ? D3DPRESENT_INTERVAL_DEFAULT : D3DPRESENT_INTERVAL_IMMEDIATE; // Present back-buffer immediately, unless V-Sync is on&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;
&#9;D3Dpp.Flags&#9;&#9;&#9;&#9;&#9;&#9;&#9;= D3DPRESENTFLAG_DISCARD_DEPTHSTENCIL;&#9;&#9;// This flag should improve performance, if not set to NULL.
&#9;D3Dpp.FullScreen_RefreshRateInHz&#9;= bWindowed ? 0 : D3DPRESENT_RATE_DEFAULT;&#9;// Full-screen refresh rate, use adapter modes or default

&#9;DWORD quality;
&#9;m_pD3DObject->CheckDeviceMultiSampleType(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, 
&#9;&#9;D3DFMT_X8R8G8B8, bWindowed, D3DMULTISAMPLE_4_SAMPLES, &quality);

&#9;//D3Dpp.MultiSampleQuality&#9;&#9;&#9;= quality - 1;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Must use quality, returned from CheckDeviceMultiSampleType(), minus one.
&#9;//D3Dpp.MultiSampleType&#9;&#9;&#9;&#9;= D3DMULTISAMPLE_4_SAMPLES;&#9;&#9;&#9;&#9;&#9;// 4x Multisampling.  Device caps can let you know which MSAA is supported.

&#9;D3Dpp.MultiSampleQuality&#9;&#9;&#9;= 0;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// MSAA currently off, check documentation for support.
&#9;D3Dpp.MultiSampleType&#9;&#9;&#9;&#9;= D3DMULTISAMPLE_NONE;&#9;&#9;&#9;&#9;&#9;// MSAA currently off, check documentation for support.

&#9;// Check device capabilities
&#9;DWORD deviceBehaviorFlags = 0;
&#9;m_pD3DObject->GetDeviceCaps(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, &m_D3DCaps);

&#9;// Determine vertex processing mode
&#9;if(m_D3DCaps.DevCaps & D3DCREATE_HARDWARE_VERTEXPROCESSING)
&#9;{
&#9;&#9;// Hardware vertex processing supported? (Video Card)
&#9;&#9;deviceBehaviorFlags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;&#9;
&#9;}
&#9;else
&#9;{
&#9;&#9;// If not, use software (CPU)
&#9;&#9;deviceBehaviorFlags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING; 
&#9;}

&#9;// If hardware vertex processing is on, check pure device support
&#9;if(m_D3DCaps.DevCaps & D3DDEVCAPS_PUREDEVICE && deviceBehaviorFlags & D3DCREATE_HARDWARE_VERTEXPROCESSING)
&#9;{
&#9;&#9;deviceBehaviorFlags |= D3DCREATE_PUREDEVICE;&#9;
&#9;}

&#9;// Create the D3D Device with the present parameters and device flags above
&#9;m_pD3DObject->CreateDevice(
&#9;&#9;D3DADAPTER_DEFAULT,&#9;&#9;// which adapter to use, set to primary
&#9;&#9;D3DDEVTYPE_HAL,&#9;&#9;&#9;// device type to use, set to hardware rasterization
&#9;&#9;hWnd,&#9;&#9;&#9;&#9;&#9;// handle to the focus window
&#9;&#9;deviceBehaviorFlags,&#9;// behavior flags
&#9;&#9;&D3Dpp,&#9;&#9;&#9;&#9;&#9;// presentation parameters
&#9;&#9;&m_pD3DDevice);&#9;&#9;&#9;// returned device pointer

&#9;//////////////////////////////////////////////////////////////////////////&#9;
&#9;// View and Projection Matrices
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Initialize View Matrix
&#9;m_eyePos&#9;= D3DXVECTOR3(0.0f, 2.0f, -10.0f);&#9;// Camera position
&#9;m_lookAt&#9;= D3DXVECTOR3(0.0f, 0.0f, 0.0f);&#9;// Position camera is viewing
&#9;m_upVec&#9;&#9;= D3DXVECTOR3(0.0f, 1.0f, 0.0f);&#9;// Rotational orientation 

&#9;// Easily calculate the view matrix with 3 intuitive vectors
&#9;D3DXMatrixLookAtLH(
&#9;&#9;&m_viewMat,&#9;// Returned viewMat
&#9;&#9;&m_eyePos,&#9;// Eye Position
&#9;&#9;&m_lookAt,&#9;// LookAt Position
&#9;&#9;&m_upVec);&#9;// Up Vector

&#9;// Apply the view matrix in the scene
&#9;m_pD3DDevice->SetTransform(D3DTS_VIEW, &m_viewMat);

&#9;// Initialize perspective projection matrix, this creates view frustum
&#9;D3DXMatrixPerspectiveFovLH(
&#9;&#9;&m_projMat,&#9;&#9;&#9;&#9;&#9;&#9;// Returned ProjMat
&#9;&#9;D3DXToRadian(65.0f),&#9;&#9;&#9;// Field of View
&#9;&#9;(float)width / (float)height,&#9;// Aspect Ratio
&#9;&#9;1.0f,&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Near Plane
&#9;&#9;1000.0f);&#9;&#9;&#9;&#9;&#9;&#9;// Far Plane

&#9;//// Apply the projection matrix in the scene
&#9;//m_pD3DDevice->SetTransform(D3DTS_PROJECTION, &m_projMat);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Vertex Declaration and Vertex and Index Buffers
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Vertex declaration
&#9;D3DVERTEXELEMENT9 decl[] =
&#9;{
&#9;&#9;{0, 0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0},
&#9;&#9;{0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0},
&#9;&#9;{0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0},
&#9;&#9;D3DDECL_END()
&#9;};
&#9;// Create vertex declaration
&#9;m_pD3DDevice->CreateVertexDeclaration(decl, &m_pD3DVertexDecl);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Load cube data (verts and indices) into respective arrays
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Load vertex info 

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Cube
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Front
&#9;m_cubeVerts[0].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;m_cubeVerts[1].position = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
&#9;m_cubeVerts[2].position = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
&#9;m_cubeVerts[3].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[0].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[1].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[2].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[3].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f));
&#9;m_cubeVerts[0].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[1].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[2].uv = D3DXVECTOR2(1.0f, 0.0f);
&#9;m_cubeVerts[3].uv = D3DXVECTOR2(1.0f, 1.0f);

&#9;// Back
&#9;m_cubeVerts[4].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;m_cubeVerts[5].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;m_cubeVerts[6].position = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
&#9;m_cubeVerts[7].position = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[4].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[5].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[6].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[7].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f));
&#9;m_cubeVerts[4].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_cubeVerts[5].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[6].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[7].uv = D3DXVECTOR2(1.0f, 0.0f);

&#9;// Top
&#9;m_cubeVerts[8].position = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
&#9;m_cubeVerts[9].position = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
&#9;m_cubeVerts[10].position = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
&#9;m_cubeVerts[11].position = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[8].normal, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[9].normal, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[10].normal, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[11].normal, &D3DXVECTOR3(0.0f, 1.0f, 0.0f));
&#9;m_cubeVerts[8].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[9].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[10].uv = D3DXVECTOR2(1.0f, 0.0f);
&#9;m_cubeVerts[11].uv = D3DXVECTOR2(1.0f, 1.0f);

&#9;// Bottom
&#9;m_cubeVerts[12].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;m_cubeVerts[13].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;m_cubeVerts[14].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;m_cubeVerts[15].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[12].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[13].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[14].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[15].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;m_cubeVerts[12].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_cubeVerts[13].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[14].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[15].uv = D3DXVECTOR2(1.0f, 0.0f);

&#9;// Left
&#9;m_cubeVerts[16].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;m_cubeVerts[17].position = D3DXVECTOR3(-1.0f, 1.0f, 1.0f);
&#9;m_cubeVerts[18].position = D3DXVECTOR3(-1.0f, 1.0f, -1.0f);
&#9;m_cubeVerts[19].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[16].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[17].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[18].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[19].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f));
&#9;m_cubeVerts[16].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[17].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[18].uv = D3DXVECTOR2(1.0f, 0.0f);
&#9;m_cubeVerts[19].uv = D3DXVECTOR2(1.0f, 1.0f);

&#9;// Right
&#9;m_cubeVerts[20].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;m_cubeVerts[21].position = D3DXVECTOR3(1.0f, 1.0f, -1.0f);
&#9;m_cubeVerts[22].position = D3DXVECTOR3(1.0f, 1.0f, 1.0f);
&#9;m_cubeVerts[23].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_cubeVerts[20].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[21].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[22].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_cubeVerts[23].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f));
&#9;m_cubeVerts[20].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_cubeVerts[21].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_cubeVerts[22].uv = D3DXVECTOR2(1.0f, 0.0f);
&#9;m_cubeVerts[23].uv = D3DXVECTOR2(1.0f, 1.0f);


&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Pyramid
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Bottom
&#9;m_pyramidVerts[0].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;m_pyramidVerts[1].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;m_pyramidVerts[2].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;m_pyramidVerts[3].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_pyramidVerts[0].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_pyramidVerts[1].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_pyramidVerts[2].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;D3DXVec3Normalize(&m_pyramidVerts[3].normal, &D3DXVECTOR3(0.0f, -1.0f, 0.0f));
&#9;m_pyramidVerts[0].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_pyramidVerts[1].uv = D3DXVECTOR2(0.0f, 1.0f);
&#9;m_pyramidVerts[2].uv = D3DXVECTOR2(0.0f, 0.0f);
&#9;m_pyramidVerts[3].uv = D3DXVECTOR2(1.0f, 0.0f);

&#9;// Front
&#9;m_pyramidVerts[4].position = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
&#9;m_pyramidVerts[5].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;m_pyramidVerts[6].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;D3DXVec3Normalize(&m_pyramidVerts[4].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[5].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[6].normal, &D3DXVECTOR3(0.0f, 0.0f, -1.0f ));
&#9;m_pyramidVerts[4].uv = D3DXVECTOR2(0.5f, 0.0f);
&#9;m_pyramidVerts[5].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_pyramidVerts[6].uv = D3DXVECTOR2(0.0f, 1.0f);

&#9;// Back
&#9;m_pyramidVerts[7].position = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
&#9;m_pyramidVerts[8].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;m_pyramidVerts[9].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_pyramidVerts[7].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[8].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[9].normal, &D3DXVECTOR3(0.0f, 0.0f, 1.0f ));
&#9;m_pyramidVerts[7].uv = D3DXVECTOR2(0.5f, 0.0f);
&#9;m_pyramidVerts[8].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_pyramidVerts[9].uv = D3DXVECTOR2(0.0f, 1.0f);

&#9;// Left
&#9;m_pyramidVerts[10].position = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
&#9;m_pyramidVerts[11].position = D3DXVECTOR3(-1.0f, -1.0f, -1.0f);
&#9;m_pyramidVerts[12].position = D3DXVECTOR3(-1.0f, -1.0f, 1.0f);
&#9;D3DXVec3Normalize(&m_pyramidVerts[10].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[11].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[12].normal, &D3DXVECTOR3(-1.0f, 0.0f, 0.0f ));
&#9;m_pyramidVerts[10].uv = D3DXVECTOR2(0.5f, 0.0f);
&#9;m_pyramidVerts[11].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_pyramidVerts[12].uv = D3DXVECTOR2(0.0f, 1.0f);

&#9;// Right
&#9;m_pyramidVerts[13].position = D3DXVECTOR3(0.0f, 1.0f, 0.0f);
&#9;m_pyramidVerts[14].position = D3DXVECTOR3(1.0f, -1.0f, 1.0f);
&#9;m_pyramidVerts[15].position = D3DXVECTOR3(1.0f, -1.0f, -1.0f);
&#9;D3DXVec3Normalize(&m_pyramidVerts[13].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[14].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f ));
&#9;D3DXVec3Normalize(&m_pyramidVerts[15].normal, &D3DXVECTOR3(1.0f, 0.0f, 0.0f ));
&#9;m_pyramidVerts[13].uv = D3DXVECTOR2(0.5f, 0.0f);
&#9;m_pyramidVerts[14].uv = D3DXVECTOR2(1.0f, 1.0f);
&#9;m_pyramidVerts[15].uv = D3DXVECTOR2(0.0f, 1.0f);

&#9;// Load index info, refers into index into verts array to compose triangles
&#9;// Note: A clockwise winding order of verts will show the front face.

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Cube
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Front
&#9;m_cubeIndices[0] = 0;  m_cubeIndices[1] = 1;  m_cubeIndices[2] = 2;&#9;&#9;// Triangle 0
&#9;m_cubeIndices[3] = 0;  m_cubeIndices[4] = 2;  m_cubeIndices[5] = 3;&#9;&#9;// Triangle 1
&#9;// Back
&#9;m_cubeIndices[6] = 4;  m_cubeIndices[7] = 5;  m_cubeIndices[8] = 6;&#9;&#9;// Triangle 2
&#9;m_cubeIndices[9] = 4;  m_cubeIndices[10] = 6; m_cubeIndices[11] = 7;&#9;// Triangle 3
&#9;// Top
&#9;m_cubeIndices[12] = 8; m_cubeIndices[13] = 9; m_cubeIndices[14] = 10;&#9;// Triangle 4
&#9;m_cubeIndices[15] = 8; m_cubeIndices[16] = 10; m_cubeIndices[17] = 11;&#9;// Triangle 5
&#9;// Bottom
&#9;m_cubeIndices[18] = 12; m_cubeIndices[19] = 13; m_cubeIndices[20] = 14;&#9;// Triangle 6
&#9;m_cubeIndices[21] = 12; m_cubeIndices[22] = 14; m_cubeIndices[23] = 15;&#9;// Triangle 7
&#9;// Left
&#9;m_cubeIndices[24] = 16; m_cubeIndices[25] = 17; m_cubeIndices[26] = 18;&#9;// Triangle 8
&#9;m_cubeIndices[27] = 16; m_cubeIndices[28] = 18; m_cubeIndices[29] = 19;&#9;// Triangle 9
&#9;// Right
&#9;m_cubeIndices[30] = 20; m_cubeIndices[31] = 21; m_cubeIndices[32] = 22;&#9;// Triangle 10
&#9;m_cubeIndices[33] = 20; m_cubeIndices[34] = 22; m_cubeIndices[35] = 23;&#9;// Triangle 11

&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Pyramid
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Bottom
&#9;m_pyramidIndices[0] = 0; m_pyramidIndices[1] = 1; m_pyramidIndices[2] = 2;&#9;&#9;// Triangle 0
&#9;m_pyramidIndices[3] = 0; m_pyramidIndices[4] = 2; m_pyramidIndices[5] = 3;&#9;&#9;// Triangle 1

&#9;// Front
&#9;m_pyramidIndices[6] = 4; m_pyramidIndices[7] = 5; m_pyramidIndices[8] = 6;&#9;&#9;// Triangle 2
&#9;// Back
&#9;m_pyramidIndices[9] = 7; m_pyramidIndices[10] = 8; m_pyramidIndices[11] = 9;&#9;// Triangle 3

&#9;// Left
&#9;m_pyramidIndices[12] = 10; m_pyramidIndices[13] = 11; m_pyramidIndices[14] = 12;// Triangle 4

&#9;// Right
&#9;m_pyramidIndices[15] = 13; m_pyramidIndices[16] = 14; m_pyramidIndices[17] = 15;// Triangle 5

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Cube
&#9;// Create Vertex Buffer
&#9;m_pD3DDevice->CreateVertexBuffer(
&#9;&#9;4 * 6 * sizeof(Vertex),&#9;// Length in bytes to allocate buffer (num quads * num sides * sizeof(Vertex))
&#9;&#9;D3DUSAGE_WRITEONLY,&#9;&#9;// Usage
&#9;&#9;0,&#9;&#9;&#9;&#9;&#9;&#9;// Used only with FVF, we are not using
&#9;&#9;D3DPOOL_MANAGED,&#9;&#9;// Memory Pool
&#9;&#9;&m_pD3DVertexBuffer,&#9;// Vertex Buffer
&#9;&#9;0);&#9;&#9;&#9;&#9;&#9;&#9;// No longer used, set to 0

&#9;// Create Index Buffer
&#9;m_pD3DDevice->CreateIndexBuffer(
&#9;&#9;3 * 12 * sizeof(WORD),&#9;// Length in bytes to allocate buffer (3 verts * num triangles * sizeof(WORD))
&#9;&#9;D3DUSAGE_WRITEONLY,&#9;&#9;// Usage
&#9;&#9;D3DFMT_INDEX16,&#9;&#9;&#9;// Index Format
&#9;&#9;D3DPOOL_MANAGED,&#9;&#9;// Memory Pool
&#9;&#9;&m_pD3DIndexBuffer,&#9;&#9;// Index Buffer
&#9;&#9;0);&#9;&#9;&#9;&#9;&#9;&#9;// No longer used

&#9;// Pyramid
&#9;// Create Vertex Buffer
&#9;m_pD3DDevice->CreateVertexBuffer(
&#9;&#9;16 * sizeof(Vertex),&#9;&#9;// Length in bytes to allocate buffer (num quads * num sides * sizeof(Vertex))
&#9;&#9;D3DUSAGE_WRITEONLY,&#9;&#9;&#9;// Usage
&#9;&#9;0,&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Used only with FVF, we are not using
&#9;&#9;D3DPOOL_MANAGED,&#9;&#9;&#9;// Memory Pool
&#9;&#9;&m_pD3DVertexBufferPyramid,&#9;// Vertex Buffer
&#9;&#9;0);&#9;&#9;&#9;&#9;&#9;&#9;&#9;// No longer used, set to 0

&#9;// Create Index Buffer
&#9;m_pD3DDevice->CreateIndexBuffer(
&#9;&#9;18 * sizeof(WORD),&#9;&#9;&#9;// Length in bytes to allocate buffer (3 verts * num triangles * sizeof(WORD))
&#9;&#9;D3DUSAGE_WRITEONLY,&#9;&#9;&#9;// Usage
&#9;&#9;D3DFMT_INDEX16,&#9;&#9;&#9;&#9;// Index Format
&#9;&#9;D3DPOOL_MANAGED,&#9;&#9;&#9;// Memory Pool
&#9;&#9;&m_pD3DIndexBufferPyramid,&#9;// Index Buffer
&#9;&#9;0);&#9;&#9;&#9;&#9;&#9;&#9;&#9;// No longer used

&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Accessing vertex buffer memory
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void* pVerts;
&#9;// Cube
&#9;// Lock vertex buffer
&#9;m_pD3DVertexBuffer->Lock(
&#9;&#9;0,&#9;&#9;&#9;// Offset to Lock (0 locks entire buffer)
&#9;&#9;0,&#9;&#9;&#9;// Size to Lock (0 locks entire buffer)
&#9;&#9;&pVerts,&#9;// Double pointer to data
&#9;&#9;0);&#9;&#9;&#9;// Flags

&#9;// Modify data
&#9;memcpy(pVerts, m_cubeVerts, 4 * 6 * sizeof(Vertex));

&#9;// Unlock vertex buffer
&#9;m_pD3DVertexBuffer->Unlock();

&#9;// Pyramid
&#9;// Lock vertex buffer
&#9;m_pD3DVertexBufferPyramid->Lock(
&#9;&#9;0,&#9;&#9;&#9;// Offset to Lock (0 locks entire buffer)
&#9;&#9;0,&#9;&#9;&#9;// Size to Lock (0 locks entire buffer)
&#9;&#9;&pVerts,&#9;// Double pointer to data
&#9;&#9;0);&#9;&#9;&#9;// Flags

&#9;// Modify data
&#9;memcpy(pVerts, m_pyramidVerts, 16 * sizeof(Vertex));

&#9;// Unlock vertex buffer
&#9;m_pD3DVertexBufferPyramid->Unlock();
&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Accessing index buffer memory
&#9;//////////////////////////////////////////////////////////////////////////
&#9;void* pIndices;
&#9;// Cube
&#9;// Lock index buffer
&#9;m_pD3DIndexBuffer->Lock(
&#9;&#9;0,&#9;&#9;&#9;// Offset to Lock (0 locks entire buffer)
&#9;&#9;0,&#9;&#9;&#9;// Size to Lock (0 locks entire buffer)
&#9;&#9;&pIndices,&#9;// Double pointer to data
&#9;&#9;0);&#9;&#9;&#9;// Flags

&#9;// Modify data
&#9;memcpy(pIndices, m_cubeIndices, 3 * 12 * sizeof(WORD));

&#9;// Unlock index buffer
&#9;m_pD3DIndexBuffer->Unlock();

&#9;// Pyramid
&#9;// Lock index buffer
&#9;m_pD3DIndexBufferPyramid->Lock(
&#9;&#9;0,&#9;&#9;&#9;// Offset to Lock (0 locks entire buffer)
&#9;&#9;0,&#9;&#9;&#9;// Size to Lock (0 locks entire buffer)
&#9;&#9;&pIndices,&#9;// Double pointer to data
&#9;&#9;0);&#9;&#9;&#9;// Flags

&#9;// Modify data
&#9;memcpy(pIndices, m_pyramidIndices, 18 * sizeof(WORD));

&#9;// Unlock index buffer
&#9;m_pD3DIndexBufferPyramid->Unlock();

&#9;
&#9;/////////////////////////////////////////////////////////////////////////////////////////////////////////////
&#9;//Create effect
&#9;D3DXCreateEffectFromFile(m_pD3DDevice, L"Lab5.fx", 0, 0,D3DXSHADER_DEBUG | D3DXSHADER_SKIPOPTIMIZATION, 0, &m_pEffect, &m_pEffectError);

&#9;// find the best techniq
&#9;m_hTech = m_pEffect->GetTechniqueByName("tech0");

&#9;// Print errors, if any
&#9;m_pEffectError = 0; // defined locally

&#9;if(m_pEffectError)
&#9;{
&#9;&#9;MessageBoxA(0, (char*)m_pEffectError->GetBufferPointer(), "Lab5.fx - Load Error", MB_OK);
&#9;}



&#9;// Enable Z-Buffer (Depth Buffer), Make sure you have:
&#9;// The two presentation parameters set
&#9;//// The flag in the Clear function
&#9;m_pD3DDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);
&#9;m_pD3DDevice->SetRenderState(D3DRS_SPECULARENABLE, TRUE);
&#9;m_pD3DDevice->SetRenderState(D3DRS_AMBIENT, D3DCOLOR_XRGB(60, 60, 60));

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Lighting, Material, and Texture
&#9;//////////////////////////////////////////////////////////////////////////

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Light
&#9;//////////////////////////////////////////////////////////////////////////
&#9;ZeroMemory(&m_Light, sizeof(m_Light));

&#9;// Ambient light color emitted from this light
&#9;m_Light.Ambient = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
&#9;// Diffuse light color emitted from this light
&#9;m_Light.Diffuse = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
&#9;// Specular light color emitted from this light
&#9;m_Light.Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);
&#9;// Light Type (Point) Requires: Position, Range, Attenuation
&#9;m_Light.Type = D3DLIGHT_POINT;&#9;// Point, alternatively D3DLIGHT_DIRECTIONAL or D3DLIGHT_SPOT
&#9;// Light Position
&#9;m_Light.Position = D3DXVECTOR3(30.0f, 10.0f, -10.0f); 
&#9;// Range of Light
&#9;m_Light.Range = 100.0f;
&#9;// Light Attenuation
&#9;m_Light.Attenuation0 = 0.0f;&#9;// Constant
&#9;m_Light.Attenuation1 = 0.05f;&#9;// Linear
&#9;m_Light.Attenuation2 = 0.0f;&#9;// Quadratic

&#9;// Set Light
&#9;m_pD3DDevice->SetLight(0, &m_Light);&#9;// 0 is the index for this light
&#9;// Enable Light
&#9;m_pD3DDevice->LightEnable(0, true);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;//// Material (How light is reflected off of an object)
&#9;//////////////////////////////////////////////////////////////////////////
&#9;ZeroMemory(&m_Material[0], sizeof(m_Material));

&#9;m_Material[0].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);&#9;&#9;// Ambient color reflected
&#9;m_Material[0].Diffuse = D3DXCOLOR(1.0f, 0.3f, 0.3f, 1.0f);&#9;&#9;// Diffuse color reflected
&#9;m_Material[0].Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);&#9;&#9;// Emissive color reflected
&#9;m_Material[0].Specular = D3DXCOLOR(0.8f, 0.8f, 0.8f, 1.0f);&#9;&#9;// Specular
&#9;m_Material[0].Power = 30.0f;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Specular highlight intensity

&#9;ZeroMemory(&m_Material[1], sizeof(m_Material[1]));

&#9;m_Material[1].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);&#9;&#9;// Ambient color reflected
&#9;m_Material[1].Diffuse = D3DXCOLOR(0.3f, 0.3f, 1.0f, 1.0f);&#9;&#9;// Diffuse color reflected
&#9;m_Material[1].Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);&#9;&#9;// Emissive color reflected
&#9;m_Material[1].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);&#9;&#9;// Specular
&#9;m_Material[1].Power = 30.0f;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Specular highlight intensity

&#9;
&#9;ZeroMemory(&m_Material[2], sizeof(m_Material[2]));

&#9;m_Material[2].Ambient = D3DXCOLOR(0.2f, 0.2f, 0.2f, 1.0f);&#9;&#9;// Ambient color reflected
&#9;m_Material[2].Diffuse = D3DXCOLOR(0.3f, 1.0f, 0.3f, 1.0f);&#9;&#9;// Diffuse color reflected
&#9;m_Material[2].Emissive = D3DXCOLOR(0.0f, 0.0f, 0.0f, 1.0f);&#9;&#9;// Emissive color reflected
&#9;m_Material[2].Specular = D3DXCOLOR(1.0f, 1.0f, 1.0f, 1.0f);&#9;&#9;// Specular
&#9;m_Material[2].Power = 30.0f;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;&#9;// Specular highlight intensity

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Texture
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Load Texture
&#9;D3DXCreateTextureFromFile(m_pD3DDevice, L"ground2.bmp", &m_pTexture[0]);
&#9;// Set Sampler States
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

&#9;D3DXCreateTextureFromFile(m_pD3DDevice, L"seafloor.bmp", &m_pTexture[1]);
&#9;// Set Sampler States
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

&#9;D3DXCreateTextureFromFile(m_pD3DDevice, L"floor.bmp", &m_pTexture[2]);
&#9;// Set Sampler States
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
&#9;m_pD3DDevice->SetSamplerState(0, D3DSAMP_MIPFILTER, D3DTEXF_LINEAR);

&#9;
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Create a Font Object
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Load a font for private use for this process
&#9;AddFontResourceEx(L"Delicious-Roman.otf", FR_PRIVATE, 0);

&#9;// Load D3DXFont, each font style you want to support will need an ID3DXFont
&#9;D3DXCreateFont(m_pD3DDevice, 30, 0, FW_BOLD, 0, false, DEFAULT_CHARSET, 
&#9;&#9;OUT_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, TEXT("Delicious-Roman"), &m_pD3DFont);

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Initialize DirectInput
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Create the DI Object
&#9;DirectInput8Create(hInst, DIRECTINPUT_VERSION, IID_IDirectInput8, (void**)&m_pDIObject, NULL);

&#9;// Initialize Keyboard
&#9;m_pDIObject->CreateDevice(GUID_SysKeyboard, &m_pDIKeyboard, NULL);

&#9;// Initialize Mouse
&#9;m_pDIObject->CreateDevice(GUID_SysMouse, &m_pDIMouse, NULL);

&#9;// Set up Keyboard
&#9;m_pDIKeyboard->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
&#9;m_pDIKeyboard->SetDataFormat(&c_dfDIKeyboard);

&#9;// Set up Mouse (c_dfDIMouse2 = 8 button mouse)
&#9;m_pDIMouse->SetCooperativeLevel(hWnd, DISCL_FOREGROUND | DISCL_NONEXCLUSIVE);
&#9;m_pDIMouse->SetDataFormat(&c_dfDIMouse2);


}

void CDirectXFramework::Update(float dt)
{
&#9;////////////////////////////////////////////////////////////////////////
&#9;// Get and Acquire Keyboard Input
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// buffer - Stores our keyboard device state
&#9;char buffer[256];
&#9;ZeroMemory(buffer, sizeof(buffer));

&#9;// Get the input device state
&#9;HRESULT hr;
&#9;hr = m_pDIKeyboard->GetDeviceState( sizeof(buffer), (LPVOID)&buffer );

&#9;if(FAILED(hr))
&#9;{
&#9;&#9;hr = m_pDIKeyboard->Acquire();

&#9;&#9;// Device has probably been lost if failed, if so keep trying to get it until it’s found.
&#9;&#9;while( hr == DIERR_INPUTLOST)
&#9;&#9;{
&#9;&#9;&#9;hr = m_pDIKeyboard->Acquire();
&#9;&#9;}

&#9;&#9;// If we failed for some other reason
&#9;&#9;if(FAILED(hr))
&#9;&#9;&#9;return;

&#9;&#9;// Read the device state again
&#9;&#9;m_pDIKeyboard->GetDeviceState(sizeof(buffer), buffer);
&#9;}


&#9;

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Get and Acquire Mouse Input
&#9;//////////////////////////////////////////////////////////////////////////
&#9;// Stores our mouse state for an 8 button mouse.
&#9;DIMOUSESTATE2 mouseState;
&#9;ZeroMemory(&mouseState, sizeof(mouseState));

&#9;// Get the input device state
&#9;hr = m_pDIMouse->GetDeviceState( sizeof(DIMOUSESTATE2), &mouseState );
&#9;if(FAILED(hr))
&#9;{
&#9;&#9;hr = m_pDIMouse->Acquire();

&#9;&#9;// Device has probably been lost if failed, if so keep trying to get it until it’s found.
&#9;&#9;while( hr == DIERR_INPUTLOST)
&#9;&#9;{
&#9;&#9;&#9;hr = m_pDIMouse->Acquire();
&#9;&#9;}

&#9;&#9;// If we failed for some other reason
&#9;&#9;if(FAILED(hr))
&#9;&#9;&#9;return;
&#9;&#9;// Read the device state again
&#9;&#9;m_pDIMouse->GetDeviceState(sizeof(DIMOUSESTATE2), &mouseState);
&#9;}


&#9;//////////////////////////////////////////////////////////////////////////
&#9;//&#9;Keyboard Code Examples: [DIK (DirectInput Key) codes we translate]
&#9;//&#9;DIK_0 – DIK_9
&#9;//&#9;DIK_NUMPAD0 – DIK_NUMPAD9
&#9;//&#9;DIK_A – DIK_Z
&#9;//&#9;DIK_F1 – DIK_F12
&#9;//&#9;DIK_UP, DIK_DOWN, DIK_LEFT, DIK_RIGHT&#9;// Arrow Keys
&#9;//&#9;DIK_SPACE, DIK_TAB, DIK_CAPITAL, DIK_LCONTROL (Left Ctrl Key), 
&#9;//  DIK_RCONTROL (Right Ctrl Key), DIK_RETURN, DIK_LMENU (Left Alt Key), 
&#9;//  DIK_LWIN (Left Windows Key), DIK_LSHIFT (Left Shift Key), etc.
&#9;//&#9;Complete list under Keyboard Device in the documentation.
&#9;//////////////////////////////////////////////////////////////////////////

&#9;//////////////////////////////////////////////////////////////////////////
&#9;//&#9;Mouse variables:  [MouseState2 structure supports 8 button mice]
&#9;//&#9;lX&#9;&#9;&#9;&#9;-&#9;X-axis mouse relative coordinates
&#9;//&#9;lY&#9;&#9;&#9;&#9;-&#9;Y-axis mouse relative coordinates
&#9;//&#9;lZ&#9;&#9;&#9;&#9;-&#9;Mouse wheel relative coordinates
&#9;//&#9;rgbButtons[8]&#9;-&#9;Array of 8 mouse buttons
&#9;//
&#9;//&#9;Usually mouse hardware maps the button layout in a standard way for 
&#9;//&#9;the first 4 buttons, after that it depends on the mouse hardware layout
&#9;//&#9;rgbButtons[0]&#9;-&#9;Left Mouse Button
&#9;//&#9;rgbButtons[1]&#9;-&#9;Right Mouse Button
&#9;//&#9;rgbButtons[2]&#9;-&#9;Middle Mouse Button (click scroll wheel)
&#9;//&#9;rgbButtons[3]&#9;-&#9;Side Mouse Button 1
&#9;//&#9;rgbButtons[4]&#9;-&#9;Side Mouse Button 2
&#9;//&#9;rgbButtons[5]&#9;-&#9;Side Mouse Button 3
&#9;//&#9;rgbButtons[6]&#9;-&#9;Side Mouse Button 4
&#9;//&#9;rgbButtons[7]&#9;-&#9;Side Mouse Button 5
&#9;//////////////////////////////////////////////////////////////////////////

&#9;//////////////////////////////////////////////////////////////////////////
&#9;//&#9;Act on Input
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// If either CTRL key is held on the keyboard, activate transformation
&#9;// input gathering for the pyramid.

&#9;// Keyboard

&#9;if(buffer[DIK_LCONTROL] & 0x80 || buffer[DIK_RCONTROL] &0x80);
&#9;
&#9;&#9;
&#9;&#9;// Mouse

&#9;&#9;// Left Mouse Button - Translation
&#9;&#9;if(mouseState.rgbButtons[0] & 0x80)
&#9;&#9;{
&#9;&#9;&#9;m_pyramidTranslation.x += mouseState.lX * 0.01f; // X Axis
&#9;&#9;&#9;m_pyramidTranslation.y -= mouseState.lY * 0.01f; // Y Axis
&#9;&#9;&#9;m_pyramidTranslation.z += mouseState.lZ * 0.01f; // Mouse Wheel

&#9;&#9;}

&#9;&#9;// Right Mouse Button - Rotation
&#9;&#9;if(mouseState.rgbButtons[1] & 0x80)
&#9;&#9;{
&#9;&#9;&#9;m_pyramidRotation.y -= mouseState.lX * 0.01f; // X Axis
&#9;&#9;&#9;m_pyramidRotation.x -= mouseState.lY * 0.01f; // Y Axis
&#9;&#9;&#9;m_pyramidRotation.z += mouseState.lZ * 0.1f; // Mouse Wheel
&#9;&#9;}

&#9;&#9;// Middle Mouse Button - Scaling
&#9;&#9;if(mouseState.rgbButtons[2] & 0x80)
&#9;&#9;{
&#9;&#9;&#9;m_pyramidScaling += mouseState.lX * 0.01f; // X Axis
&#9;&#9;&#9;m_pyramidScaling += mouseState.lY * 0.01f; // Y Axis
&#9;&#9;&#9;m_pD3DDevice->SetRenderState(D3DRS_NORMALIZENORMALS, true);
&#9;&#9;}
}



&#9;

void CDirectXFramework::Render(float dt)
{
&#9;// If the device was not created successfully, return
&#9;if(!m_pD3DDevice)
&#9;&#9;return;

&#9;//////////////////////////////////////////////////////////////////////////
&#9;// All draw calls between swap chain's functions, and pre-render and post- 
&#9;// render functions (Clear and Present, BeginScene and EndScene)
&#9;//////////////////////////////////////////////////////////////////////////

&#9;// Clear the back buffer, call BeginScene()
&#9;if(SUCCEEDED(m_pD3DDevice->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DXCOLOR(0.0f, 0.4f, 0.8f, 1.0f), 1.0f, 0)))
&#9;{
&#9;&#9;if(SUCCEEDED(m_pD3DDevice->BeginScene()))
&#9;&#9;{
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Draw 3D Objects
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;UINT pass =0;
&#9;&#9;&#9;m_pEffect->SetTechnique(m_hTech);
&#9;&#9;&#9;m_pEffect->Begin(&pass, 0);

&#9;&#9;&#9;//// Set global shader parameters
&#9;&#9;&#9;m_pEffect->SetFloatArray("eyePos", (float*)m_eyePos, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("lightPos", (float*)&m_Light.Position, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("ambientLight", (float*)&m_Light.Ambient, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("specularLight", (float*)&m_Light.Specular, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("diffuseLight", (float*)&m_Light.Diffuse, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("lightAttenuation", (float*)&D3DXVECTOR3(m_Light.Attenuation0,m_Light.Attenuation1, m_Light.Attenuation2), 3);
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Matrix Transformations to control each objects position, scale, and 
&#9;&#9;&#9;// rotation.  Set these matrices for each object you want to render.
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;D3DXMATRIX transMat, rotMat, scaleMat, worldMat;
&#9;&#9;&#9;D3DXMatrixIdentity(&transMat);
&#9;&#9;&#9;D3DXMatrixIdentity(&scaleMat);
&#9;&#9;&#9;D3DXMatrixIdentity(&rotMat);
&#9;&#9;&#9;D3DXMatrixIdentity(&worldMat);

&#9;&#9;&#9;m_pD3DDevice->SetStreamSource(0, m_pD3DVertexBuffer, 0, sizeof(Vertex));
&#9;&#9;&#9;m_pD3DDevice->SetIndices(m_pD3DIndexBuffer);
&#9;&#9;&#9;m_pD3DDevice->SetVertexDeclaration(m_pD3DVertexDecl);

&#9;&#9;&#9;////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;//Cube 1
&#9;&#9;&#9;////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Calculate Matrix Transform
&#9;&#9;&#9;D3DXMatrixScaling(&scaleMat, 1.0f, 1.0f, 1.0f);&#9;&#9;&#9;// Scaling
&#9;&#9;&#9;D3DXMatrixRotationYawPitchRoll(&rotMat, timeGetTime() * 0.001f, 0.0f, 0.0f); // Rotation on Yaw, Pitch, and Roll
&#9;&#9;&#9;D3DXMatrixTranslation(&transMat, -4.0f, 0.0f, 0.0f);&#9;&#9;// Translation
&#9;&#9;&#9;D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);&#9;&#9;// Multiply scale and rotation, store in scale
&#9;&#9;&#9;D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);&#9;// Multiply scale and translation, store in world


&#9;&#9;&#9;for(int i=0; i < pass; i++)
&#9;&#9;&#9;{
&#9;&#9;&#9;&#9;// Begin the pass
&#9;&#9;&#9;&#9;m_pEffect->BeginPass(i);
&#9;&#9;&#9;&#9;m_pEffect->SetMatrix("worldViewProjMat", &(worldMat * m_viewMat * m_projMat));
&#9;&#9;&#9;&#9;D3DXMatrixInverse(&WITMat,0,&worldMat);
&#9;&#9;&#9;&#9;D3DXMatrixTranspose(&WITMat,&WITMat);
&#9;&#9;&#9;&#9;m_pEffect->SetMatrix("worldInverseTransposeMat",&(WITMat));
&#9;&#9;&#9;&#9;m_pEffect->SetMatrix("worldMat", &worldMat);
&#9;&#9;&#9;&#9;m_pEffect->SetFloatArray("ambientMaterial",(float*)&m_Material[2].Ambient, 3);
&#9;&#9;&#9;&#9;m_pEffect->SetFloatArray("diffuseMaterial",(float*)&m_Material[2].Diffuse, 3);
&#9;&#9;&#9;&#9;m_pEffect->SetFloatArray("specularMaterial",(float*)&m_Material[2].Specular, 3);
&#9;&#9;&#9;&#9;m_pEffect->SetFloat("specularPower",m_Material[2].Power);
&#9;&#9;&#9;&#9;m_pEffect->SetTexture("tex",m_pTexture);




&#9;&#9;&#9;&#9;m_pEffect->CommitChanges();

&#9;&#9;&#9;&#9;m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4 * 6, 0, 12);

&#9;&#9;&#9;&#9;// End the pass
&#9;&#9;&#9;&#9;m_pEffect->EndPass();
&#9;&#9;&#9;}
&#9;&#9;&#9;m_pEffect->End();    // end the effect

&#9;&#9;&#9;//// Set global shader parameters
&#9;&#9;&#9;m_pEffect->SetFloatArray("eyePos", (float*)m_eyePos, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("lightPos", (float*)&m_Light.Position, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("ambientLight", (float*)&m_Light.Ambient, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("specularLight", (float*)&m_Light.Specular, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("diffuseLight", (float*)&m_Light.Diffuse, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("lightAttenuation", (float*)&D3DXVECTOR3(m_Light.Attenuation0,m_Light.Attenuation1, m_Light.Attenuation2), 3);

&#9;&#9;&#9;/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Cube 2
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////

&#9;&#9;&#9;D3DXMatrixScaling(&scaleMat, 1.0f, 1.0f, 1.0f);&#9;&#9;&#9;// Scaling
&#9;&#9;&#9;D3DXMatrixRotationYawPitchRoll(&rotMat, timeGetTime() * -0.001f, 0.0f, 0.0f); // Rotation on Yaw, Pitch, and Roll
&#9;&#9;&#9;D3DXMatrixTranslation(&transMat, 4.0f, 0.0f, 0.0f);&#9;&#9;// Translation
&#9;&#9;&#9;D3DXMatrixMultiply(&scaleMat, &scaleMat, &rotMat);&#9;&#9;// Multiply scale and rotation, store in scale
&#9;&#9;&#9;D3DXMatrixMultiply(&worldMat, &scaleMat, &transMat);&#9;// Multiply scale and translation, store in world


&#9;&#9;&#9;m_pEffect->SetMatrix("worldViewProjMat", &(worldMat * m_viewMat * m_projMat));
&#9;&#9;&#9;D3DXMatrixInverse(&WITMat,0,&worldMat);
&#9;&#9;&#9;D3DXMatrixTranspose(&WITMat,&WITMat);
&#9;&#9;&#9;m_pEffect->SetMatrix("worldInverseTransposeMat",&(WITMat));
&#9;&#9;&#9;m_pEffect->SetMatrix("worldMat", &worldMat);
&#9;&#9;&#9;m_pEffect->SetFloatArray("ambientMaterial",(float*)&m_Material[1].Ambient, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("diffuseMaterial",(float*)&m_Material[1].Diffuse, 3);
&#9;&#9;&#9;m_pEffect->SetFloatArray("specularMaterial",(float*)&m_Material[1].Specular, 3);
&#9;&#9;&#9;m_pEffect->SetFloat("specularPower",m_Material[1].Power);
&#9;&#9;&#9;m_pEffect->SetTexture("tex",m_pTexture);

&#9;&#9;&#9;for(int i=0; i < pass; i++)
&#9;&#9;&#9;{&#9;
&#9;&#9;&#9;&#9;// Begin the pass
&#9;&#9;&#9;&#9;m_pEffect->BeginPass(i);

&#9;&#9;&#9;&#9;m_pEffect->CommitChanges();
&#9;&#9;&#9;&#9;// Draw cube
&#9;&#9;&#9;&#9;m_pD3DDevice->DrawIndexedPrimitive(D3DPT_TRIANGLELIST, 0, 0, 4 * 6, 0, 12);;

&#9;&#9;&#9;&#9;m_pEffect->EndPass();
&#9;&#9;&#9;}// Loop Ends
&#9;&#9;&#9;m_pEffect->End();    // end the effect
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Pyramid
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Draw 2D sprites
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////

&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Draw Text
&#9;&#9;&#9;//////////////////////////////////////////////////////////////////////////
&#9;&#9;&#9;// Calculate RECT structure for text drawing placement, using whole screen
&#9;&#9;&#9;RECT rect;
&#9;&#9;&#9;GetWindowRect(m_hWnd, &rect);
&#9;&#9;&#9;rect.right = rect.right - rect.left;
&#9;&#9;&#9;rect.bottom = rect.bottom - rect.top;
&#9;&#9;&#9;rect.left = 0;
&#9;&#9;&#9;rect.top = 0;

&#9;&#9;&#9;// Draw Text, using DT_TOP, DT_RIGHT for placement in the top right of the
&#9;&#9;&#9;// screen.  DT_NOCLIP can improve speed of text rendering, but allows text
&#9;&#9;&#9;// to be drawn outside of the rect specified to draw text in.
&#9;&#9;&#9;m_pD3DFont->DrawText(0, L"<Orlando Camacho>", -1, &rect, DT_TOP | DT_RIGHT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

&#9;&#9;&#9;// Draw Controls
&#9;&#9;&#9;m_pD3DFont->DrawText(0, L"Pyramid Controls:\nHold either CTRL key then:\nTranslation - Left Mouse Button\nRotation - Right Mouse Button\nScaling - Middle Mouse Button", -1, &rect, DT_BOTTOM | DT_LEFT | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

&#9;&#9;&#9;// Draw FPS & ms
&#9;&#9;&#9;wchar_t buffer[64];
&#9;&#9;&#9;swprintf_s(buffer, 64, L"FPS: %d\nMs: %0.2f", m_FPS, m_elapsedTime);
&#9;&#9;&#9;m_pD3DFont->DrawText(0, buffer, -1, &screenRect, DT_TOP | DT_NOCLIP, D3DCOLOR_ARGB(255, 255, 255, 255));

&#9;&#9;&#9;// EndScene, and Present the back buffer to the display buffer
&#9;&#9;&#9;m_pD3DDevice->EndScene();
&#9;&#9;}
&#9;&#9;m_pD3DDevice->Present(0, 0, 0, 0);
&#9;}

&#9;// Calculate Frames per Second
&#9;m_currTime = (float)timeGetTime();
&#9;static int fpsCounter = 0;
&#9;if(m_currTime - m_prevTime >= 1000.0f)
&#9;{
&#9;&#9;m_prevTime = m_currTime;
&#9;&#9;m_FPS = fpsCounter;
&#9;&#9;fpsCounter = 0;&#9;&#9;
&#9;}
&#9;else
&#9;{
&#9;&#9;++fpsCounter;
&#9;}
}

void CDirectXFramework::Shutdown()
{
&#9;// Release COM objects in the opposite order they were created in
&#9;// close and release the effect

&#9;SAFE_RELEASE(m_pDIMouse);
&#9;SAFE_RELEASE(m_pDIKeyboard);
&#9;SAFE_RELEASE(m_pDIObject);


&#9;SAFE_RELEASE(m_pD3DFont);
&#9;RemoveFontResourceEx(L"Delicious-Roman.otf", FR_PRIVATE, 0);
&#9;SAFE_RELEASE(m_pTexture);
&#9;SAFE_RELEASE(m_pEffect);
&#9;SAFE_RELEASE(m_pD3DVertexBufferPyramid);
&#9;SAFE_RELEASE(m_pD3DIndexBufferPyramid);
&#9;SAFE_RELEASE(m_pD3DIndexBuffer);
&#9;SAFE_RELEASE(m_pD3DVertexBuffer);
&#9;SAFE_RELEASE(m_pD3DVertexDecl);
&#9;SAFE_RELEASE(m_pD3DDevice);
&#9;SAFE_RELEASE(m_pD3DObject);
}

I received these Errors can anyone assist me please:
c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.h(162): error C2040: 'CDirectXFramework::m_Material' : 'D3DMATERIAL9 [2]' differs in levels of indirection from 'D3DMATERIAL9'
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(33): error C2065: 'm_pyramidScaling' : undeclared identifier
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(400): error C2664: 'IDirect3DDevice9::CreateIndexBuffer' : cannot convert parameter 5 from 'IDirect3DVertexBuffer9 **' to 'IDirect3DIndexBuffer9 **'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(526): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(528): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(528): error C2228: left of '.Ambient' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(529): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(529): error C2228: left of '.Diffuse' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(530): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(530): error C2228: left of '.Emissive' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(531): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(531): error C2228: left of '.Specular' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(532): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(532): error C2228: left of '.Power' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(534): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(534): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(536): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(536): error C2228: left of '.Ambient' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(537): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(537): error C2228: left of '.Diffuse' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(538): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(538): error C2228: left of '.Emissive' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(539): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(539): error C2228: left of '.Specular' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(540): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(540): error C2228: left of '.Power' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(543): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(543): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(545): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(545): error C2228: left of '.Ambient' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(546): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(546): error C2228: left of '.Diffuse' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(547): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(547): error C2228: left of '.Emissive' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(548): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(548): error C2228: left of '.Specular' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(549): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(549): error C2228: left of '.Power' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(555): error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 3 from 'IDirect3DTexture9 *' to 'LPDIRECT3DTEXTURE9 *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(561): error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 3 from 'IDirect3DTexture9 *' to 'LPDIRECT3DTEXTURE9 *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(567): error C2664: 'D3DXCreateTextureFromFileW' : cannot convert parameter 3 from 'IDirect3DTexture9 *' to 'LPDIRECT3DTEXTURE9 *'
1>          Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(718): warning C4390: ';' : empty controlled statement found; is this the intent?
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(737): error C2065: 'm_pyramidScaling' : undeclared identifier
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(738): error C2065: 'm_pyramidScaling' : undeclared identifier
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(802): warning C4018: '<' : signed/unsigned mismatch
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(811): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(811): error C2228: left of '.Ambient' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(812): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(812): error C2228: left of '.Diffuse' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(813): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(813): error C2228: left of '.Specular' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(814): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(814): error C2228: left of '.Power' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(854): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(854): error C2228: left of '.Ambient' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(855): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(855): error C2228: left of '.Diffuse' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(856): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(856): error C2228: left of '.Specular' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(857): error C2088: '[' : illegal for struct
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(857): error C2228: left of '.Power' must have class/struct/union
1>c:\users\generalcamacho\documents\visual studio 2010\projects\gspweek4assignment\gspweek4assigment\directxframework.cpp(860): warning C4018: '<' : signed/unsigned mismatch

Open in new window

Avatar of Member_2_5069294
Member_2_5069294

This isn't really a Game Programming problem, this is language syntax. Specifically you're mixing structs, classes and arrays. I suggest you add this to one of the more active programming topics, I have asked a moderator to help with this.
ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial