Tommy,
1>------ Build started: Project: sdl, Configuration: Release Win32 ------
1>Compiling...
1>Polygonstruct.cpp
1>C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(590) : warning C4312: 'type cast' : conversion from 'uintptr_t' to 'void *' of greater size
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(566) : while compiling class template member function 'std::istreambuf_iterator<_Elem,_Traits> std::num_get<_Elem,_InIt>::do_get(_InIt,_InIt,std: :ios_base &,std::ios_base::iostate &,void *&) const'
1> with
1> [
1> _Elem=char,
1> _Traits=std::char_traits<char>,
1> _InIt=std::istreambuf_iterator<char,std::char_trai ts<char>>
1> ]
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(1365) : see reference to class template instantiation 'std::num_get<_Elem,_InIt>' being compiled
1> with
1> [
1> _Elem=char,
1> _InIt=std::istreambuf_iterator<char,std::char_trai ts<char>>
1> ]
1>C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(590) : warning C4312: 'type cast' : conversion from 'uintptr_t' to 'void *' of greater size
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(566) : while compiling class template member function 'std::istreambuf_iterator<_Elem,_Traits> std::num_get<_Elem,_InIt>::do_get(_InIt,_InIt,std: :ios_base &,std::ios_base::iostate &,void *&) const'
1> with
1> [
1> _Elem=wchar_t,
1> _Traits=std::char_traits<wchar_t>,
1> _InIt=std::istreambuf_iterator<wchar_t,std::char_t raits<wchar_t>>
1> ]
1> C:\Program Files\Microsoft Visual Studio 8\VC\include\xlocnum(1371) : see reference to class template instantiation 'std::num_get<_Elem,_InIt>' being compiled
1> with
1> [
1> _Elem=wchar_t,
1> _InIt=std::istreambuf_iterator<wchar_t,std::char_t raits<wchar_t>>
1> ]
1>Build log was saved at "file://e:\c++\sdl\sdl\Release\BuildLog.htm"
1>sdl - 0 error(s), 2 warning(s)
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
Here are the code :
Expand|Select|Wrap|Line Numbers
- /*
- Homemade class for loading .ase object files and put vertex and face data into datastructure
- Does not support lights, but have made a colorchage on each face to get a "false" feeling of
- volume of the objects, this means that the setColor is not active for objects until lights are
- supported. Anyhow this colorchange function is not so robust when the objects have over 100 faces
- because then the step between ecah color are getting to small.
- */
- //#include "Polygonstruct.h"
- #include "SDL.h" // SDL: window & input library
- #include "SDL_opengl.h" // platform independent OpenGL include
- #include <vector>
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <math.h>
- #include <stdio.h>
- #include <stdlib.h>
- using namespace std;
- //struct to store vertices
- struct VERTEX{
- float x,y,z;
- };
- //struct to store faces
- struct FACE{
- int index[3];
- };
- class Poly{
- public:
- //vector isnt the fastest structure but uses them anyway
- vector <VERTEX> vertices;
- vector <FACE> faces;
- VERTEX v;
- FACE f;
- float xPos;
- float yPos;
- float zPos;
- GLfloat maxvalue;
- int numberOfVertices;
- int numberOfFaces;
- string filename;
- public:
- Poly(string s){
- LoadFile(s);
- }
- //set pos in world
- void setPos(float x,float y, float z){
- xPos=x;
- yPos=y;
- zPos=z;
- }
- float getPosX(){
- return xPos;
- }
- float getPosY(){
- return yPos;
- }
- float getPosZ(){
- return zPos;
- }
- void LoadFile(string s){
- string line;
- const char* filename = s.c_str(); //convert str to char and return pointer
- ifstream In(filename);
- if (!In) {
- cerr << "Unable to open file";
- exit(1); // call system to stop
- }
- //Parse .asj file to extract relevant data
- while(!In.eof()){
- In>>line;
- //number of vertices
- if (line=="*MESH_NUMVERTEX"){
- In>>line;
- const char* templine = line.c_str();
- numberOfVertices = atoi(templine);
- }
- //number of faces
- if (line=="*MESH_NUMFACES"){
- In>>line;
- const char* templine = line.c_str();
- numberOfFaces = atoi(templine);
- }
- //extract index and vertices
- if(line=="*MESH_VERTEX"){
- In>>line>>(float)v.x>>(float)v.y>>(float)v.z;
- //cout<<i.nVertex<<" "<<v.x<<" "<<v.y<<" "<<v.z<<endl;
- // get max abs vertex value 1 step in normalizing vertex data
- if ( fabs(v.x)>maxvalue){
- maxvalue=fabs(v.x);
- }
- if ( fabs(v.y)>maxvalue){
- maxvalue=fabs(v.y);
- }
- if ( fabs(v.z)>maxvalue){
- maxvalue=fabs(v.z);
- }
- vertices.push_back(v);
- }
- //cout<<maxvalue<<endl;
- //extract faces
- if(line=="*MESH_FACE"){
- In>>line>>line>>(int)f.index[0]>>line>>(int)f.index[1]>>line>>(int)f.index[2];
- faces.push_back(f);
- }
- }//while
- In.close();
- //cout<<faces[0].index[0]<<" "<<faces[0].index[1]<<" "<<faces[0].index[2];
- normalizeVertices();
- }
- void Draw(){
- float inc = (float)0.5/(float)numberOfVertices; // Have to do some color changes to make a "feeling" of light
- //glPushMatrix();
- GLfloat color = 0.5f;
- glBegin(GL_TRIANGLES);
- for(int i=0; i<numberOfFaces; i++){
- glColor3f(color,0.0,0.0);
- color=color+inc;
- for(int j=0; j<3; j++){
- //cout<<vertices[faces[i].index[j]].x<<" "<<vertices[faces[i].index[j]].y<<" "<<vertices[faces[i].index[j]].z<<endl;
- glVertex3f(vertices[faces[i].index[j]].x,vertices[faces[i].index[j]].y,vertices[faces[i].index[j]].z);
- }
- }
- glEnd();
- //glPopMatrix();
- }
- // When importing 3d objects vertex data ranges can be wide. this function normalize vertex data
- // to fall into the range -1 to 1 for x,y and z coord.
- void normalizeVertices(){
- for (unsigned int c=0;c<vertices.size();c++)
- {
- vertices[c].x=(vertices[c].x)/maxvalue;
- vertices[c].y=(vertices[c].y)/maxvalue;
- vertices[c].z=(vertices[c].z)/maxvalue;
- //cout<<vertices[c].x<<" "<<vertices[c].y<<" "<<vertices[c].z<<endl;
- }
- }
- };