Jump to content

  • Log In with Google      Sign In   
  • Create Account

14 years ago on June 15th Gamedev.net was first launched! We want to thank all of you for being part of our community and hope the best years are ahead of us. Happy birthday Gamedev.net!

#ActualCanvas

Posted 26 April 2012 - 08:56 AM

Ok Washu i have added your code and im getting a error

Here is my Md3Asset.cpp file
#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) {
	std::ifstream fin("../lara_head.MD3", std::ios::binary | std::ios::in);
	auto data = std::vector<char>(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
	md3_header* header = reinterpret_cast<MD3Header*>(&data.front()); //LINE WONT COMPILE
	std::cout<<std::hex<<header->ident<<std::endl;
	for(int32_t i = 0; i < header->num_frames; ++i) {
			md3_frame* frame = reinterpret_cast<md3_frame*>(&data.front() + header->ofs_frames) + i;
			std::cout<<frame->name<<std::endl;
	}

};

and this is my header
Md3Asset.h
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
#include <iterator>
#include "GameAsset.h"
using namespace std;
#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 Vec3 {
  float x, y, z;
};
struct md3_header {
  int32_t ident;
  int32_t version;
  char name[64];
  int32_t flags;
  int32_t num_frames;
  int32_t num_tags;
  int32_t num_surfaces;
  int32_t num_skins;
  int32_t ofs_frames;
  int32_t ofs_tags;
  int32_t ofs_surfaces;
  int32_t ofs_eof;
};
struct md3_frame
{
  Vec3 min_bounds;
  Vec3 max_bounds;
  Vec3 local_origin;
  float radius;
  char name[16];
};
struct md3_tag {
  char name[64];
  Vec3 origin;
  Vec3 axis[3][3];
};
struct md3_surface
{
  int32_t ident; //Stores the identity
  char name[64]; //Stores the surface name
  int32_t flags; //Stores the flags
  int32_t num_frames; //Stores the number of frames
  int32_t num_shaders; //Stores the number of shaders
  int32_t num_verts; //Stores the number of vertices
  int32_t num_triangles; //Stores the number of triangles
  int32_t ofs_triangles; //Stores the offset triangles
  int32_t ofs_shaders; //Stores the offset shaders
  int32_t ofs_ST; //Stores the offset starts
  int32_t ofs_xyzNormal; //Stores the offset starting positions
  int32_t ofs_end; //Stores the offset surface ends
};
struct md3_shader
  {
   char name[64]; //Stores the file name
   int32_t shader_index; //Stores the shader index number
  };
  struct md3_triangle
  {
   int32_t 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
  };
};
#endif

Its ok i have changed the line and the code is compiling BUT, when i click build, it builds it then displays a box for a split second and then just dissappears... I now put the load line as this
std::ifstream fin("data/lara/lara_head.MD3", std::ios::binary | std::ios::in);
and i now get this but still closes
33504449
(from 3DSMax)

#2Canvas

Posted 26 April 2012 - 08:54 AM

Ok Washu i have added your code and im getting a error

Here is my Md3Asset.cpp file
#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) {
	std::ifstream fin("../lara_head.MD3", std::ios::binary | std::ios::in);
	auto data = std::vector<char>(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
	md3_header* header = reinterpret_cast<MD3Header*>(&data.front()); //LINE WONT COMPILE
	std::cout<<std::hex<<header->ident<<std::endl;
	for(int32_t i = 0; i < header->num_frames; ++i) {
			md3_frame* frame = reinterpret_cast<md3_frame*>(&data.front() + header->ofs_frames) + i;
			std::cout<<frame->name<<std::endl;
	}

};

