2012-10-29 21 views
0

我有一個struct'GLpoint',在我的NormalCalculator.h中定義。出於某種原因,當我在.cpp文件中定義一個返回GLpoint的函數時,紅色波浪線告訴我「標識符GLpoint未定義」。字面上的函數的返回類型。出現這種情況,在功能是:你能看到我的未定義標識符錯誤來自哪裏嗎?

GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal)

錯誤日誌還告訴我,有一個失蹤「;」在函數定義之前。我看不出這些來自哪裏。特別是作爲computeFaceNormals的定義之前發生的最後一件事是

else return false; 

的代碼可以在下面找到。

NormalCalculator.h

#pragma once 

#include <vector> 
#include <GL/glut.h> 


class NormalCalculator 
{ 

struct GLpoint 
{ 
    GLfloat x,y,z; 
}; 

struct GLface 
{ 
    GLfloat x1,y1,z1,x2,y2,z2,x3,y3,z3; 
}; 

public: 
    NormalCalculator(void); 
    ~NormalCalculator(void); 
    //put all of the face normal functions together 
    void generateFaceNormals(std::vector<GLfloat>* vertexArray, std::vector<GLubyte>* indexArray, std::vector<GLfloat>* normalArray); 


private: 
    //creates the line vectors from the the 3 points passed in as a part of the GLface 
    void createLineVectorsFromFace(GLface facePassedIn, GLpoint* l_vec1, GLpoint* l_vec2); 
    //generates a normal vector for the 2 line vectors made by createLineVectorsFromFace 
    void crossProductOfVecs(GLpoint* l_vec1, GLpoint* l_vec2, GLpoint* outPutNormal); 
    //alters the normal vector so that it is of Unit length 
    bool normalizeVector(GLpoint* normalVector, GLpoint* normalizedNormalVecContainer); 
    GLpoint computeFaceNormal(GLface faceToNormal); 
}; 

NormalCalculator.cpp

#include "NormalCalculator.h" 
#include <gl/glut.h> 
#include <math.h> 
#include <iostream> 





void NormalCalculator::createLineVectorsFromFace(GLface facePassedIn, GLpoint* l_vec1, GLpoint* l_vec2) 
{ 
    //from verts 1 & 2 initialize l_vec1 
    l_vec1->x = facePassedIn.x1 - facePassedIn.x2; 
    l_vec1->y = facePassedIn.y1 - facePassedIn.y2; 
    l_vec1->z = facePassedIn.z1 - facePassedIn.z2; 
    //do that same for l_vec2 from face 2 and 3 
    l_vec2->x = facePassedIn.x2 - facePassedIn.x3; 
    l_vec2->y = facePassedIn.y2 - facePassedIn.y3; 
    l_vec2->z = facePassedIn.z2 - facePassedIn.z3; 
} 


void NormalCalculator::crossProductOfVecs(GLpoint* l_vec1, GLpoint* l_vec2, GLpoint* outPutNormal) 
{ 
    //cross product dat hoe 
    outPutNormal->x = (l_vec1->y * l_vec2->z) - (l_vec1->z * l_vec2->y);//x = aybz-byaz 
    outPutNormal->y = (l_vec1->z * l_vec2->x) - (l_vec1->x - l_vec2->z);//y = azbx-bzax 
    outPutNormal->z = (l_vec1->x * l_vec2->y) - (l_vec1->y - l_vec2->x);//z = axby-bxay 
} 


bool NormalCalculator::normalizeVector(GLpoint* normalVector, GLpoint* normalizedNormalVecContainer) 
{ 
    //first we must work out the magnitude of the normal vector 
    GLfloat mag = (sqrt((float) pow(normalVector->x,2) + pow(normalVector->y,2) + pow(normalVector->z,2))); 

    if(mag) 
    { 
     normalizedNormalVecContainer->x = normalVector->x/mag; 
     normalizedNormalVecContainer->y = normalVector->y/mag; 
     normalizedNormalVecContainer->z = normalVector->z/mag; 
     return true; 
    } 

    else return false; 

} 

GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal) 
{ 
    //first we create a couple of container GLpoints for our 2 line vectors 
    GLpoint a; 
    GLpoint b; 
    createLineVectorsFromFace(faceToNormal, &a, &b); 
    //Create a container for our origional normal 
    GLpoint firstNorm; 
    //We have our line vectors, and a container. Now cross product them and put them in the container. 
    crossProductOfVecs(&a, &b, &firstNorm); 
    //create out last normal container 
    GLpoint finalNorm; 
    //normalize it 
    normalizeVector(&firstNorm, &finalNorm); 

    return finalNorm; 
} 



NormalCalculator::NormalCalculator(void) 
{ 
} 

NormalCalculator::~NormalCalculator(void) 
{ 
} 

回答

4
GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal) 

應該

NormalCalculator::GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal) 

在參數列表中,不需要資格。

+0

我是否正確地認爲我必須在NormalCalculator ::前綴的前綴類型的GLpoint,因爲它是NormalCalculator的成員,而不是說'int','float'或'bool'是標準C庫類型? 再次感謝@LuchianGrigore –

+0

@GuyJoelMcLean是的,它是一個嵌套類型,所以超出了課程範圍,您必須具備資格。 –

相關問題