|
/* file cMunsell.h
*
* This is the header file for my cMunsell class which uses Direct3D 8
* to draw a three-dimensional model of the Munsell color solid.
*
* Because this code employs Direct3D, you must link with D3D8.LIB,
* D3DX8.LIB, and DXERR8.LIB.
*
* You can check out my other software at:
* www.computersciencelab.com
*
* John Kopplin 1/03
*/
#ifndef _CMUNSELL_H
#define _CMUNSELL_H
///////////////////////////////////////////////////////////////////////////////
// Includes
//
///////////////////////////////////////////////////////////////////////////////
#include <d3d8.h>
#include <d3dx8.h>
#include <Dxerr8.h> // needed for DXGetErrorString8() and DXTrace()
#include <d3dxerr.h>
#include <stdio.h>
#include "d3dfont.h" // needed for Microsoft's CD3DFont class
///////////////////////////////////////////////////////////////////////////////
// Defines and Typedefs
//
///////////////////////////////////////////////////////////////////////////////
#define NSLICES 20
#define PI 3.1415926535897932384626433832795
#define TWOPI 6.28318530717958647692528676655901
#define HALFPI 1.57079632679489661923132169163975
///////////////////////////////////////////////////////////////////////////////
// cMunsell class
//
///////////////////////////////////////////////////////////////////////////////
class cMunsell
{
public:
// Constructors
cMunsell();
virtual ~cMunsell();
// Interface
HRESULT CreateGeometry();
HRESULT ReleaseGeometry();
HRESULT SetRenderStates();
HRESULT Render();
void ToggleTransparency();
inline void ToggleBackfaceCulling()
{
if ( m_bBackfaceCulling )
m_bBackfaceCulling = false;
else
m_bBackfaceCulling = true;
}
inline void TogglePaintersAlgorithm()
{
if ( m_bPaintersAlgorithm )
m_bPaintersAlgorithm = false;
else
m_bPaintersAlgorithm = true;
}
inline float GetRotation()
{
return m_fRotation;
}
inline void SetRotation( float fRotation )
{
m_fRotation = fRotation;
}
inline float GetElevation()
{
return m_fElevation;
}
inline void SetElevation( float fElevation )
{
m_fElevation = fElevation;
}
inline float GetViewRadius()
{
return m_fViewRadius;
}
inline void SetViewRadius( float fViewRadius )
{
m_fViewRadius = fViewRadius;
}
protected:
// Data
// Direct3D employs the flexible vertex format (FVF) which means
// that we get to define a struct holding the information relevant
// to our vertices. Older version of Direct3D provided "pre-canned"
// vertex types such as D3DVERTEX but these are no longer supported.
// ****** WARNING ******
// Regardless of what vertex data you choose to include,
// you MUST order the vertex data as indicated below !!
struct MYVERTEX
{
FLOAT x, y, z; // transformed position, used with D3DFVF_XYZ
// FLOAT rhw; // reciprocal of homogeneous w, used with
// D3DFVF_XYZRHW
// blending weight data // used with D3DFVF_XYZB1 through D3DFVF_XYZB5
// FLOAT nx, ny, nz; // normal vector components, used with D3DFVF_NORMAL
// vertex point size // used with D3DFVF_PSIZE
// D3DCOLOR diffuse; // diffuse vertex color, used with D3DFVF_DIFFUSE
// D3DCOLOR specular; // specular vertex color, used with D3DFVF_SPECULAR
FLOAT tu, tv; // 1 set of texture coordinates, used with
// D3DFVF_TEX1
};
// U and V are the column and row coordinates of each texel (texture element).
// In computer graphics, a "texture" is a bitmap of pixel colors that
// give an object the appearance of texture. Primitives that have no textures
// are rendered with the color specified by their material, or with the colors
// specified for the vertices, if any. Texture coordinates are in the range
// of 0.0 to 1.0 inclusive.
DWORD m_FVF;
// We specify all the vertices of our model in a huge array. Triangles
// are defined as a triple of indices into this array. We pass to
// DrawIndexedPrimitive() another array holding indices into the
// vertex array. The surface normal vector's direction is determined by
// the order in which the vertices are defined (and by whether the
// coordinate system is right- or left-handed; Direct3D employs a
// left-handed coordinate system). The face normal points away from
// the front side of the face. A front face is one in which vertices
// are defined in clockwise order. By default, Direct3D, culls the
// back faces.
D3DCOLOR m_d3dcrBackground;
// D3DCOLOR_XRGB(), D3DCOLOR_ARGB(), and D3DCOLOR_RGBA() are macros that
// return a D3DCOLOR which is just a typedef for a DWORD.
UINT m_nVertices;
UINT m_nIndices;
PDIRECT3DVERTEXBUFFER8 m_pVertexBuffer;
PDIRECT3DINDEXBUFFER8 m_pIndexBuffer;
IDirect3DTexture8 * m_pTextures[NSLICES];
D3DXVECTOR3 m_vObjectCenter; // center of bounding sphere of object
float m_fObjectRadius; // radius of bounding sphere of object
float m_fViewRadius;
float m_fRotation; // longitude
float m_fElevation; // latitude
D3DXVECTOR3 m_vEyePt; // describes the camera
D3DXVECTOR3 m_vLookatPt; // " " "
D3DXVECTOR3 m_vUpVector; // " " "
// The only purpose of these last 3 Booleans is to allow
// this tutorial to do things wrong as well as right.
BOOL m_bTransparency;
BOOL m_bBackfaceCulling;
BOOL m_bPaintersAlgorithm;
};
#endif // _CMUNSELL_H
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.