2012-10-26 22 views
0

我認爲這是一個範圍問題。我所有試圖傳遞指針或實際結構(GLface或GLpoint)的嘗試都給我提供了未聲明的標識符錯誤。不確定在哪裏定義和聲明我的結構。 (獲取未聲明的標識符)

但是這兩個結構在.h文件中都有明確的定義。

NormalCalulator.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::NormalCalculator(void); 
    NormalCalculator::~NormalCalculator(void); 
    //put all of the face normal functions together 
    void NormalCalculator::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 NormalCalculator::createLineVectorsFromFace(GLface facePassedIn, GLpoint* l_vec1, GLpoint* l_vec2); 
    //generates a normal vector for the 2 line vectors made by createLineVectorsFromFace 
    void NormalCalculator::crossProductOfVecs(GLpoint* l_vec1, GLpoint* l_vec2, GLpoint* outPutNormal); 
    //alters the normal vector so that it is of Unit length 
    bool NormalCalculator::normalizeVector(GLpoint* normalVector, GLpoint* normalizedNormalVecContainer); 
    GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal); 
}; 

和NormalCalculator.cpp如下。

根據編譯器的錯誤,我開始將GLface傳遞給函數createLineVectorsFromFace。 如果有人想知道,GLface作爲對象傳遞而不是指向GLface的指針是有意的。

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





void 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 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) 
{ 
} 

這只是一個瘋狂的猜測,但我需要做一些與typedef?

+0

究竟是什麼是第一個錯誤消息,在什麼源代碼行? – aschepler

+0

是否有效的聲明在類定義中的成員函數與合格的標識符(額外'NormalCalculator ::')那樣? – aschepler

回答

3
void createLineVectorsFromFace(.... 

是不一樣的

void NormalCalculator::createLineVectorsFromFace(.... 

編譯器是正確的(像往常一樣),則沒有限定構件,你定義一個自由函數。

同樣適用於crossProductOfVecs

+0

另外,NormalCalculator :: createLineVectorsFromFace不應該在NormalCalculator的類定義中使用。即,類foo {void foo :: bar(int x); };是壞的,但類foo {void bar(int x); };很好。 – Yakk

+0

你是完全正確的。傻我。 –

+0

Yakk我不太明白你的意思是按類定義。你的意思是在.h文件中,我應該從函數聲明中省略NormalCalculator ::。 因爲現在我被告知 失蹤';'在NormalCalculator :: computeFaceNormals之前(........ 在.cpp文件中。 –