and this is my header
Md3Asset.h
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
#include <iterator>
#include "GameAsset.h"
using namespace std;
#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 Vec3 {
  float x, y, z;
};
struct md3_header {
  int32_t ident;
  int32_t version;
  char name[64];
  int32_t flags;
  int32_t num_frames;
  int32_t num_tags;
  int32_t num_surfaces;
  int32_t num_skins;
  int32_t ofs_frames;
  int32_t ofs_tags;
  int32_t ofs_surfaces;
  int32_t ofs_eof;
};
struct md3_frame
{
  Vec3 min_bounds;
  Vec3 max_bounds;
  Vec3 local_origin;
  float radius;
  char name[16];
};
struct md3_tag {
  char name[64];
  Vec3 origin;
  Vec3 axis[3][3];
};
struct md3_surface
{
  int32_t ident; //Stores the identity
  char name[64]; //Stores the surface name
  int32_t flags; //Stores the flags
  int32_t num_frames; //Stores the number of frames
  int32_t num_shaders; //Stores the number of shaders
  int32_t num_verts; //Stores the number of vertices
  int32_t num_triangles; //Stores the number of triangles
  int32_t ofs_triangles; //Stores the offset triangles
  int32_t ofs_shaders; //Stores the offset shaders
  int32_t ofs_ST; //Stores the offset starts
  int32_t ofs_xyzNormal; //Stores the offset starting positions
  int32_t ofs_end; //Stores the offset surface ends
};
struct md3_shader
  {
   char name[64]; //Stores the file name
   int32_t shader_index; //Stores the shader index number
  };
  struct md3_triangle
  {
   int32_t 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
  };
};
#endif

Its ok i have changed the line and the code is compiling BUT, when i click build, it builds it then displays a box for a split second and then just dissappears...

#1Canvas

Posted 26 April 2012 - 08:48 AM

Ok Washu i have added your code and im getting a error

Here is my Md3Asset.cpp file
#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) {
    std::ifstream fin("../lara_head.MD3", std::ios::binary | std::ios::in);
    auto data = std::vector<char>(std::istreambuf_iterator<char>(fin), std::istreambuf_iterator<char>());
    md3_header* header = reinterpret_cast<MD3Header*>(&data.front()); //LINE WONT COMPILE
    std::cout<<std::hex<<header->ident<<std::endl;
    for(int32_t i = 0; i < header->num_frames; ++i) {
		    md3_frame* frame = reinterpret_cast<md3_frame*>(&data.front() + header->ofs_frames) + i;
		    std::cout<<frame->name<<std::endl;
    }

};

and this is my header
Md3Asset.h
#include <iostream>
#include <fstream>
#include <vector>
#include <cstdint>
#include <iterator>
#include "GameAsset.h"
using namespace std;
#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 Vec3 {
  float x, y, z;
};
struct md3_header {
  int32_t ident;
  int32_t version;
  char name[64];
  int32_t flags;
  int32_t num_frames;
  int32_t num_tags;
  int32_t num_surfaces;
  int32_t num_skins;
  int32_t ofs_frames;
  int32_t ofs_tags;
  int32_t ofs_surfaces;
  int32_t ofs_eof;
};
struct md3_frame
{
  Vec3 min_bounds;
  Vec3 max_bounds;
  Vec3 local_origin;
  float radius;
  char name[16];
};
struct md3_tag {
  char name[64];
  Vec3 origin;
  Vec3 axis[3][3];
};
struct md3_surface
{
  int32_t ident; //Stores the identity
  char name[64]; //Stores the surface name
  int32_t flags; //Stores the flags
  int32_t num_frames; //Stores the number of frames
  int32_t num_shaders; //Stores the number of shaders
  int32_t num_verts; //Stores the number of vertices
  int32_t num_triangles; //Stores the number of triangles
  int32_t ofs_triangles; //Stores the offset triangles
  int32_t ofs_shaders; //Stores the offset shaders
  int32_t ofs_ST; //Stores the offset starts
  int32_t ofs_xyzNormal; //Stores the offset starting positions
  int32_t ofs_end; //Stores the offset surface ends
};
struct md3_shader
  {
   char name[64]; //Stores the file name
   int32_t shader_index; //Stores the shader index number
  };
  struct md3_triangle
  {
   int32_t 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
  };
};
#endif

Is that looking better?

PARTNERS