Difference between revisions of "Tutorial - Setup Horde with Gtkmm"
From Horde3D Wiki
Line 21: | Line 21: | ||
#include <math.h> | #include <math.h> | ||
#include <iomanip> | #include <iomanip> | ||
+ | #include <glibmm/timer.h> | ||
using namespace std; | using namespace std; | ||
Line 43: | Line 44: | ||
//finnaly our horde update function | //finnaly our horde update function | ||
void update_hordeScene(); | void update_hordeScene(); | ||
+ | //gets are current fps | ||
+ | void get_FramesPerSecond(); | ||
private: | private: | ||
Line 48: | Line 51: | ||
NodeHandle _cam, _knight, _particleSys; | NodeHandle _cam, _knight, _particleSys; | ||
float _x, _y, _z, _rx, _ry; // Viewer position and orientation | float _x, _y, _z, _rx, _ry; // Viewer position and orientation | ||
− | + | float _curFPS; | |
− | float _curFPS | ||
− | + | bool _freeze; | |
+ | float _animTime, _weight; | ||
− | + | double last_time; | |
− | + | int frames; | |
+ | |||
+ | Glib::Timer m_animtimer; // our animation timer gets miliseconds | ||
+ | Glib::Timer m_fpstimer; // our fps timer gets current fps | ||
}; | }; | ||
Line 231: | Line 237: | ||
void cHordeWidget::render_hordeScene(){ | void cHordeWidget::render_hordeScene(){ | ||
+ | m_fpstimer.start();//start fps timer | ||
− | Horde3D::setOption( EngineOptions::DebugViewMode, | + | //Horde3D::setOption( EngineOptions::DebugViewMode, 1.0f ); |
− | Horde3D::setOption( EngineOptions::WireframeMode, | + | //Horde3D::setOption( EngineOptions::WireframeMode, 1.0f ); |
− | + | // Do animation blending | |
− | Horde3D::setModelAnimParams( _knight, 0, _animTime | + | Horde3D::setModelAnimParams( _knight, 0, _animTime , _weight ); |
− | Horde3D::setModelAnimParams( _knight, 1, _animTime | + | Horde3D::setModelAnimParams( _knight, 1, _animTime , 1.0f - _weight ); |
// Animate particle systems (several emitters in a group node) | // Animate particle systems (several emitters in a group node) | ||
unsigned int cnt = cnt = Horde3D::findNodes( _particleSys, "", SceneNodeTypes::Emitter ); | unsigned int cnt = cnt = Horde3D::findNodes( _particleSys, "", SceneNodeTypes::Emitter ); | ||
+ | |||
for( unsigned int i = 0; i < cnt; ++i ) | for( unsigned int i = 0; i < cnt; ++i ) | ||
Horde3D::advanceEmitterTime( Horde3D::getNodeFindResult( i ), 1.0f / _curFPS ); | Horde3D::advanceEmitterTime( Horde3D::getNodeFindResult( i ), 1.0f / _curFPS ); | ||
− | + | // Set camera parameters | |
− | + | Horde3D::setNodeTransform( _cam, _x, 4, 25, _rx ,_ry, 0, 1, 1, 1 ); | |
+ | |||
+ | // Show logo | ||
+ | Horde3D::showOverlay( 0.75f, 0, 0, 0, 1, 0, 1, 0, | ||
+ | 1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1, | ||
+ | 7, _logoMatRes ); | ||
− | + | // Render scene | |
− | + | Horde3D::render( _cam ); | |
− | |||
− | |||
− | + | // Remove all overlays | |
− | + | Horde3D::clearOverlays(); | |
− | + | get_FramesPerSecond();//get are frame rate *only call once per a frame | |
− | |||
} | } | ||
void cHordeWidget::update_hordeScene(){ | void cHordeWidget::update_hordeScene(){ | ||
− | |||
− | |||
− | |||
− | Gtk::Widget::queue_draw(); | + | double seconds = m_animtimer.elapsed(); //sets the elapsed time in a double |
+ | |||
+ | _animTime += seconds * 30; // gets the elapsed time and multiplys it by 30 for some smooth animation | ||
+ | |||
+ | m_animtimer.reset(); //reset animiation timer. | ||
+ | |||
+ | Gtk::Widget::queue_draw();//redraw the screen | ||
} | } | ||
+ | |||
+ | void cHordeWidget::get_FramesPerSecond(){ | ||
+ | ++frames; | ||
+ | |||
+ | last_time = last_time + m_fpstimer.elapsed(); | ||
+ | |||
+ | if(last_time >= 0){ | ||
+ | _curFPS = (float)(frames / last_time); | ||
+ | frames = 0; | ||
+ | last_time = 0; | ||
+ | m_fpstimer.reset(); | ||
+ | } | ||
+ | |||
+ | std::cout<<_curFPS<<endl;//prints the current fps to console. | ||
+ | } | ||
+ | |||
+ | |||
Revision as of 18:19, 9 August 2008
|
|