I have some basic code written, I have the header wirtten and some of the cpp file, at the moment im looking for a website to actually explain how the C++ file to be written, there is enough information about the header file but none about coding/createing the cpp file. I have seen the other post on this forum about a MD3 loader but i have luck in making that one work,
Here is my header file
Code: Select all
#include <GL/glew.h>
#include <GL/gl.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vectormath/scalar/cpp/vectormath_aos.h>
#include "GameAsset.h"
using namespace std;
using namespace Vectormath::Aos;
#ifndef MD3ASSET_H_
#define MD3ASSET_H_
class Md3Asset : public GameAsset{
public:
Md3Asset();
Md3Asset(const string &filename);
virtual ~Md3Asset();
virtual void update();
private:
void import_md3_asset(const string &filename);
struct md3_header
{
int ident;
int version;
char name[64];
int flags;
int num_frames;
int num_tags;
int num_surfaces;
int num_skins;
int ofs_frames;
int ofs_tags;
int ofs_surfaces;
int ofs_eof;
struct md3_frame
{
Vector3 min_bounds;
Vector3 max_bounds;
Vector3 local_origin;
float radius;
char name[16];
};
struct md3_tag
{
char name[64];
Vector3 origin;
Vector3 axis[3];
};
struct md3_surface
{
int ident;
char name[64];
int flags;
int num_frames;
int num_shaders;
int num_verts;
int num_triangles;
int ofs_triangles;
int ofs_shaders;
int ofs_ST;
int ofs_xyzNormal;
int ofs_end;
struct md3_shader
{
char name[64];
int shader_index;
};
struct md3_triangle
{
int indexes[3];
};
struct md3_st
{
float st[3];
};
struct md3_vertex
{
short coord[3];
short normal;
};
};
};
//Not sure about this
typedef float vec3[3];
//Not sure about this
md3_header::md3_surface::md3_triangle * triangles;
md3_header::md3_surface * surfaces;
};
#endif /* MD3ASSET_H_ */
Code: Select all
#include "Md3Asset.h"
Md3Asset::Md3Asset(const string &filename) {
import_md3_asset(filename);
// make the objects to display
if(0 == make_resources()) {
cout << "Can't make the required OpenGL resources for Md3Asset." << endl;
// TODO: exit nicely here
}
}
Md3Asset::Md3Asset(){}
Md3Asset::~Md3Asset() {
// TODO: clean up
}
void Md3Asset::update() {
}
void Md3Asset::import_md3_asset(const string &filename) {
ifstream md3file;
md3file.open(filename.c_str(), ios::in|ios::binary);
// C stuff
md3_header * md3header = (struct md3_header *)
malloc(sizeof(struct md3_header));
md3file.read((char*) md3header, sizeof(struct md3_header));
if((md3header->ident != 860898377)||(md3header->version !=15))
{
cout << md3header->version << endl;
cout << md3header->ident << endl;
cerr<<"Bad Version or identifier"<<endl;
}
// Get the triange data
this->triangles = (md3_header::md3_surface::md3_triangle*)
calloc(this->surfaces->num_triangles, sizeof(struct md3_header::md3_surface));
cout<<triangles<<endl;
}
Cheers