Hey guys,
I thought I should spend a bit of extra time to make it easier for someone to port our 3d format's exporter. Heres the interface to our model loading subsystem...still working on the implementation...
#ifndef __RES_MDL_MODEL_H__#define __RES_MDL_MODEL_H__//----------------------------------------------------------------------------////res_mdl_model.h////Copyright © Rishi Ramraj, 2004// Model loading/displaying library//----------------------------------------------------------------------------//··········································································//// header :: Inclusions//··········································································//#include "res_img_image.h"//··········································································//// header :: Definitions//··········································································////··········································································//// header :: Structures//··········································································////··········································································//// header :: Class Defs//··········································································//// Class design philosophy// These classes are designed to operate in two modes; read mode and write mode.// To use write mode, use the init function to initalize the respective class// with the desired values. Behaviour is undefined if both modes are used together. // The read, write, or init functions should only be called once. Both read and // write functions append directly onto the file passed.class res_mdl_vertex{public: res_mdl_vertex(); ~res_mdl_vertex(); // sends the vector data to OpenGL void draw(void); // reads vector data from the FILE struct passed bool read(void * file); bool init(float v_x, float v_y, float v_z, float u, float v); // writes vector data to the FILE struct passed bool write(void * file);private: // vertex data float vertex[3]; // texture coordinates float tex_u; float tex_v;};class res_mdl_normal{public: res_mdl_normal(); ~res_mdl_normal(); // sends the normal data to OpenGL void draw(void); // reads normal data from the FILE struct passed bool read(void * file); bool init(float n_x, float n_y, float n_z); // writes normal data to the FILE struct passed bool write(void * file);private: // normal data float normal[3];};class res_mdl_triangle{public: res_mdl_triangle(); ~res_mdl_triangle(); // sends the triangle data to OpenGL void draw( res_mdl_vertex * vertices, res_mdl_normal * normals); // reads vector data from the FILE struct passed bool read(void * file); bool init(int v_1, int v_2, int v_3, int n_1, int n_2, int n_3); // writes vector data to the FILE struct passed bool write(void * file);private: // triangle data int vertex_indices[3]; int normal_indices[3];};class res_mdl_material{public: res_mdl_material(); ~res_mdl_material(); // sends the material data to OpenGL void draw(void); // reads material data from the FILE struct passed bool read(void * file); // Note that path is duplicated in memory bool init(float al_x, float al_y, float al_z, float dl_x, float dl_y, float dl_z, float sl_x, float sl_y, float sl_z, float el_x, float el_y, float el_z, const char * path); // writes material data to the FILE struct passed bool write(void * file);private: // material data float ambiant_light[4]; float diffuse_light[4]; float specular_light[4]; float emissive_light[4]; res_img_image texture; // path is only used for writing // path is stored to resolve an issue that arises with the write function. // The class is responsible for writing the relative path of the texture to // disk, but the path does not need to be stored when the class is used // under read mode circumstances. char * path;};class res_mdl_mesh{public: res_mdl_mesh(); ~res_mdl_mesh(); // sends the mesh data to OpenGL void draw(void); // reads mesh data from the FILE struct passed bool read(void * file); // Note that the pointers are not duplicated in memory. // They should be allocated using new. The mesh class // will delete the data after it goes out of scope. bool init(int mi, int n_verts, res_mdl_vertex * verts, int n_norms, res_mdl_normal * norms, int n_faces, res_mdl_triangle * faces); // writes material data to the FILE struct passed bool write(void * file);private: // mesh data int material_index; int num_vertices; res_mdl_vertex * vertices; int num_normals; res_mdl_normal * normals; int num_triangles; res_mdl_triangle * triangles;};class res_mdl_model{public: res_mdl_model(); ~res_mdl_model(); // sends the mesh data to OpenGL as a display list void draw(void); // reads mesh data from the FILE struct passed. Once the model // has been read, it is sent to OpenGL as a display list. bool read(void * file); // Note that the pointers are not duplicated in memory. // They should be allocated using new. The model class // will delete the data after it goes out of scope. bool init(int n_mats , res_mdl_material * mats, int n_meshes, res_mdl_mesh * meshes); // writes material data to the FILE struct passed bool write(void * file);private: // model data int num_materials; res_mdl_material * materials; int num_meshes; res_mdl_mesh * meshes; unsigned int display_list;};//··········································································//// header :: Function Defs//··········································································////----------------------------------------------------------------------------//res_mdl_model.h//Copyright © Rishi Ramraj, 2004//----------------------------------------------------------------------------#endif //__RES_MDL_MODEL_H__
I'm still working on tweaking it to make it a bit easier to use (scalable that is). I will probably end up changing the interface a bit before the subsystem is complete. Should be done by tomorrow.
Once the model loading subsystem is done, I'll take a bit of time to discuss how chess game logic/ai is programmed on a computer. This way we can hammer out a rough design for our implementation before we get there.
Till then,
- llvllatrix