gpt4 book ai didi

c++ - glm : is not a type or namespace? 我的标题中有令人困惑的错误

转载 作者:行者123 更新时间:2023-11-30 04:01:11 26 4
gpt4 key购买 nike

我正在关注 this tutorial here (我知道本教程中没有定义从 glfw 2 到 3 的变化,我已经更正了这些方面。

但是,当尝试在应该可以工作后进行编译时,我收到一个错误,因为我的头文件没有将 glm 识别为 namespace ,因此假设 int 会破坏程序的其余部分。

我的标题如下:

#ifndef CONTROLS_HPP
#define CONTROLS_HPP

void computeMatricesFromInputs();
glm::mat4 getViewMatrix();
glm::mat4 getProjectionMatrix();

#endif

我的 .cpp 文件是这样的:

// Include GLFW
#include <glfw3.h>
extern GLFWwindow* window;

// Include GLM
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/transform.hpp>
using namespace glm;

#include "Outputs/controls.hpp"

glm::mat4 ViewMatrix;
glm::mat4 ProjectionMatrix;

glm::mat4 getViewMatrix(){
return ViewMatrix;
}
glm::mat4 getProjectionMatrix(){
return ProjectionMatrix;
}


// Initial position : on +Z
glm::vec3 position = glm::vec3(0, 0, 5);
// Initial horizontal angle : toward -Z
float horizontalAngle = 3.14f;
// Initial vertical angle : none
float verticalAngle = 0.0f;
// Initial Field of View
float initialFoV = 45.0f;

float speed = 3.0f; // 3 units / second
float mouseSpeed = 0.005f;



void computeMatricesFromInputs(){

// glfwGetTime is called only once, the first time this function is called
static double lastTime = glfwGetTime();

// Compute time difference between current and last frame
double currentTime = glfwGetTime();
float deltaTime = float(currentTime - lastTime);

// Get mouse position
double xpos, ypos;
glfwGetCursorPos(window, &xpos, &ypos);

// Reset mouse position for next frame
glfwSetCursorPos(window, 1024 / 2, 768 / 2);

// Compute new orientation
horizontalAngle += mouseSpeed * float(1024 / 2 - xpos);
verticalAngle += mouseSpeed * float(768 / 2 - ypos);

// Direction : Spherical coordinates to Cartesian coordinates conversion
glm::vec3 direction(
cos(verticalAngle) * sin(horizontalAngle),
sin(verticalAngle),
cos(verticalAngle) * cos(horizontalAngle)
);

// Right vector
glm::vec3 right = glm::vec3(
sin(horizontalAngle - 3.14f / 2.0f),
0,
cos(horizontalAngle - 3.14f / 2.0f)
);

// Up vector
glm::vec3 up = glm::cross(right, direction);

// Move forward
if (glfwGetKey(window, GLFW_KEY_UP) == GLFW_PRESS){
position += direction * deltaTime * speed;
}
// Move backward
if (glfwGetKey(window, GLFW_KEY_DOWN) == GLFW_PRESS){
position -= direction * deltaTime * speed;
}
// Strafe right
if (glfwGetKey(window, GLFW_KEY_RIGHT) == GLFW_PRESS){
position += right * deltaTime * speed;
}
// Strafe left
if (glfwGetKey(window, GLFW_KEY_LEFT) == GLFW_PRESS){
position -= right * deltaTime * speed;
}

float FoV = initialFoV;

// Projection matrix : 45° Field of View, 4:3 ratio, display range : 0.1 unit <-> 100 units
ProjectionMatrix = glm::perspective(FoV, 4.0f / 3.0f, 0.1f, 100.0f);
// Camera matrix
ViewMatrix = glm::lookAt(
position, // Camera is here
position + direction, // and looks here : at the same position, plus "direction"
up // Head is up (set to 0,-1,0 to look upside-down)
);

// For the next frame, the "last time" will be "now"
lastTime = currentTime;
}

我很困惑这里发生了什么,使用 glm 的所有其他方面都完全没问题。

最佳答案

Borgleader 已经为我回答了这个问题(谢谢!)。它也通过在 header 中使用包含 glm 来解决。

关于c++ - glm : is not a type or namespace? 我的标题中有令人困惑的错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25921746/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com