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: }Material;
0027:
0028: typedef struct{
0029: int type;
0030:
0031: Material material;
0032:
0033: struct{
0034:
0035: float x0[3];
0036: float x1[3];
0037: float x2[3];
0038: } triangle;
0039: struct {
0040:
0041: float center[3];
0042: float radius;
0043: } sphere;
0044:
0045: }OBJ_DATA;
0046:
0047:
0048:
0049:
0050:
0051:
0052: class CPrimitive
0053: {
0054: public:
0055: enum {
0056: INFINTY_DIST = 10000,
0057: };
0058: int m_type;
0059: Material m_material;
0060:
0061: void Init(OBJ_DATA *pData);
0062: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v){return INFINTY_DIST;}
0063: D3DXVECTOR3 *GetColor(D3DXVECTOR3 *dest, float LN, float HN );
0064: };
0065:
0066:
0067:
0068: class CSphere : public CPrimitive
0069: {
0070: private:
0071: D3DXVECTOR4 center;
0072: float radius_sq;
0073:
0074: public:
0075: CSphere();
0076:
0077: void Init(OBJ_DATA *pData);
0078: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0079: };
0080:
0081:
0082:
0083:
0084: class CTriangle : public CPrimitive
0085: {
0086: private:
0087: D3DXVECTOR4 pos[3];
0088: D3DXVECTOR4 t0; FLOAT l0;
0089: D3DXVECTOR4 t1; FLOAT l1;
0090: D3DXVECTOR4 normal;
0091:
0092: public:
0093: CTriangle();
0094:
0095: void Init(OBJ_DATA *pData);
0096: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0097: };
0098:
0099:
0100:
0101:
0102:
0103: class CMesh
0104: {
0105: public:
0106: CMesh();
0107: ~CMesh();
0108: CPrimitive **m_ppPrim;
0109: int m_num;
0110:
0111: void Init(OBJ_DATA *pData, int num);
0112: void Delete();
0113: float IsAcross(float dist, D3DXVECTOR4 *n, D3DXVECTOR4 *p, CPrimitive **dest, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0114: bool IsAcross(float dist, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v);
0115: };
0116:
0117:
0118: };
0119:
0120: #endif
0121: