Skip to content

Commit

Permalink
Made rotation smoother.
Browse files Browse the repository at this point in the history
  • Loading branch information
acaudwell committed Aug 20, 2010
1 parent 3cb2019 commit f37654c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions src/gource.cpp
Expand Up @@ -757,7 +757,7 @@ void Gource::reset() {
hoverFile = 0;

manual_rotate = false;
rotation_interval = 0.0f;
rotation_remaining_angle = 0.0f;

selectedUser = 0;
hoverUser = 0;
Expand Down Expand Up @@ -1254,22 +1254,26 @@ void Gource::updateCamera(float dt) {
//automatically rotate camera
if(auto_rotate) {

if(rotation_interval > 0.00001f) {
if(rotation_remaining_angle > 0.0f) {

//rotate 90 degrees over the period of about a second
rotate_angle = 90.0f * rotation_interval*dt * DEGREES_TO_RADIANS;
rotation_interval -= rotation_interval*dt;
//rotation through 90 degrees, speed peaks at half way
float angle_rate = std::max(dt, (float) (1.0f - fabs((rotation_remaining_angle / 90.0f) - 0.5) * 2.0f)) * dt;

rotate_angle = std::min(rotation_remaining_angle, 90.0f * angle_rate);
rotation_remaining_angle -= rotate_angle;

rotate_angle *= DEGREES_TO_RADIANS;

} else if(!cursor.rightButtonPressed() && dir_bounds.area() > 10000.0f) {

float ratio = dir_bounds.width() / dir_bounds.height();

if(ratio < 0.67f) {
rotation_interval = 1.0f;
rotation_remaining_angle = 90.0f;
}
}
} else {
rotation_interval = 0.0f;
rotation_remaining_angle = 0.0f;
}
}

Expand Down Expand Up @@ -1952,7 +1956,7 @@ void Gource::draw(float t, float dt) {
font.print(1,320,"User Inner Loops: %d", gGourceUserInnerLoops);
font.print(1,340,"Dir Inner Loops: %d (QTree items = %d, nodes = %d)", gGourceDirNodeInnerLoops,
dirNodeTree->item_count, dirNodeTree->node_count);
font.print(1,360,"Dir Bounds Ratio: %.2f, %.5f", dir_bounds.width() / dir_bounds.height(), rotation_interval);
font.print(1,360,"Dir Bounds Ratio: %.2f, %.5f", dir_bounds.width() / dir_bounds.height(), rotation_remaining_angle);

if(selectedUser != 0) {

Expand Down
2 changes: 1 addition & 1 deletion src/gource.h
Expand Up @@ -65,7 +65,7 @@ class Gource : public SDLApp {
bool debug, trace_debug;

bool manual_rotate;
float rotation_interval;
float rotation_remaining_angle;

MouseCursor cursor;

Expand Down

0 comments on commit f37654c

Please sign in to comment.