void Render::step(void) { if(player->hasMoved()) //only recalculate on movement { calculateView(player->x, player->y, player->getDirection()); } }
void resetView() { // camera tripodHeight = 4.0; cameraPos = vec4( gridSize/2.0, gridSize/2.0, 1.0, 1.0 ); cameraPos.z = getZ( cameraPos.x, cameraPos.y ) + tripodHeight; cameraRotXY = M_PI / 2.0; cameraRotZ = 0.0; // matrix stacks mvStack.empty(); projStack.empty(); calculateView(); }
void move( int t ) { // skip if no movement if( moveDir == NONE && lookDir == NONE && heightDir == NONE ) { glutTimerFunc( mspf, move, 0 ); return; } // move if( moveDir & UP ) { cameraPos.x += std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * cos( cameraRotXY ) * moveInc; cameraPos.y += std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * sin( cameraRotXY ) * moveInc; } else if( moveDir & DOWN ) { cameraPos.x -= std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * cos( cameraRotXY ) * moveInc; cameraPos.y -= std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * sin( cameraRotXY ) * moveInc; } if( moveDir & RIGHT ) { cameraPos.x -= std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * cos( cameraRotXY + M_PI / 2.0 ) * moveInc; cameraPos.y -= std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * sin( cameraRotXY + M_PI / 2.0 ) * moveInc; } else if( moveDir & LEFT ) { cameraPos.x += std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * cos( cameraRotXY + M_PI / 2.0 ) * moveInc; cameraPos.y += std::fmax( std::fmin( maxMove, tripodHeight / 4.0 ), moveInc ) * sin( cameraRotXY + M_PI / 2.0 ) * moveInc; } // look if( lookDir & UP ) { cameraRotZ += lookInc; if( cameraRotZ >= M_PI / 2.0 ) { cameraRotZ = M_PI / 2.0 - lookInc; } } else if( lookDir & DOWN ) { cameraRotZ -= lookInc; if( cameraRotZ < -M_PI / 2.0 + lookInc ) { cameraRotZ = -M_PI / 2.0 + lookInc; } } if( lookDir & RIGHT ) { cameraRotXY -= lookInc; if( cameraRotXY < 0.0 ) { cameraRotXY += 2.0 * M_PI; } } else if( lookDir & LEFT ) { cameraRotXY += lookInc; if( cameraRotXY > 2.0 * M_PI ) { cameraRotXY -= 2.0 * M_PI; } } // height if( heightDir == UP ) { tripodHeight *= 1.0 + lookInc; } else if( heightDir == DOWN ) { tripodHeight /= 1.0 + lookInc; if( tripodHeight < moveInc ) { tripodHeight = moveInc; } } // check mesh edges if( cameraPos.x < 0.0 || cameraPos.x > gridSize - 1 || cameraPos.y < 0.0 || cameraPos.y > gridSize - 1 ) { moveToNextMesh(); } // redraw calculateView(); glutPostRedisplay(); // repeat glutTimerFunc( mspf, move, 0 ); }
void keyboard( unsigned char key, int x, int y ) { switch( key ) { case '=': case '+': heightDir = UP; break; case '-': case '_': heightDir = DOWN; break; case '[': case '{': viewLimitOn = true; viewLimit /= 1.1; calculateView(); glutPostRedisplay(); break; case ']': case '}': viewLimitOn = true; viewLimit *= 1.1; calculateView(); glutPostRedisplay(); break; case '\\': case '|': viewLimitOn = !viewLimitOn; calculateView(); glutPostRedisplay(); break; case 'w': case 'W': lookDir = static_cast<direction>( ( lookDir & ~DOWN ) | UP ); break; case 's': case 'S': lookDir = static_cast<direction>( ( lookDir & ~UP ) | DOWN ); break; case 'a': case 'A': lookDir = static_cast<direction>( ( lookDir & ~RIGHT ) | LEFT ); break; case 'd': case 'D': lookDir = static_cast<direction>( ( lookDir & ~LEFT ) | RIGHT ); break; case 13: // 'ENTER' solidMesh = !solidMesh; glPolygonMode( GL_FRONT_AND_BACK, solidMesh ? GL_FILL : GL_LINE ); if( solidMesh ) { glClearColor( skyColor.x, skyColor.y, skyColor.z, 1.0 ); } else { glClearColor( 0.0, 0.0, 0.0, 1.0 ); } glutPostRedisplay(); break; case 033: // 'ESC' exit( EXIT_SUCCESS ); default: break; } }
void VideoMode::SetVirtualResolution(int width, int height) { virtualResolution.x = width; virtualResolution.y = height; calculateView(); }
void VideoMode::SetVirtualResolution(const sf::Vector2i &resolution) { virtualResolution = resolution; calculateView(); }
VideoMode::VideoMode(int windowWidth, int windowHeight, int virtualWidth, int virtualHeight, bool fullscreen) : virtualResolution(virtualWidth, virtualHeight), windowResolution(windowWidth, windowHeight), windowFullscreen(fullscreen) { calculateView(); }
VideoMode::VideoMode(const sf::Vector2i &windowResolution, const sf::Vector2i &virtualResolution, bool fullscreen) : virtualResolution(virtualResolution), windowResolution(windowResolution), windowFullscreen(fullscreen) { calculateView(); }
void Camera::setPosition(glm::vec4 tvec4) { SceneObject::setPosition(tvec4); calculateView(); }
void Camera::setOrientation(glm::quat tquat) { SceneObject::setOrientation(tquat); calculateView(); }