Permalink
Browse files

More accurate camera tracking, added --padding option.

Camera now tracks the bounding boxes of objects instead of centre points.

Made bounds updates and pawn drawing more efficient.
  • Loading branch information...
acaudwell committed Aug 18, 2010
1 parent 7990800 commit 2e2a418e8acde9a314265628cfcbe35153a4ccca
Showing with 96 additions and 54 deletions.
  1. +2 −0 ChangeLog
  2. +3 −0 README
  3. +3 −0 data/gource.1
  4. +1 −1 src/core
  5. +2 −1 src/file.cpp
  6. +18 −14 src/gource.cpp
  7. +5 −3 src/gource.h
  8. +17 −4 src/gource_settings.cpp
  9. +3 −0 src/gource_settings.h
  10. +27 −16 src/pawn.cpp
  11. +3 −4 src/pawn.h
  12. +10 −10 src/user.cpp
  13. +2 −1 src/user.h
View
@@ -3,6 +3,8 @@
* C++ efficiency improvements (Oliver Smith).
* Improved cvs-exp log compatibility.
* Re-show name of user when adding a new action if user is idle.
+ * Added --padding option to control camera view padding.
+ * More accurate camera tracking (tracks the bounding boxes of objects).
0.27:
* Display time stops at the time of the last commit.
View
3 README
@@ -152,6 +152,9 @@ options:
--crop AXIS
Crop view on an axis (vertical,horizontal).
+ --padding FLOAT
+ Camera view padding.
+
--multi-sampling
Enable multi-sampling.
View
@@ -124,6 +124,9 @@ Colourize user images.
\fB\-\-crop AXIS\fR
Crop view on an axis (vertical,horizontal).
.TP
+\fB\-\-padding FLOAT\fR
+Camera view padding.
+.TP
\fB\-\-multi\-sampling\fR
Enable multi-sampling.
.TP
Submodule core updated 5 files
+29 −7 bounds.h
+72 −10 conffile.cpp
+16 −1 conffile.h
+2 −5 settings.cpp
+2 −2 vectors.h
View
@@ -23,10 +23,11 @@ std::vector<RFile*> gGourceRemovedFiles;
RFile::RFile(const std::string & name, const vec3f & colour, const vec2f & pos, int tagid) : Pawn(name,pos,tagid) {
hidden = true;
- icon = texturemanager.grab("file.png");
size = gGourceFileDiameter;
radius = size * 0.5;
+ setGraphic(gGourceSettings.file_graphic);
+
speed = 5.0;
nametime = 4.0;
name_interval = nametime;
View
@@ -29,6 +29,10 @@ Gource::Gource(FrameExporter* exporter) {
commitlog = 0;
+ if(!gGourceSettings.file_graphic) {
+ gGourceSettings.file_graphic = texturemanager.grab("file.png");
+ }
+
fontlarge = fontmanager.grab("FreeSans.ttf", 42);
fontlarge.dropShadow(true);
fontlarge.roundCoordinates(true);
@@ -98,7 +102,8 @@ Gource::Gource(FrameExporter* exporter) {
date_x_offset = 0;
camera = ZoomCamera(vec3f(0,0, -300), vec3f(0.0, 0.0, 0.0), 250.0, 5000.0);
-
+ camera.setPadding(gGourceSettings.padding);
+
setCameraMode(gGourceSettings.camera_mode);
root = 0;
@@ -1057,7 +1062,6 @@ void Gource::interactUsers() {
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
RUser* user = it->second;
- user->updateQuadItemBounds();
userTree->addItem(user);
}
@@ -1081,10 +1085,11 @@ void Gource::updateBounds() {
user_bounds.reset();
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
- RUser* u = it->second;
+ RUser* user = it->second;
- if(!u->isIdle()) {
- user_bounds.update(u->getPos());
+ if(!user->isIdle()) {
+ user->updateQuadItemBounds();
+ user_bounds.update(user->quadItemBounds);
}
}
@@ -1094,7 +1099,8 @@ void Gource::updateBounds() {
RDirNode* node = it->second;
if(node->isVisible()) {
- dir_bounds.update(node->getPos());
+ node->updateQuadItemBounds();
+ dir_bounds.update(node->quadItemBounds);
}
}
}
@@ -1105,9 +1111,6 @@ void Gource::updateUsers(float t, float dt) {
size_t idle_users = 0;
- //recalc the user bounds
- user_bounds.reset();
-
// move users
for(std::map<std::string,RUser*>::iterator it = users.begin(); it!=users.end(); it++) {
RUser* u = it->second;
@@ -1156,7 +1159,7 @@ void Gource::updateUsers(float t, float dt) {
}
}
-void Gource::updateQuadTree() {
+void Gource::interactDirs() {
// update quad tree
Bounds2D quadtreebounds = dir_bounds;
@@ -1182,7 +1185,6 @@ void Gource::updateQuadTree() {
RDirNode* node = it->second;
if(!node->empty()) {
- node->updateQuadItemBounds();
dirNodeTree->addItem(node);
}
}
@@ -1329,7 +1331,7 @@ void Gource::logic(float t, float dt) {
//still want to update camera while paused
if(paused) {
updateBounds();
- updateQuadTree();
+ interactDirs();
updateCamera(dt);
return;
}
@@ -1398,11 +1400,12 @@ void Gource::logic(float t, float dt) {
gGourceDirNodeInnerLoops = 0;
gGourceFileInnerLoops = 0;
+ updateBounds();
+
interactUsers();
updateUsers(t, dt);
- updateQuadTree();
- updateBounds();
+ interactDirs();
updateDirs(dt);
updateCamera(dt);
@@ -1817,6 +1820,7 @@ void Gource::draw(float t, float dt) {
if(debug) {
glDisable(GL_TEXTURE_2D);
+ glLineWidth(2.0);
glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
track_users ? user_bounds.draw() : dir_bounds.draw();
View
@@ -173,12 +173,14 @@ class Gource : public SDLApp {
RCommitLog* determineFormat(const std::string& logfile);
- void interactUsers();
+ void updateCamera(float dt);
void updateUsers(float t, float dt);
void updateDirs(float dt);
- void updateCamera(float dt);
- void updateQuadTree();
+
+ void interactUsers();
+ void interactDirs();
+
void updateBounds();
void updateTime(time_t display_time);
View
@@ -81,8 +81,9 @@ if(extended_help) {
printf(" --bloom-multiplier Adjust the amount of bloom (default: 1.0)\n");
printf(" --bloom-intensity Adjust the intensity of the bloom (default: 0.75)\n\n");
+ printf(" --camera-mode MODE Camera mode (overview,track)\n");
printf(" --crop AXIS Crop view on an axis (vertical,horizontal)\n");
- printf(" --camera-mode MODE Camera mode (overview,track)\n\n");
+ printf(" --padding FLOAT Camera view padding (default: 1.0)\n\n");
printf(" --disable-auto-rotate Disable automatic camera rotation\n\n");
@@ -134,6 +135,7 @@ if(extended_help) {
GourceSettings::GourceSettings() {
repo_count = 0;
+ file_graphic = 0;
setGourceDefaults();
@@ -205,6 +207,7 @@ GourceSettings::GourceSettings() {
arg_types["stop-at-time"] = "float";
arg_types["max-user-speed"] = "float";
arg_types["user-friction"] = "float";
+ arg_types["padding"] = "float";
arg_types["max-files"] = "int";
arg_types["font-size"] = "int";
@@ -279,6 +282,7 @@ void GourceSettings::setGourceDefaults() {
user_image_map.clear();
camera_mode = "overview";
+ padding = 1.0f;
crop_vertical = false;
crop_horizontal = false;
@@ -384,9 +388,7 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
if(gource_settings == 0) gource_settings = conffile.getSection(default_section_name);
if(gource_settings == 0) {
- ConfSection* gource_section = new ConfSection("gource");
- conffile.addSection(gource_section);
- gource_settings = gource_section;
+ gource_settings = conffile.addSection("gource");
}
ConfEntry* entry = 0;
@@ -883,6 +885,17 @@ void GourceSettings::importGourceSettings(ConfFile& conffile, ConfSection* gourc
}
}
+ if((entry = gource_settings->getEntry("padding")) != 0) {
+
+ if(!entry->hasValue()) conffile.entryException(entry, "specify padding (float)");
+
+ padding = entry->getFloat();
+
+ if(padding <= 0.0f || padding >= 2.0f) {
+ conffile.invalidValueException(entry);
+ }
+ }
+
// multi-value entries
if((entry = gource_settings->getEntry("highlight-user")) != 0) {
View
@@ -76,6 +76,7 @@ class GourceSettings : public SDLAppSettings {
std::map<std::string, std::string> user_image_map;
std::string camera_mode;
+ float padding;
bool crop_vertical;
bool crop_horizontal;
@@ -114,6 +115,8 @@ class GourceSettings : public SDLAppSettings {
std::vector<Regex*> user_filters;
bool file_extensions;
+ TextureResource* file_graphic;
+
GourceSettings();
void setGourceDefaults();
View
@@ -40,6 +40,9 @@ Pawn::Pawn(const std::string& name, vec2f pos, int tagid) {
this->name_interval = 0.0;
this->namecol = vec3f(1.0, 1.0, 1.0);
this->selectedcol = vec3f(1.0, 1.0, 0.3);
+
+ this->graphic = 0;
+ this->graphic_ratio = 1.0;
}
float Pawn::getSize() {
@@ -60,10 +63,9 @@ void Pawn::showName() {
void Pawn::updateQuadItemBounds() {
- float ratio = icon->h / (float) icon->w;
float halfsize_x = size * 0.5f;
- vec2f halfsize ( halfsize_x, halfsize_x * ratio );
+ vec2f halfsize ( halfsize_x, halfsize_x * graphic_ratio );
//set bounds
quadItemBounds.set(pos - halfsize, pos + halfsize);
@@ -77,6 +79,18 @@ void Pawn::logic(float dt) {
}
}
+void Pawn::setGraphic(TextureResource* graphic) {
+
+ if(graphic) {
+ graphic_ratio = graphic->h / (float) graphic->w;
+ } else {
+ graphic_ratio = 1.0f;
+ }
+
+ this->graphic = graphic;
+}
+
+
void Pawn::setMouseOver(bool over) {
showName();
this->mouseover = over;
@@ -136,9 +150,8 @@ void Pawn::drawSimple(float dt) {
glLoadName(tagid);
- float ratio = icon->h / (float) icon->w;
float halfsize = size * 0.5f;
- vec2f offsetpos = pos - vec2f(halfsize, halfsize*ratio);
+ vec2f offsetpos = pos - vec2f(halfsize, halfsize*graphic_ratio);
float alpha = getAlpha();
vec3f col = getColour();
@@ -156,24 +169,23 @@ void Pawn::drawSimple(float dt) {
glVertex2f(size, 0.0f);
glTexCoord2f(1.0f,1.0f);
- glVertex2f(size, size*ratio);
+ glVertex2f(size, size*graphic_ratio);
glTexCoord2f(0.0f,1.0f);
- glVertex2f(0.0f, size*ratio);
+ glVertex2f(0.0f, size*graphic_ratio);
glEnd();
glPopMatrix();
}
void Pawn::drawShadow(float dt) {
if(isHidden() || !shadow) return;
- float ratio = icon->h / (float) icon->w;
float halfsize = size * 0.5f;
- vec2f offsetpos = pos - vec2f(halfsize, halfsize*ratio) + shadowOffset;
+ vec2f offsetpos = pos - vec2f(halfsize, halfsize*graphic_ratio) + shadowOffset;
float alpha = getAlpha();
- glBindTexture(GL_TEXTURE_2D, getIcon()->textureid);
+ glBindTexture(GL_TEXTURE_2D, graphic->textureid);
glColor4f(0.0, 0.0, 0.0, alpha * gGourceShadowStrength);
@@ -188,10 +200,10 @@ void Pawn::drawShadow(float dt) {
glVertex2f(size, 0.0f);
glTexCoord2f(1.0f,1.0f);
- glVertex2f(size, size*ratio);
+ glVertex2f(size, size*graphic_ratio);
glTexCoord2f(0.0f,1.0f);
- glVertex2f(0.0f, size*ratio);
+ glVertex2f(0.0f, size*graphic_ratio);
glEnd();
glPopMatrix();
}
@@ -202,15 +214,14 @@ void Pawn::draw(float dt) {
glEnable(GL_BLEND);
glEnable(GL_TEXTURE_2D);
- float ratio = icon->h / (float) icon->w;
float halfsize = size * 0.5f;
- vec2f offsetpos = pos - vec2f(halfsize, halfsize*ratio);
+ vec2f offsetpos = pos - vec2f(halfsize, halfsize*graphic_ratio);
float alpha = getAlpha();
vec3f col = getColour();
- glBindTexture(GL_TEXTURE_2D, getIcon()->textureid);
+ glBindTexture(GL_TEXTURE_2D, graphic->textureid);
glPushMatrix();
glTranslatef(offsetpos.x, offsetpos.y, 0.0f);
@@ -225,10 +236,10 @@ void Pawn::draw(float dt) {
glVertex2f(size, 0.0f);
glTexCoord2f(1.0f,1.0f);
- glVertex2f(size, size*ratio);
+ glVertex2f(size, size*graphic_ratio);
glTexCoord2f(0.0f,1.0f);
- glVertex2f(0.0f, size*ratio);
+ glVertex2f(0.0f, size*graphic_ratio);
glEnd();
glPopMatrix();
Oops, something went wrong.

0 comments on commit 2e2a418

Please sign in to comment.