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_DIF[4];
0023: float reflection;
0024: float refraction;
0025: float diffuse;
0026: float emmisive;
0027: }Material;
0028:
0029: typedef struct{
0030: int type;
0031:
0032: Material material;
0033:
0034: struct{
0035:
0036: float x0[3];
0037: float x1[3];
0038: float x2[3];
0039: } triangle;
0040: struct {
0041:
0042: float center[3];
0043: float radius;
0044: } sphere;
0045:
0046: }OBJ_DATA;
0047:
0048:
0049:
0050:
0051:
0052:
0053: class CPrimitive
0054: {
0055: public:
0056: enum {
0057: INFINTY_DIST = 100000,
0058: };
0059: int m_type;
0060: Material m_material;
0061:
0062: void Init(OBJ_DATA *pData);
0063: float IsAcross(D3DXVECTOR4 *n, D3DXVECTOR4 *p, const D3DXVECTOR4 *x, const D3DXVECTOR4 *v){return INFINTY_DIST;}
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: