我在尝试学习一些opengl和shader的东西时遇到了这个错误...
代码:
#pragma once
#include "OpenGL.h"
#include "glm\glm.hpp"
#include "glm\gtx\transform.hpp"
#include "Camera.h"
class Transform
{
private:
glm::vec3 position;
glm::vec3 rotation;
glm::vec3 scale;
public:
Transform(void);
~Transform(void);
inline glm::vec3* GetPos() { return &position; }
inline glm::vec3* GetRot() { return &rotation; }
inline glm::vec3* GetScale() { return &scale; }
inline void SetPos(glm::vec3& pos) { this->position = pos; }
inline void SetRot(glm::vec3& rot) { this->rotation = rot; }
inline void SetScale(glm::vec3& scale) { this->scale = scale; }
void Update();
/*inline glm::mat4 GetModelMatrix() const
{
glm::mat4 posMat = glm::translate(position);
glm::mat4 scaleMat = glm::scale(scale);
glm::mat4 rotX = glm::rotate(rotation.x, glm::vec3(1.0, 0.0, 0.0));
glm::mat4 rotY = glm::rotate(rotation.y, glm::vec3(0.0, 1.0, 0.0));
glm::mat4 rotZ = glm::rotate(rotation.z, glm::vec3(0.0, 0.0, 1.0));
glm::mat4 rotMat = rotX * rotY * rotZ;
return posMat * rotMat * scaleMat; //Model Matrix
}
*/
//glm::mat4 GetMVP();
inline glm::mat4 GetMVP(Camera& camera) //LINE A
{
glm::mat4 posMat = glm::translate(position);
glm::mat4 scaleMat = glm::scale(scale);
glm::mat4 rotX = glm::rotate(rotation.x, glm::vec3(1.0, 0.0, 0.0));
glm::mat4 rotY = glm::rotate(rotation.y, glm::vec3(0.0, 1.0, 0.0));
glm::mat4 rotZ = glm::rotate(rotation.z, glm::vec3(0.0, 0.0, 1.0));
glm::mat4 rotMat = rotX * rotY * rotZ;
glm::mat4 ModelMatrix = posMat * rotMat * scaleMat;
glm::mat4 MVP = camera.GetViewProjection()* ModelMatrix; //LINE B
return MVP;
}
};
此代码是Transform类功能的一部分。
我在A行和B行出错了
错误:
error C2061: syntax error : identifier 'Camera'
error C2065: 'camera' : undeclared identifier
error C2228: left of '.GetViewProjection' must have class/struct/union
第三个错误是相关的(B行)
原因是什么? “必须有class / struct / union”?
编辑Camera.h
#include "OpenGL.h"
#include "Input.h"
#include "Input_Keys.h"
#include "Transform.h"
class Camera
{
glm::mat4 projection;
glm::vec3 pos;
glm::vec3 forward;
glm::vec3 up;
//para rot vertical
glm::vec3 right;
float FOV;
float moveSpeed;
bool freeze;
float rot_horizontal;
float rot_vertical;
Input* input_handler;
Window* window_handler;
public:
Camera(bool _freeze ,float _moveSpeed , const glm::vec3& pos, float fov, float aspect, float zNear, float zFar);
~Camera(void);
void SetInputHandler(Input* _input);
void SetFreeze(bool freeze);
void Move(); //WASD
void Look(); //up down left right
void ShowData();
glm::mat4 Camera:: GetViewProjection();
};
和GetViewProjection ...
glm::mat4 Camera:: GetViewProjection()
{
return projection * glm::lookAt(pos, pos + forward, up);
}
好的,现在只有一个错误:
error C2061: syntax error : identifier 'Camera'
我注意到getviewprojection()有“Camera ::”所以我将其删除,并将内联函数转换为非内联函数
在Transform类中......
#pragma once
#include "OpenGL.h"
#include "glm\glm.hpp"
#include "glm\gtx\transform.hpp"
#include "Camera.h"
在Camera类中......
#pragma once
#include "OpenGL.h"
#include "Input.h"
#include "Input_Keys.h"
#include "Transform.h"
我认为订单应该重要吗?
答案 0 :(得分:0)
您需要在此文件中包含包含Camera
类定义的标头。在顶部附近,您应该执行以下操作:
#include "Camera.h" // Or whatever the name of the header that contains the Camera definition is