Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 您能看到我的未定义标识符错误来自哪里吗?_C++ - Fatal编程技术网

C++ 您能看到我的未定义标识符错误来自哪里吗?

C++ 您能看到我的未定义标识符错误来自哪里吗?,c++,C++,我在NormalCalculator.h中定义了一个结构“GLpoint”。出于某种原因,当我在.cpp文件中定义一个返回GLpoint的函数时,红色的曲线告诉我“标识符GLpoint未定义”。根据函数的返回类型。发生这种情况的功能是: GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal) 错误日志还告诉我函数定义之前缺少“;”。我看不出它们是从哪里来的。特别是在定义computeFaceNormals之前发生的最后一件

我在NormalCalculator.h中定义了一个结构“GLpoint”。出于某种原因,当我在.cpp文件中定义一个返回GLpoint的函数时,红色的曲线告诉我“标识符GLpoint未定义”。根据函数的返回类型。发生这种情况的功能是:

GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal)

错误日志还告诉我函数定义之前缺少“;”。我看不出它们是从哪里来的。特别是在定义computeFaceNormals之前发生的最后一件事是

else return false;
代码可以在下面找到

标准计算器

#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);
};
#pragma一次
#包括
#包括
类正态计算器
{
结构GLpoint
{
glx,y,z;
};
结构GLface
{
GLX1,y1,z1,x2,y2,z2,x3,y3,z3;
};
公众:
普通计算器(无效);
~z~正常计算器(无效);
//将所有面法线函数放在一起
void generatefaconormals(std::vector*vertexArray、std::vector*indexArray、std::vector*normalArray);
私人:
//从作为GLface一部分传入的3个点创建线向量
void CreateLineVector fromFace(GLface facePassedIn,GLpoint*l_vec1,GLpoint*l_vec2);
//为createLineVectorsFromFace生成的2个线向量生成法向量
无效向量的交叉乘积(GLpoint*l_vec1、GLpoint*l_vec2、GLpoint*outPutNormal);
//改变法向量,使其具有单位长度
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)
{
}
#包括“NormalCalculator.h”
#包括
#包括
#包括
void NormalCalculator::createLineVectorsFromFace(GLface facePassedIn、GLpoint*l_vec1、GLpoint*l_vec2)
{
//从顶点1和2初始化l_vec1
l_vec1->x=facePassedIn.x1-facePassedIn.x2;
l_vec1->y=facePassedIn.y1-facePassedIn.y2;
l_vec1->z=facePassedIn.z1-facePassedIn.z2;
//从面2和面3对l_vec2执行相同的操作
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)
{
//叉积dat锄头
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
}
布尔NormalCalculator::normalizeVector(GLpoint*normalVector,GLpoint*normalizedNormalVecContainer)
{
//首先我们必须算出法向量的大小
GLfloat mag=(sqrt((浮点)功率(法向量->x,2)+功率(法向量->y,2)+功率(法向量->z,2));
如果(mag)
{
normalizedNormalVecContainer->x=normalVector->x/mag;
normalizedNormalVecContainer->y=normalVector->y/mag;
normalizedNormalVecContainer->z=normalVector->z/mag;
返回true;
}
否则返回false;
}
GLpoint法线计算器::computeFaceNormal(GLface FaceOnNormal)
{
//首先,我们为2个线向量创建几个点
GLA点;
GLB点;
createLineVectorsFromFace(FacetonNormal、a和b);
//为原始法线创建一个容器
GLpoint-firstNorm;
//我们有线向量和一个容器。现在把它们交叉积,放到容器中。
向量向量机(a、b和firstNorm)的交叉乘积;
//创建最后一个普通容器
GLpoint最终形式;
//使其正常化
normalizeVector(&firstNorm,&finalNorm);
返回最终形式;
}
NormalCalculator::NormalCalculator(无效)
{
}
NormalCalculator::~NormalCalculator(无效)
{
}
应该是

NormalCalculator::GLpoint NormalCalculator::computeFaceNormal(GLface faceToNormal)
在参数列表中,不需要资格认证

应该是

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

在参数列表中,不需要限定条件。

我是否正确地假设我必须将NormalCalculator::作为类型GLpoint的前缀,因为它是NormalCalculator的成员,而不是标准C库类型的“int”、“float”或“bool”?再次感谢@LuchianGrigore@GuyJoelMcLean是的,它是一个嵌套类型,因此在类的作用域之外您必须限定它。我是否正确地假设我必须将NormalCalculator::作为类型GLpoint的前缀,因为它是NormalCalculator的成员,而不是标准C库类型的“int”、“float”或“bool”?再次感谢@LuchianGrigore@GuyJoelMcLean是的,它是嵌套类型,因此在类的范围之外,您必须限定它。