C++ 更改类变量的问题';价值

C++ 更改类变量的问题';价值,c++,c++11,opengl,C++,C++11,Opengl,我有个问题。我正在处理一个OpenGL项目,我需要通过class方法访问一个类变量。我完成了,但后来修改了一些代码,现在它不工作了,我无法完成。这一切都与偏航和俯仰变量有关。如果我在它们的类方法中更改它们(例如,ProccesMouseInput),它们不会更改它们的值,但我已经在main函数中尝试过了,然后它们会。。。这是我的密码 照相机 #pragma once #include <glm/glm.hpp> #include <glm/vec3.hpp> #inclu

我有个问题。我正在处理一个OpenGL项目,我需要通过class方法访问一个类变量。我完成了,但后来修改了一些代码,现在它不工作了,我无法完成。这一切都与
偏航
俯仰
变量有关。如果我在它们的类方法中更改它们(例如,
ProccesMouseInput
),它们不会更改它们的值,但我已经在main函数中尝试过了,然后它们会。。。这是我的密码

照相机

#pragma once
#include <glm/glm.hpp>
#include <glm/vec3.hpp>
#include <glm/gtc/matrix_transform.hpp>

enum class movement_direction{
    FORWARD,
    BACKWARD,
    LEFT,
    RIGHT,
    UP,
    DOWN
};

class Camera {
private:
    glm::vec3 m_Position;
    glm::vec3 m_Front;
    glm::vec3 m_Up;
    glm::vec3 m_Right;
    glm::vec3 m_WorldUp;
    float m_MouseSensitivity;
    float MovementSpeed = 2.5f;
    float MouseSensitivity = 0.1f;
    float FOV = 45.0f;
    float Yaw;
    float Pitch;


public:
    Camera(glm::vec3 pos, glm::vec3 up, float yaw, float pitch);
    Camera(float PosX, float PosY, float PosZ, float UpX, float UpY, float UpZ, float yaw, float pitch);
    void ProcessMouseInput(float offsetX, float offsetY, bool constrainPitch);
    void ProcessKeyboardInput(movement_direction direction, float deltaTime);
    void ProcessScrollInput(float offsetX, float offsetY);
    void UpdateCameraVectors();
    glm::mat4 GetViewMatrix();
};
#pragma一次
#包括
#包括
#包括
枚举类移动方向{
向前地
向后的
左边
正当
向上的
向下
};
类摄像机{
私人:
glm::vec3 m_位置;
glm::vec3 m_前部;
glm::向上3米;
glm::vec3 m_Right;
glm::vec3 m_WorldUp;
浮动鼠标灵敏度;
浮动移动速度=2.5f;
浮动鼠标灵敏度=0.1f;
浮动视野=45.0f;
浮动偏航;
浮动螺距;
公众:
摄像机(glm::vec3位置、glm::vec3向上、浮动偏航、浮动俯仰);
摄像机(浮标位置X、浮标位置Y、浮标位置Z、浮标向上X、浮标向上Y、浮标向上Z、浮标偏航、浮标俯仰);
void ProcessMouseInput(float offsetX、float offsetY、bool-pitch);
void processkeyboard输入(移动方向、浮点增量);
void ProcessScrollInput(float offsetX,float offsetY);
void UpdateCameraVectors();
glm::mat4 GetViewMatrix();
};
Camera.cpp

#include "Camera.h"
#include <iostream>



Camera::Camera(glm::vec3 pos = glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3 up = glm::vec3(0.0f, 1.0f, 0.0f), float yaw = -90.0f, float pitch = 0.0f)
    : m_Position(pos), m_Up(up), m_WorldUp(up), Yaw(yaw), Pitch(pitch), m_MouseSensitivity(MouseSensitivity)
{

    UpdateCameraVectors();
}

Camera::Camera(float PosX, float PosY, float PosZ, float UpX, float UpY, float UpZ, float yaw, float pitch)
    : m_Position(glm::vec3(PosX, PosY, PosZ)), m_Up(glm::vec3(UpX, UpY, UpZ)), m_WorldUp(glm::vec3(UpX, UpY, UpZ)), Yaw(yaw), Pitch(pitch), m_MouseSensitivity(MouseSensitivity)
{

    UpdateCameraVectors();
}

void Camera::ProcessMouseInput(float offsetX, float offsetY, bool constrainPitch = true)
{
    Yaw += offsetX * m_MouseSensitivity;
    Pitch += offsetY * m_MouseSensitivity;
    if (constrainPitch)
    {
        if (Pitch < -89.0f)
            Pitch = -89.0f;
        if (Pitch > 89.0f)
            Pitch = 89.0f;
    }

    UpdateCameraVectors();

}

void Camera::ProcessKeyboardInput(movement_direction direction, float deltaTime)
{
    float velocity = MovementSpeed * deltaTime;

    if (direction == movement_direction::FORWARD)
        m_Position +=  m_Front * velocity;
    if (direction == movement_direction::BACKWARD)
        m_Position -= m_Front * velocity;
    if (direction == movement_direction::LEFT)
        m_Position -= m_Right * velocity;
    if (direction == movement_direction::RIGHT)
        m_Position += m_Right * velocity;
    if (direction == movement_direction::UP)
        m_Position += m_WorldUp * velocity;
    if (direction == movement_direction::DOWN)
        m_Position -= m_WorldUp * velocity;
}

void Camera::ProcessScrollInput(float offsetX, float offsetY)
{
}

void Camera::UpdateCameraVectors()
{
    glm::vec3 direction;

    direction.x = cos(glm::radians(Yaw)) * cos(glm::radians(Pitch));
    direction.y = sin(glm::radians(Pitch));
    direction.z = sin(glm::radians(Yaw)) * cos(glm::radians(Pitch));

    m_Front = glm::normalize(direction);
    m_Right = glm::normalize(glm::cross(m_Front, m_WorldUp));
    m_Up = glm::normalize(glm::cross(m_Right, m_Front));
}

glm::mat4 Camera::GetViewMatrix()
{
    return glm::lookAt(m_Position, m_Position + m_Front, m_Up);
}

#包括“Camera.h”
#包括
摄像机:摄像机(glm::vec3 pos=glm::vec3(0.0f,0.0f,0.0f),glm::vec3 up=glm::vec3(0.0f,1.0f,0.0f),浮动偏航=-90.0f,浮动俯仰=0.0f)
:m_位置(位置)、m_向上(向上)、m_世界向上(向上)、偏航(偏航)、俯仰(俯仰)、m_鼠标灵敏度(鼠标灵敏度)
{
UpdateCameraVectors();
}
摄像机:摄像机(浮动偏航,浮动偏航,浮动偏航,浮动偏航,浮动上移,浮动上移,浮动上移,浮动偏航,浮动俯仰)
:m_位置(glm::vec3(PosX,PosY,PosZ)),m_向上(glm::vec3(UpX,UpY,UpZ)),m_世界向上(glm::vec3(UpX,UpY,UpZ)),偏航(偏航),俯仰(俯仰),m_鼠标灵敏度(鼠标灵敏度)
{
UpdateCameraVectors();
}
无效摄影机::ProcessMouseInput(浮点偏移量x、浮点偏移量y、布尔约束间距=true)
{
偏航+=偏移量x*m_鼠标灵敏度;
螺距+=偏移*m_鼠标灵敏度;
如果(俯仰)
{
如果(节距<-89.0f)
螺距=-89.0f;
如果(节距>89.0f)
螺距=89.0f;
}
UpdateCameraVectors();
}
无效摄影机::处理键盘输入(移动方向、浮动增量)
{
浮动速度=移动速度*增量时间;
如果(方向==移动方向::前进)
m_位置+=m_前部*速度;
如果(方向==移动方向::向后)
m_位置-=m_前部*速度;
如果(方向==移动方向::左)
m_位置-=m_右*速度;
如果(方向==移动方向::右)
m_位置+=m_右*速度;
如果(方向==移动方向::向上)
m_位置+=m_世界上升*速度;
如果(方向==移动方向::向下)
m_位置-=m_WorldUp*速度;
}
无效摄影机::ProcessScrollInput(浮动偏移量x,浮动偏移量y)
{
}
无效摄影机::UpdateCameraVectors()
{
glm::vec3方向;
方向x=cos(glm::弧度(偏航))*cos(glm::弧度(俯仰));
方向y=sin(glm::弧度(节距));
方向z=sin(glm::弧度(偏航))*cos(glm::弧度(俯仰));
m_Front=glm::规格化(方向);
m_Right=glm::normalize(glm::cross(m_Front,m_WorldUp));
m_Up=glm::normalize(glm::cross(m_Right,m_Front));
}
glm::mat4摄像头::GetViewMatrix()
{
返回glm::lookAt(m_位置,m_位置+m_前部,m_向上);
}
Application.cpp

