0001:
0002: #include <d3d9.h>
0003: #include <d3dx9.h>
0004:
0005:
0006: #ifndef _PRIM_H_
0007: #define _PRIM_H_
0008:
0009: namespace Render {
0010:
0011:
0012:
0013:
0014: enum {
0015: OBJ_TYPE_SPHERE = 0,
0016: OBJ_TYPE_TRIANGLE,
0017: };
0018:
0019:
0020:
0021: typedef struct{
0022: float COLOR_AMB[4];
0023: float COLOR_DIF[4];
0024: float COLOR_SPE[4];
0025: float speq_power;
0026: float reflection;
0027: float refraction;
0028: float diffuse;
0029: }Material;
0030:
0031: typedef struct{
0032: int type;
0033:
0034: Material material;
0035:
0036: struct{
0037:
0038: float x0[3];
0039: float x1[3];
0040: float x2[3];
0041: } triangle;
0042: struct {
0043:
0044: float center[3];
0045: float radius;
0046: } sphere;
0047:
0048: }OBJ_DATA;
0049:
0050:
0051:
0052:
0053:
0054:
0055: class CPrimitive
0056: {
0057: public:
0058: enum {
0059: INFINTY_DIST = 10000,
0060: };
0061: int m_type;
0062: Material m_material;
0063:
0064: void Init(OBJ_DATA *pData);
0065: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v){return INFINTY_DIST;}
0066: D3DXVECTOR3 *GetColor(D3DXVECTOR3 *dest, float LN, float HN );
0067: };
0068:
0069:
0070:
0071: class CSphere : public CPrimitive
0072: {
0073: private:
0074: D3DXVECTOR4 center;
0075: float radius_sq;
0076:
0077: public:
0078: CSphere();
0079:
0080: void Init(OBJ_DATA *pData);
0081: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0082: };
0083:
0084:
0085:
0086:
0087: class CTriangle : public CPrimitive
0088: {
0089: private:
0090: D3DXVECTOR4 pos[3];
0091: D3DXVECTOR4 t0; FLOAT l0;
0092: D3DXVECTOR4 t1; FLOAT l1;
0093: D3DXVECTOR4 normal;
0094:
0095: public:
0096: CTriangle();
0097:
0098: void Init(OBJ_DATA *pData);
0099: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0100: };
0101:
0102:
0103:
0104:
0105:
0106: class CMesh
0107: {
0108: public:
0109: CMesh();
0110: ~CMesh();
0111: CPrimitive **m_ppPrim;
0112: int m_num;
0113:
0114: void Init(OBJ_DATA *pData, int num);
0115: void Delete();
0116: float IsAcross(float dist, D3DXVECTOR4 *n, D3DXVECTOR4 *p, CPrimitive **dest, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0117: bool IsAcross(float dist, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0118: };
0119:
0120:
0121: };
0122:
0123: #endif
0124: