Skip to main content
Tweeted twitter.com/#!/StackGameDev/status/436579468053053441
added 305 characters in body
Source Link
CroCo
  • 255
  • 1
  • 2
  • 10

I would like to simulate a point that moves in 2D. The input should be the speed of the mouse, so the new position will be computed as following

new_position = old_position + delta_time*mouse_velocity

As far as I know in GLUT there is no function to acquire the current speed of the mouse between each frame. What I've done so far to compute the delta_time as following

void Display()
{
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0f, 0.0f, 0.0f);
    static int delta_t, current_t, previous_t;
    current_t = glutGet(GLUT_ELAPSED_TIME);
    delta_t = current_t - previous_t;
    std::cout << delta_t << std::endl;

    previous_t = current_t;
    glutSwapBuffers();  
}

Where should I start from here? (Note: I have to get the speed of the mouse because I'm modeling a system)


Edit: Based on the above code, delta_time fluctuates so much

34
19
2
20
1
20
0
16
1
1
10
21
0
13
1
19
34
0
13
0
6
1
14

Why does this happen?

I would like to simulate a point that moves in 2D. The input should be the speed of the mouse, so the new position will be computed as following

new_position = old_position + delta_time*mouse_velocity

As far as I know in GLUT there is no function to acquire the current speed of the mouse between each frame. What I've done so far to compute the delta_time as following

void Display()
{
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0f, 0.0f, 0.0f);
    static int delta_t, current_t, previous_t;
    current_t = glutGet(GLUT_ELAPSED_TIME);
    delta_t = current_t - previous_t;
    std::cout << delta_t << std::endl;

    previous_t = current_t;
    glutSwapBuffers();  
}

Where should I start from here? (Note: I have to get the speed of the mouse because I'm modeling a system)

I would like to simulate a point that moves in 2D. The input should be the speed of the mouse, so the new position will be computed as following

new_position = old_position + delta_time*mouse_velocity

As far as I know in GLUT there is no function to acquire the current speed of the mouse between each frame. What I've done so far to compute the delta_time as following

void Display()
{
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0f, 0.0f, 0.0f);
    static int delta_t, current_t, previous_t;
    current_t = glutGet(GLUT_ELAPSED_TIME);
    delta_t = current_t - previous_t;
    std::cout << delta_t << std::endl;

    previous_t = current_t;
    glutSwapBuffers();  
}

Where should I start from here? (Note: I have to get the speed of the mouse because I'm modeling a system)


Edit: Based on the above code, delta_time fluctuates so much

34
19
2
20
1
20
0
16
1
1
10
21
0
13
1
19
34
0
13
0
6
1
14

Why does this happen?

Source Link
CroCo
  • 255
  • 1
  • 2
  • 10

Mouse Speed in GLUT and OpenGL?

I would like to simulate a point that moves in 2D. The input should be the speed of the mouse, so the new position will be computed as following

new_position = old_position + delta_time*mouse_velocity

As far as I know in GLUT there is no function to acquire the current speed of the mouse between each frame. What I've done so far to compute the delta_time as following

void Display()
{
    
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    glColor3f(1.0f, 0.0f, 0.0f);
    static int delta_t, current_t, previous_t;
    current_t = glutGet(GLUT_ELAPSED_TIME);
    delta_t = current_t - previous_t;
    std::cout << delta_t << std::endl;

    previous_t = current_t;
    glutSwapBuffers();  
}

Where should I start from here? (Note: I have to get the speed of the mouse because I'm modeling a system)