/* Including GLEW */
#include <GL/glew.h>

/* Including GLFW */
#include <GLFW/glfw3.h>

#define STB_IMAGE_IMPLEMENTATION
#include "vendor/stb_image/stb_image.h"

#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>

#include <iostream>
#include <string>
#include <conio.h>

#include "Shader.h"
#include "Camera.h"

void processInput(GLFWwindow* window);
void mouse_callback(GLFWwindow* window, double xpos, double ypos);
void scroll_callback(GLFWwindow* window, double offsetX, double offsetY);

const int SCR_WIDTH = 800;
const int SCR_HEIGHT = 600;

float deltaTime = 0.0f;
float currentFrame = 0.0f;
float lastFrame = 0.0f;

float lastX = SCR_WIDTH / 2;
float lastY = SCR_HEIGHT / 2;

bool firstMouse = true;

float fov = 45.0f;

Camera main_camera(glm::vec3(0.0f, 0.0f, -3.0f), glm::vec3(0.0f, 1.0f, 0.0f), -90.0f, 0.0f);

int main(void)
{

    GLFWwindow* window;

    /* Initializing the library */
    if (!glfwInit())
    {
        std::cout << "Failed to initialize GLFW.\n";
        return -1;
    }

    /* Creating a windowed mode window and its OpenGL context */

    window = glfwCreateWindow(SCR_WIDTH, SCR_HEIGHT, "Hello World", NULL, NULL);

    if (!window)
    {
        std::cout << "Failed to open GLFW window.\n";
        glfwTerminate();
        return -1;
    }

    /* Making the window's context current */
    glfwMakeContextCurrent(window);
    if (glewInit() != GLEW_OK)
        std::cout << "Failed to initialize GLEW\n";

    glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_DISABLED);
    glfwSetCursorPosCallback(window, mouse_callback);

    glfwSetScrollCallback(window, scroll_callback);

    /* Getting the version of GL */
    std::cout << "Using GL Version: " << glGetString(GL_VERSION) << std::endl;

    float vertices[] = {
        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
         0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
         0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
         0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
        -0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,

        -0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
         0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
        -0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
        -0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,

        -0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
        -0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
        -0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
        -0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,

         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
         0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
         0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
         0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
         0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,

        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
         0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
         0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
         0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
        -0.5f, -0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
        -0.5f, -0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,

        -0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f,
         0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 1.0f,
         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
         0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    1.0f, 0.0f,
        -0.5f,  0.5f,  0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 0.0f,
        -0.5f,  0.5f, -0.5f,    0.0f, 0.0f, 0.0f,    0.0f, 1.0f
    };

    glm::vec3 cubes_positions[]{
        glm::vec3( 0.0f,  0.0f,  0.0f),
        glm::vec3( 2.0f,  5.0f, -15.0f),
        glm::vec3(-1.5f, -2.2f, -2.5f),
        glm::vec3(-3.8f, -2.0f, -12.3f),
        glm::vec3( 2.4f, -0.4f, -3.5f),
        glm::vec3(-1.7f,  3.0f, -7.5f),
        glm::vec3( 1.3f, -2.0f, -2.5f),
        glm::vec3( 1.5f,  2.0f, -2.5f),
        glm::vec3( 1.5f,  0.2f, -1.5f),
        glm::vec3(-1.3f,  1.0f, -1.5f)
    };


    /* VERTEX ARRAY */
    unsigned int VAO;
    glGenVertexArrays(1, &VAO);
    glBindVertexArray(VAO);

    /* VERTEX BUFFER */
    unsigned int VBO;
    glGenBuffers(1, &VBO);
    glBindBuffer(GL_ARRAY_BUFFER, VBO);
    glBufferData(GL_ARRAY_BUFFER, sizeof(vertices), vertices, GL_STATIC_DRAW);

    /* VERTEX LAYOUT */
    glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)0);
    glEnableVertexAttribArray(0);

    glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(3 * sizeof(float)));
    glEnableVertexAttribArray(1);

    glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, 8 * sizeof(float), (void*)(6 * sizeof(float)));
    glEnableVertexAttribArray(2);

    /* LOADING TEXTURES */
    // --- first texture object ---
    unsigned int texture1;
    glGenTextures(1, &texture1);
    glBindTexture(GL_TEXTURE_2D, texture1);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    float borderColor1[]{
        0.1f, 0.1f, 0.0f, 1.0f
    };
    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor1);

    int width, height, channelsNr;
    unsigned char* data = stbi_load("res/textures/container.jpg", &width, &height, &channelsNr, 0);
    if (data)
    {
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, data);
        glGenerateMipmap(GL_TEXTURE_2D);
    }
    else
    {
        std::cout << "Failed to load texture\n";
    }
    stbi_image_free(data);

    // --- second texture object ---
    unsigned int texture2;
    glGenTextures(1, &texture2);
    glBindTexture(GL_TEXTURE_2D, texture2);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
    glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

    float borderColor2[]{
        0.1f, 0.1f, 0.0f, 1.0f
    };
    glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, borderColor2);

    stbi_set_flip_vertically_on_load(true);
    data = stbi_load("res/textures/awesomeface.png", &width, &height, &channelsNr, 0);
    if (data)
    {
        glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, data);
    }
    else
    {
        std::cout << "Failed to load texture\n";
    }
    stbi_image_free(data);

    /* BINDING BEFORE THE DRAW CALL */
    // --- shader ---
    Shader basic("res/shaders/Basic.glsl");
    basic.Bind();
    basic.SetUniform1i("texture1", 0);
    basic.SetUniform1i("texture2", 1);
    glEnable(GL_DEPTH_TEST);
    // --- texture ---
    glBindTexture(GL_TEXTURE_2D, texture2);

    // --- vertex array object ---
    glBindVertexArray(VAO);

    float value = 0.5f;
    basic.SetUniform1f("mix_value", 0.2f);

    /* Loop until the user closes the window */
    while (!glfwWindowShouldClose(window))
    {
        currentFrame = (float)glfwGetTime();
        deltaTime = currentFrame - lastFrame;
        lastFrame = currentFrame;

        processInput(window);

        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
        glClearColor(0.f, 0.2f, 0.2f, 1.f);
        /* Render here */

        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, texture1);

        glActiveTexture(GL_TEXTURE1);
        glBindTexture(GL_TEXTURE_2D, texture2);

        glm::mat4 projection = glm::perspective(glm::radians(fov), (float)SCR_WIDTH / (float)SCR_HEIGHT, 0.1f, 100.0f);
        basic.SetUniformMatrix4fv("proj", 1, glm::value_ptr(projection));

        glm::mat4 view = main_camera.GetViewMatrix();
        basic.SetUniformMatrix4fv("view", 1, glm::value_ptr(view));

        for (int i = 0; i < (sizeof(cubes_positions) / sizeof(glm::vec3)); i++)
        {
            float angle = 20.0f * i;
            glm::mat4 model = glm::mat4(1.0f);
            model = glm::translate(model, cubes_positions[i]);
            model = glm::rotate(model, glm::radians(angle), glm::vec3(1.0f, 0.0f, 0.0f));
            basic.SetUniformMatrix4fv("model", 1, glm::value_ptr(model));

            glDrawArrays(GL_TRIANGLES, 0, 36);
        }

        /* Swap front and back buffers */
        glfwSwapBuffers(window);

        /* Poll for and process events */
        glfwPollEvents();

    }

    glfwTerminate();
    return 0;
}

