2013-04-28 70 views
-1

我试图让我的模型在一个圆圈内移动,而且我得到的错误是循环和速度都是undefined.my代码在这里,并且即时提供2个类文件头文件和.cpp文件。OpenGL对象在一个圆圈内自动移动

头文件

#ifndef OBJECTLOADERGUILTYSPARK_H 
#define OBJECTLOADERGUILTYSPARK_H 

#include <iostream> 
#include <windows.h> 
#include <GL/gl.h> 
#include <GL/glu.h> 
#include "glut.h" 
#include <istream> 
#include <fstream> 
#include <string> 
#include <sstream> 
#include <vector> 
#include "StructHeader.h" 

using namespace std; 

class ObjectLoaderGuiltyspark 
{ 
private: 

string guiltyName; 
int numVert; 
int numNormals; 
int numcoords; 
int numFaces; 
int ammount; 
float speed; 
point3D loop; 
float radius; 
point3D v343[1718]; 
point3D vn343[964]; 
point3D vt343[521]; 
point3Di f343[5186][3]; 


public: 
ObjectLoaderGuiltyspark(string guiltyName); 
~ObjectLoaderGuiltyspark() {}; 

void objLoader343(string guiltyName); 
void draw343(int x, int y, int z, point3D loop[], int radius); 
void getCalcPlanetCircle(); 
circle getPlanetPos(); 
    }; 

    #endif 

类文件

#include <windows.h> 
#include "ObjectLoaderGuiltyspark.h" 
#include <math.h> 



ObjectLoaderGuiltyspark::ObjectLoaderGuiltyspark(string gName) 
: guiltyName(gName) 
{ 
numVert = 0; 
numNormals = 0; 
numcoords = 0; 
numFaces = 0; 
ammount = 0; 
speed = 5; 
radius = 5; 
loop = new point3D[600]; 

} 

void ObjectLoaderGuiltyspark::objLoader343(string gfile) 
{ 

string test; 
ifstream inputFile; 
inputFile.open(gfile); 

if (!inputFile.good()) 
    cout << "Problem with Input File"; 
else 
{ 
    while(inputFile >> test) 
    { 

     if (test == "v") 
     { 
      inputFile >> v343[numVert].x; 
      inputFile >> v343[numVert].y; 
      inputFile >> v343[numVert].z; 
      numVert++; 
     } 

     else if(test == "vn") 
     { 
      inputFile >> vn343[numNormals].x; 
      inputFile >> vn343[numNormals].y; 
      inputFile >> vn343[numNormals].z; 
      numNormals++; 
     } 
     else if(test == "vt") 
     { 
      inputFile >> vt343[numcoords].x; 
      inputFile >> vt343[numcoords].y; 
      inputFile >> vt343[numcoords].z; 
      numcoords++; 
     } 
     else if(test == "f") 
     { 
      string temp; 
      for(int count = 0; count < 3; count++) 
      { 
       inputFile >> temp; 
       stringstream stream(temp); 

       getline(stream, temp, '/'); 
       f343[numFaces][count].x = atoi(temp.c_str()) - 1; 
       getline(stream, temp, '/'); 
       f343[numFaces][count].y = atoi(temp.c_str()) - 1; 
       getline(stream, temp, '/'); 
       f343[numFaces][count].z = atoi(temp.c_str()) - 1; 
      } 

      numFaces++; 
     } 


    } 
} 
} 

void getCalcPlanetCircle(point3D loop[], int radius) 
{ 

    for (int i = 0; i < 600 ; i++) 
     { 
      loop[i].x = radius * sin(i/100.0); 
      loop[i].y = 0; 
      loop[i].z = radius * cos(i/100.0); 
     } 
} 


circle getPlanetPos() 
{ 
    circle loopPos; 
    loopPos.xRot = loop[(int)(ceil (speed))].x; 
    loopPos.yRot = loop[(int)(ceil (speed))].y; 
    loopPos.zRot = loop[(int)(ceil (speed))].z; 
    return loopPos; 
} 

void ObjectLoaderGuiltyspark::draw343(int x, int y, int z, point3D loop[], int radius) 
{ 

glTranslated(loop[(int)(ceil (speed))].x, loop[(int)(ceil (speed))].y, loop[(int)   (ceil (speed))].z); 

for(int i = 0; i < 5186; i++)//reads coords for verts from global arrays. 
{ 

    glBegin(GL_TRIANGLES); 

    glColor3f(1.0, 1.0, 1.0); 
    int one = f343[i][0].x; 
    int two = f343[i][1].x; 
    int three = f343[i][2].x; 

    int tex_one = f343[i][0].z; 
    int tex_two = f343[i][1].z; 
    int tex_three = f343[i][2].z; 

    glVertex3fv(&(v343[one].x)); 
    glTexCoord2fv(&(vt343[tex_one].x)); 
    glVertex3fv(&(v343[two].x)); 
    glTexCoord2fv(&(vt343[tex_two].x)); 
    glVertex3fv(&(v343[three].x)); 
    glTexCoord2fv(&(vt343[tex_three].x)); 


    glEnd(); 
} 
} 
+0

为前缀,那么你是否包含了带有point3d定义的文件? – 4pie0 2013-04-28 23:58:12

+0

是的,它现在编译,只是为了澄清它之前呈现,它是查看能力,我只是想使它移动一个点 – 2013-04-29 00:21:01

回答

1

getPlanetPos被声明为成员函数,但定义(实现),其为游离的功能。你只需要以ObjectLoaderGuiltyspark ::

+0

感谢它现在编译,但我将原始位置设置为0,0和半径为2但它没有渲染或我无法找到它。 – 2013-04-29 00:17:40