0

我的 Camera 类构造函数有问题。我有很多在构造函数中初始化的变量,并且为所有变量分配了一些垃圾值而不是我的。问题可能出在哪里?例如printf("%d", yawSensitivity)输出-1610612736

我试图粘贴尽可能少的代码。也许你会发现一个概念错误并指出我正确的方向......

相机.h

class Camera
{
    protected:

        int windowMidX;
        int windowMidY;

        float pitchSensitivity; 
        float yawSensitivity; 

    public:

        Camera(int windowWidth, int windowHeight);
        ~Camera();
};

相机.cpp

Camera::Camera(int windowWidth, int windowHeight)
{
    this->windowMidX = windowWidth  / 2;
    this->windowMidY = windowHeight / 2;

    this->pitchSensitivity = 0.1f; 
    this->yawSensitivity   = 0.1f;
}
Camera::~Camera() {}

相机初始化

Camera *cam = new Camera(WIN_WIDTH, WIN_HEIGHT);
4

1 回答 1

3

例如printf("%d", yawSensitivity)

您的代码表现出未定义的行为。yawSensitivity是类型float%d格式说明符需要一个类型为 的参数int。改为使用%f

于 2013-10-31T00:32:16.403 回答