我根据鼠标位置旋转相机。但我希望仅当鼠标左键或右键按下时才激活此功能。这段代码的问题是我必须释放并再次按下才能让程序注意到我已经移动了鼠标。
当使用键盘按键并移动鼠标时,它起作用了。
尝试 glutPostRedisplay 但我不确定它是否是我需要的或如何使用它。
void processMouse(int button, int state, int x, int y) {
if (state == GLUT_DOWN) {
if (button == GLUT_LEFT_BUTTON) {mouseM=true;} if (button == GLUT_RIGHT_BUTTON) {mouseN=true;}
} if (state == GLUT_UP){ if (button == GLUT_LEFT_BUTTON){mouseM=false;} if (button == GLUT_RIGHT_BUTTON) {mouseN=false;} }
}
void mouseMove(int x, int y){
if (x < 0) angleX = 0.0; else if (x > w) angleX = 180.0; else //angleX = 5.0 * ((float) x)/w; angleX = (x-320)/50; angleZ = angleX; angleY= …Run Code Online (Sandbox Code Playgroud) 我正在尝试构建我的代码,就像这个主要的< - 游戏< - 播放器.
如果我写在主要:
player* P;
P = new player;
P->move();
Run Code Online (Sandbox Code Playgroud)
一切正常,但在尝试将此代码移入游戏组件时,我遇到了问题.
以下是我需要帮助的game.cpp的部分内容.
#include "game.h"
#include <string>
using namespace std;
game::game(){
player* P;
P = new player;
};
void game::playerStuff(){
P->move(); //c2227+C2065
};
Run Code Online (Sandbox Code Playgroud)
这是game.h的一部分
#include "player.h"
class game {
public:
game();
void playerStuff();
Run Code Online (Sandbox Code Playgroud)