Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

FPS.C

Go to the documentation of this file.
00001 /***************************************************************************
00002  *cr                                                                       
00003  *cr            (C) Copyright 1995-2019 The Board of Trustees of the           
00004  *cr                        University of Illinois                       
00005  *cr                         All Rights Reserved                        
00006  *cr                                                                   
00007  ***************************************************************************/
00008 
00009 #include <stdio.h>
00010 #include "FPS.h"
00011 #include "DisplayDevice.h"
00012 #include "Displayable.h"
00013 #include "DispCmds.h"
00014 #include "Scene.h"
00015 
00016 FPS::FPS(DisplayDevice *d, Displayable *par) 
00017 : Displayable(par), disp(d) {
00018   last_update = time_of_day(); // setup time of day with initial value
00019   loop_count = 0;
00020 
00021   // disable transformations on this displayable
00022   rot_off();
00023   glob_trans_off();
00024   cent_trans_off();
00025   scale_off();
00026 
00027   // set the text color category, index, etc. 
00028   colorCat = scene->add_color_category("Display");
00029   if (colorCat < 0)
00030     colorCat = scene->category_index("Display");
00031 
00032   usecolor = scene->add_color_item(colorCat, "FPS", REGWHITE);
00033   do_color_changed(colorCat);
00034 }
00035 
00036 void FPS::prepare() {
00037   if (!displayed()) return;
00038   ++loop_count;
00039   double curtime = time_of_day();
00040   // force a redraw....
00041   need_matrix_recalc();
00042   // but don't redraw indicator more than twice per second
00043   if (curtime - last_update < 0.5) return;
00044   double rate = loop_count / (curtime - last_update);
00045   last_update = curtime;
00046   loop_count = 0;
00047 
00048   reset_disp_list();
00049   append(DMATERIALOFF);
00050 
00051   float asp = disp->aspect();
00052   float poscale = 1.2f;
00053   float pos[3];
00054   pos[0] = asp * poscale;
00055   pos[1] = poscale;
00056   pos[2] = 0;
00057   
00058   DispCmdColorIndex cmdColor;
00059   cmdColor.putdata(usecolor, cmdList);
00060 
00061   DispCmdText cmdText;
00062   char buf[20];
00063   sprintf(buf, "%5.2f", rate);
00064   cmdText.putdata(pos, buf, 1.0f, 1.0f, 0, 0, cmdList);
00065 }
00066 
00067 void FPS::do_color_changed(int clr) {
00068   if (clr == colorCat) {
00069     usecolor = scene->category_item_value(colorCat, "FPS");
00070   }
00071 }
00072 

Generated on Fri Nov 8 02:44:36 2024 for VMD (current) by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002