コード例 #1
0
main() {
    for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++) {
        ballCosines[loopVar] = cos(loopVar * 2 * PI / BALL_RESOLUTION);
        ballSines[loopVar] = sin(loopVar * 2 * PI / BALL_RESOLUTION);
    }
    loadFile();
    glfwInit();
    glfwOpenWindow(WINDOW_WIDTH, WINDOW_HEIGHT, 0, 0, 0, 0, 0, 0, GLFW_WINDOW);
    glFrustum(-1, 1, -WINDOW_HEIGHT / WINDOW_WIDTH, WINDOW_HEIGHT / WINDOW_WIDTH, 1, CAMERA_RANGE);
    for(glfwSetWindowTitle("Camera Demo"); glfwGetWindowParam(GLFW_OPENED) == GL_TRUE; glfwSwapBuffers(), glClear(GL_COLOR_BUFFER_BIT)) {
        if(glfwGetKey('A') == GLFW_PRESS)
            moveBall(-.1,0,0);
        if(glfwGetKey('D') == GLFW_PRESS)
            moveBall(.1,0,0);
        if(glfwGetKey('S') == GLFW_PRESS)
            moveBall(0,-.1,0);
        if(glfwGetKey('W') == GLFW_PRESS)
            moveBall(0,.1,0);
        if(glfwGetKey('Q') == GLFW_PRESS)
            moveBall(0,0,.1);
        if(glfwGetKey('E') == GLFW_PRESS)
            moveBall(0,0,-.1);
        if(glfwGetKey('Z') == GLFW_PRESS)
            moveBall(-xPos,-yPos,-zPos);
        if(glfwGetKey('X') == GLFW_PRESS)
            loadFile();
        physicsStep();
        glPushMatrix();
        glTranslatef(-xCam - xPos, -yCam - yPos, -zCam - zPos);
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballCosines[loopVar] + xPos, ballSines[loopVar] + yPos, zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(xPos, ballCosines[loopVar] + yPos, ballSines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_LOOP);
        for(loopVar = 0; loopVar < BALL_RESOLUTION; loopVar++)
            glVertex3f(ballSines[loopVar] + xPos, yPos, ballCosines[loopVar] + zPos);
        glEnd();
        glBegin(GL_LINE_STRIP);
        for(loopVar = 0; loopVar < vertexDataSize; loopVar += 3) {
            if(vertices[loopVar] == 0 && vertices[loopVar + 1] == 0 && vertices[loopVar + 2] == 0) {
                glEnd();
                glBegin(GL_LINE_STRIP);
            }
            else
                glVertex3f(vertices[loopVar],vertices[loopVar+1],vertices[loopVar+2]);
        }
        glEnd();
        glPopMatrix();
        for(glfwSetTime(glfwGetTime() - 1 / FPS); glfwGetTime() < 1 / FPS; );
    }
}
コード例 #2
0
void World::update()
{
	m_car.update(m_iControlState);
	
	physicsStep(1.0f / m_fDelta);
	m_track.setCurrentPosition(m_car.getPosition());
	updateProbes();
	m_passageEvaluator.update(m_fDelta);

	m_iControlState = 0;
}