Я использую c ++, OpenGL, графическую библиотеку SOIL и Microsoft Visual c ++ 2010 Express.
я добавил видео, чтобы продемонстрировать проблему
http://www.youtube.com/watch?v=7F7YDN0zbc4&Функция = youtu.be
Это моя текущая проблема;
Наша сцена или среда — это 3D [x] [y] [z].
Проблема не возникает, когда мы движемся в направлении x и ни в y (мы не разрешаем двигаться в направлении y с точки зрения шагов, мы можем прыгать).
Но как только мы доберемся до z = 70, камера развернется. поэтому, если вы двигаетесь в направлении z = 70, а x и y равны 1, давайте рассмотрим нашу ориентацию + в направлении z, но как только мы достигнем 70, наша камера поворачивается, но наша ориентация по-прежнему +. Я знаю это, потому что у меня есть кут << это говорит мне направление и положение системы координат.
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
Я не уверен, какой код мне нужно вставить сюда, поэтому какие функции я должен вставить сюда.
// это наша стартовая позиция
void demo(){
gameState = 1;
player.setPos(4,1,15);
player.setFacing(3);
setPos();
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing();
}
// так мы устанавливаем нашу позицию
void setPos(){
currentXPos = player.getXPos()+(player.getXWidth()/2);
currentYPos = player.getYPos()+(player.getYHeight());
currentZPos = player.getZPos()+(player.getZDepth()/2);
currentYFace = currentYPos;
if(player.getFacing() == 0){
currentXFace = MAPWIDTH;
currentZFace = currentZPos;
}else if(player.getFacing() == 2){
currentXFace = 0;
currentZFace = currentZPos;
}else if(player.getFacing() == 3){
currentXFace = currentXPos;
currentZFace = MAPDEPTH;
}else{
currentXFace = currentXPos;
currentZFace = 0;
}
}
// это наша функция отображения
void /*GraphicsEngine::*/display(){
glClearColor (0.0, 0.0, 0.0, 1.0);
glLoadIdentity ();
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glShadeModel(GL_FLAT);
glClearDepth(1.0);
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
setPos();
gluLookAt(currentXPos,currentYPos,currentZPos,currentXFace,currentYFace,currentZFace,0,1,0);
generateMap();
graphicsFloor();
int i = 0;
if(projectiles.size()>0){
for(i= 0; i< projectiles.size(); i++){
arrow(projectiles.operator[](i).getXPos(),projectiles.operator[](i).getYPos(),projectiles.operator[](i).getZPos(),0.5,BLOCKWIDTH);
}
projectileMotion();
player.advance();
glutPostRedisplay();
}else if(player.advance()){
glutPostRedisplay();
}
glFlush();
glutSwapBuffers();
}
// это наша функция изменения формы
void reshape(int w, int h){
glViewport(0, 0, (GLsizei) w, (GLsizei) h);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(60.0, (GLfloat) w/(GLfloat) h, 1.0, 200.0);
glMatrixMode(GL_MODELVIEW);
glTranslatef(0.0, 0.0, -3.6);
glLoadIdentity();
}
// это то, как мы контролируем то, что пользователь делает с клавиатурой, я не буду публиковать все остальные случаи, так как они пустые
void userAction(unsigned int userInput){
int i;
switch(userInput){
case 1:
player.turnLeft();
glutPostRedisplay();
break;
case 2:
player.turnRight();
//apply graphics
glutPostRedisplay();
break;
case 3:
if(player.getFacing() == 0){
player.setPos(player.getXPos()-1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() ==3){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()-1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() == 2){
player.setPos(player.getXPos()+1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else{
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()+1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}
//apply graphics
glutPostRedisplay();
break;
case 4:
if(player.getFacing() == 0){
player.setPos(player.getXPos()+1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() ==3){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()+1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() == 2){
player.setPos(player.getXPos()-1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else{
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()-1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}
//apply graphics
glutPostRedisplay();
break;
case 5:
if(player.getFacing() == 0){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()-1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() == 2){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()+1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() == 3){
player.setPos(player.getXPos()+1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else{
player.setPos(player.getXPos()-1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}
glutPostRedisplay();
break;
case 6:
if(player.getFacing() == 0){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()+1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else if(player.getFacing() == 2){
player.setPos(player.getXPos(),player.getYPos(),player.getZPos()-1);
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " <<player.getFacing() << "\n";
}else if(player.getFacing() == 1){
player.setPos(player.getXPos()+1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}else{
player.setPos(player.getXPos()-1,player.getYPos(),player.getZPos());
cout << "The player is at position: " << player.getXPos() << ", " << player.getYPos() << ", " << player.getZPos() << ", " << player.getFacing() << "\n";
}
glutPostRedisplay();
break;
}
// и вот как мы устанавливаем лицо
void PlayerCharacter::setFacing(unsigned short newFace){
facing = newFace % 4;
}
// и это для позиции
bool PlayerCharacter::setPos(int x, int y, int z){
positionData pTemp;
pTemp.x = x;
pTemp.y = y;
pTemp.z = z;
pTemp.id = p.id;
pTemp.w = p.w;
pTemp.h = p.h;
pTemp.d = p.d;
pTemp.type = p.type;
if(/*phys->*/openBlocks(pTemp) && /*phys->*/validPosition(pTemp)==0){
p.x=x;
p.y=y;
p.z=z;
/*phys->*/updatePlacements(p);
return true;
}else{
return false;
}
}
currentZPos = player.getZPos (); Это устраняет проблему.
Других решений пока нет …