#ifndef D3DUTILS_H
#define D3DUTILS_H
/*
**-----------------------------------------------------------------------------
** Name: D3DUtils.h
** Purpose: Various D3D utility functions
** Notes:
**
** Copyright (c) 1995 - 1997 by Microsoft, all rights reserved
**-----------------------------------------------------------------------------
*/
#define D3D_OVERLOADS
#include <d3d.h>
#include <d3dtypes.h>
extern const float pi;
/*
**-----------------------------------------------------------------------------
** Function Prototypes
**-----------------------------------------------------------------------------
*/
// generic simple matrix routines
extern D3DMATRIX ZeroMatrix(void);
extern D3DMATRIX IdentityMatrix(void);
extern D3DMATRIX ProjectionMatrix(const float near_plane, const float far_plane, const float fov);
extern D3DMATRIX ViewMatrix(const D3DVECTOR & from, const D3DVECTOR & at,
const D3DVECTOR & up, const float roll=0.0f);
extern D3DMATRIX RotateXMatrix(const float rads);
extern D3DMATRIX RotateYMatrix(const float rads);
extern D3DMATRIX RotateZMatrix(const float rads);
extern D3DMATRIX TranslateMatrix(const float dx, const float dy, const float dz);
extern D3DMATRIX TranslateMatrix(const D3DVECTOR & v);
extern D3DMATRIX ScaleMatrix(const float size);
extern D3DMATRIX ScaleMatrix(const float a, const float b, const float c);
extern D3DMATRIX ScaleMatrix(const D3DVECTOR & v);
extern D3DMATRIX MatrixMult(const D3DMATRIX & a, const D3DMATRIX & b);
extern D3DMATRIX MatrixInverse(const D3DMATRIX & m);
extern D3DMATRIX MatrixTranspose(const D3DMATRIX & m);
extern D3DVECTOR TransformVector(const D3DVECTOR & v, const D3DMATRIX & m);
extern D3DVECTOR TransformNormal(const D3DVECTOR & v, const D3DMATRIX & m);
// Other stuff
extern float rnd(void);
/*
**-----------------------------------------------------------------------------
** Classes
**-----------------------------------------------------------------------------
*/
/*
**-----------------------------------------------------------------------------
**Class:Light
**Purpose:
**-----------------------------------------------------------------------------
*/
class Light {
protected:
public:
D3DLIGHT2light;// structure defining the light
LPDIRECT3DLIGHTlpD3DLight;// object pointer for the light
intchanged;
public:
Light(LPDIRECT3D2 lpD3D);
~Light();
HRESULTAddToViewport(LPDIRECT3DVIEWPORT2 lpView);
HRESULTRemoveFromViewport(LPDIRECT3DVIEWPORT2 lpView);
HRESULTSet(void);
voidSetColor(const D3DVECTOR& color);
D3DVECTORGetColor(void) const;
voidSetPosition(const D3DVECTOR& position);
D3DVECTORGetPosition(void) const;
voidSetDirection(const D3DVECTOR& direction);
D3DVECTORGetDirection(void) const;
voidSetAttenuation(const D3DVECTOR& attenuation);
D3DVECTORGetAttenuation(void) const;
voidSetRange(const float range);
floatGetRange(void) const;
voidSetFalloff(const float falloff);
floatGetFalloff(void) const;
voidSetUmbra(const float falloff);
floatGetUmbra(void) const;
voidSetPenumbra(const float falloff);
floatGetPenumbra(void) const;
voidSetFlags(const DWORD flags);
DWORDGetFlags(void) const;
}; // End Light
/*
**-----------------------------------------------------------------------------
**Class:PointLight
**Purpose:
**-----------------------------------------------------------------------------
*/
class PointLight : public Light {
public:
PointLight(LPDIRECT3D2 lpD3D,
const D3DVECTOR & color,
const D3DVECTOR & position);
}; // End PointLight
/*
**-----------------------------------------------------------------------------
**Class:SpotLight
**Purpose:
**-----------------------------------------------------------------------------
*/
class SpotLight : public Light {
public:
SpotLight(LPDIRECT3D2 lpD3D,
const D3DVECTOR& color,
const D3DVECTOR& position,
const D3DVECTOR& direction,
const float umbra_angle,
const float penumbra_angle);
}; // End SpotLight
/*
**-----------------------------------------------------------------------------
**Class:DirectionalLight
**Purpose:
**-----------------------------------------------------------------------------
*/
class DirectionalLight : public Light {
public:
DirectionalLight(LPDIRECT3D2 lpD3D,
const D3DVECTOR& color, const D3DVECTOR& direction);
};
/*
**-----------------------------------------------------------------------------
**Class:ParallelPointLight
**Purpose:
**-----------------------------------------------------------------------------
*/
class ParallelPointLight : public Light {
public:
ParallelPointLight(LPDIRECT3D2 lpD3D, const D3DVECTOR& color, const D3DVECTOR& position);
}; // End ParallelPointLight
/*
**-----------------------------------------------------------------------------
**Class:Material
**Purpose:
**-----------------------------------------------------------------------------
*/
class Material
{
protected:
D3DMATERIALMat;
D3DMATERIALHANDLEhMat;
LPDIRECT3DMATERIAL2 lpMat;
intchanged;
public:
Material(LPDIRECT3D2 lpD3D, LPDIRECT3DDEVICE2 lpDev);
~Material();
HRESULTSetAsCurrent(LPDIRECT3DDEVICE2 lpDev);
HRESULTSetAsBackground(LPDIRECT3DVIEWPORT2 lpView);
HRESULTSet(void);
voidSetDiffuse(const D3DVECTOR& color);
D3DVECTORGetDiffuse(void) const;
voidSetAlpha(const float& alpha);
floatGetAlpha(void) const;
voidSetAmbient(const D3DVECTOR& color);
D3DVECTORGetAmbient(void) const;
voidSetEmissive(const D3DVECTOR& color);
D3DVECTORGetEmissive(void) const;
voidSetSpecular(const D3DVECTOR& color);
D3DVECTORGetSpecular(void) const;
voidSetPower(const D3DVALUE& power);
D3DVALUEGetPower(void) const;
voidSetRampSize(const DWORD& ramp);
DWORDGetRampSize(void) const;
voidSetTextureHandle(const D3DTEXTUREHANDLE& hTexture);
D3DTEXTUREHANDLEGetTextureHandle(void);
}; // End Material
//
// include the inline functions for the classes
//
#include "d3dutils.inl"
/*
**-----------------------------------------------------------------------------
**End of File
**-----------------------------------------------------------------------------
*/
#endif // D3DUTILS_H