Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualCanvas

Posted 26 April 2012 - 03:12 AM

Cheers Washu, I have a lesson soon so i wont be able to check your code until 1english time Posted Image, Sorry about the lack of knowledge, it does come in time tho Posted Image

Also here is my header and cpp file before i edit it with washu's code

Md3Asset.cpp
#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 Md2Asset." << endl;
   // TODO: exit nicely here
}
}
Md3Asset::~Md3Asset() {
  // TODO: clean up
}
void Md3Asset::update() {
}
void Md3Asset::import_md3_asset(const string &filename) {
/*ifstream md3file(filename, ios::in|ios::binary);
//md3file.open(filename.c_str(), ios::in|ios::binary|ios::ate|ios_base::binary);
// C stuff
md3_header * md3Header = (struct md3_header *)
  malloc(sizeof(struct md3_header));//Malloc seems to read the data correctly
  //new vector<int>(sizeof(struct md3_header));
// it involves evil casting.*/
//ifstream is input stream, ofstream is output stream
//fstream is input&output
fstream md3file;
//ios::in = open for input mode
//ios::binary = opens the file in binary mode
md3file.open(filename.c_str(), ios::in | ios::binary | ios::ate);
md3_header md3Header;
md3file.read(reinterpret_cast<char *>(&md3Header), sizeof(md3_header));
if((md3Header.ident != 860898377)||(md3Header.version !=15)
   ||((md3Header.fileID[0] != 'I')
   ||(md3Header.fileID[1] != 'D')
   ||(md3Header.fileID[2] != 'P')
   ||(md3Header.fileID[3] != '3')))
   {
  cout<<"Bad Version or identifier"<<endl;
   cout << md3Header.fileID[0] << md3Header.fileID[1] <<
	 md3Header.fileID[2] << md3Header.fileID[3] << endl;
   cout << md3Header.version << endl;
   cout << md3Header.ident << endl;
   }
md3file.close();
}

Md3Asset.h
#include <GL/glew.h>
#include <GL/gl.h>
#include <string>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <fstream>
#include <vector>
#include "GameAsset.h"
using namespace std;
#ifndef MD3ASSET_H_
#define MD3ASSET_H_
class Md3Asset : public GameAsset {
public:
Md3Asset(const string &filename);
virtual ~Md3Asset();
virtual void update();
private:
void import_md3_asset(const string &filename);
//May need this
typedef float vec3[3];
struct md3_header
{
  char fileID[4]; //Stores the file IDs
  int ident;  //Stores the identity
  int version; //Stores the version, Must be 15
  char name[64]; //Stores the name of the file
  int flags;  //Stores the flags
  int num_frames; //Stores number of frames
  int num_tags; //Stores number of tags
  int num_surfaces; //Stores number of surfaces
  int num_skins; //Stores number of skins
  int ofs_frames; //Stores offset number of frames
  int ofs_tags; //Stores offset number of tags
  int ofs_surfaces; //Stores offset number of surfaces
  int ofs_eof; //Stores offset end and finish???
};
struct md3_frame
{
  float min_bounds[3]; //Min (x,y,z) value for the frame
  float max_bounds[3]; //Max (x,y,a) value for the frame
  float local_origin[3]; //Stores the frame position
  float radius; //Scale/Radius of the frame
  char name[16]; //Modeler used to create the loaded model
};
struct md3_tag
{
  char name[64]; //Stores the name of the tag
  Vector3 origin; //Stores the translation that should be performed
  Vector3 axis[3][3]; //Stores the 3x3 rotation matrix for this frame
};
struct md3_surface
{
  int ident; //Stores the identity
  char name[64]; //Stores the surface name
  int flags; //Stores the flags
  int num_frames; //Stores the number of frames
  int num_shaders; //Stores the number of shaders
  int num_verts; //Stores the number of vertices
  int num_triangles; //Stores the number of triangles
  int ofs_triangles; //Stores the offset triangles
  int ofs_shaders; //Stores the offset shaders
  int ofs_ST; //Stores the offset starts
  int ofs_xyzNormal; //Stores the offset starting positions
  int ofs_end; //Stores the offset surface ends
};
struct md3_shader
{
  char name[64]; //Stores the file name
  int shader_index; //Stores the shader index number
};
struct md3_triangle
{
  int indexes[3]; //Stores a list of offset values for Vertex
};
struct md3_texCoord
{
  float st[3]; //Stores s & t texture coordinates
};
struct md3_vertex
{
  short coord[3]; //x,y,z coordinates in right-handed 3-space
  short normal; //Stores angles
};
md3_frame *md3Frame;
md3_tag *md3Tag;
md3_surface *md3Surface;
md3_shader *md3Shader;
md3_triangle *md3Triangle;
md3_texCoord *md3TexCords;
md3_vertex *md3Vertex;
};
#endif

Thats my code at the moment which will change soonish

#1Canvas

Posted 26 April 2012 - 03:09 AM

Cheers Washu, I have a lesson soon so i wont be able to check your code until 1english time :), Sorry about the lack of knowledge, it does come in time tho :)

PARTNERS