void processInput(GLFWwindow *window)
{
    if (glfwGetKey(window, GLFW_KEY_ESCAPE) == GLFW_PRESS)
        glfwSetWindowShouldClose(window, true);

    if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::FORWARD, deltaTime);
    if (glfwGetKey(window, GLFW_KEY_S) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::BACKWARD, deltaTime);
    if (glfwGetKey(window, GLFW_KEY_A) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::LEFT, deltaTime);
    if (glfwGetKey(window, GLFW_KEY_D) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::RIGHT, deltaTime);
    if (glfwGetKey(window, GLFW_KEY_SPACE) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::UP, deltaTime);
    if (glfwGetKey(window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS)
        main_camera.ProcessKeyboardInput(movement_direction::DOWN, deltaTime);
}

void mouse_callback(GLFWwindow* window, double xpos, double ypos)
{
    if (firstMouse)
    {
        lastX = (float)xpos;
        lastY = (float)ypos;
        firstMouse = false;
    }

    float offsetX = (float)xpos - lastX;
    float offsetY = lastY - (float)ypos;
    lastX = (float)xpos;
    lastY = (float)ypos;
    main_camera.ProcessMouseInput(offsetX, offsetY, true);
}

void scroll_callback(GLFWwindow* window, double offsetX, double offsetY)
{
    fov -= (float)offsetY;
    if (fov < 1.0f)
        fov = 1.0f;
    if (fov > 90.0f)
        fov = 90.0f;
}
/*包括GLEW*/
#包括
/*包括GLFW*/
#包括
#定义机顶盒映像的实现
#包括“供应商/stb_映像/stb_映像.h”
#包括
#包括
#包括
#包括
#包括
#包括
#包括“Shader.h”
#包括“Camera.h”
无效处理输入(GLFWwindow*窗口);
无效鼠标回调(GLFWwindow*窗口,双XPO,双YPO);
无效滚动_回调(GLFWwindow*窗口,双偏移量,双偏移量);
const int SCR_WIDTH=800;
常数int SCR_高度=600;
浮动增量时间=0.0f;
浮动电流帧=0.0f;
浮动lastFrame=0.0f;
浮动lastX=SCR_宽度/2;
浮动长度=SCR\U高度/2;
bool firstMouse=true;
浮动视野=45.0f;
摄像头主摄像头(glm::vec3(0.0f,0.0f,-3.0f),glm::vec3(0.0f,1.0f,0.0f),-90.0f,0.0f);
内部主(空)
{
GLFWwindow*窗口;
/*初始化库*/
如果(!glfwInit())
{

std::cout我终于修复了它!这与
mouseseensitivity
乘以
offsetX
offsetY
有关。由于某些原因,它没有正确初始化,因此被指定为0。通过乘以零,你得到零,因此
偏航和
俯仰
没有改变。谢谢你的帮助lp请您提供一个最小的可重复性示例,而不是要求修复您的代码?请澄清:“如果我在类方法中更改它们”-您的意思是
Camera::ProcessMouseInput
?“但如果我在主函数中更改它们”-这意味着什么?我看不到您这样做的行(你不能,因为两者都是私有的)。可能问题出在构造函数中。检查:
if(Yaw!=newYaw)
if(Pitch!=newPitch)
逻辑错误并导致UB,因为这些成员以前没有被初始化为任何值。您到底在哪里更改偏航值?您在哪里调用该方法?您如何知道成员没有更改?
mouse\u callback中调用“processmouseinput”,在鼠标移动时在main中定义。我已分配将其放在主函数的顶部(
glfwSetCursorPosCallback(窗口,鼠标回调);
)。更重要的是,构造函数并不重要(但感谢您指出,将
Yaw
分配给
newYaw
在逻辑上是不正确的