我试图让我的模型在一个圆圈中移动并且我得到错误,循环和速度是未定义的。我的代码在这里,我提供2个类文件头文件和.cpp文件。
标头文件
#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 :(得分:1)
getPlanetPos被声明为成员函数,但被定义(实现)为自由函数。您只需要使用ObjectLoaderGuiltyspark ::
作为前缀