-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathanimationcallbacks.h
109 lines (89 loc) · 2.61 KB
/
animationcallbacks.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef ANIMATIONCALLBACKS_H_
#define ANIMATIONCALLBACKS_H_
#include <osg/NodeCallback>
#include <osg/Node>
#include <osg/NodeVisitor>
#include <osg/MatrixTransform>
#include <osg/Drawable>
#include <osgViewer/Viewer>
#include <osgText/Text>
#include <cstdlib>
#include <sstream>
#include <sys/time.h>
#include "macro.h"
namespace amussementpark {
struct HUDDebuggerPosCallBack: public osg::Drawable::UpdateCallback {
private:
osgViewer::Viewer *viewer;
public:
HUDDebuggerPosCallBack(osgViewer::Viewer *view) {
viewer = view;
}
virtual void update(osg::NodeVisitor *nv, osg::Drawable *node) {
osgText::Text *t = static_cast<osgText::Text*>(node);
osg::Vec3 eye, center, up;
viewer->getCamera()->getViewMatrixAsLookAt(eye, center, up);
std::ostringstream strs;
strs << "Viewer x = " << eye.x() << "; y = " << eye.y() << "; z = " << eye.z();
t->setText(strs.str());
}
};
struct HUDDebuggerCallBack: public osg::Drawable::UpdateCallback {
private:
struct timeval start;
INT updateCounter;
public:
HUDDebuggerCallBack() {
gettimeofday(&start, NULL);
updateCounter = 0;
}
DOUBLE updateFPS() {
struct timeval now;
gettimeofday(&now, NULL);
DOUBLE timeNow = now.tv_sec + (now.tv_usec / 1000000.0);
DOUBLE timeStart = start.tv_sec + (start.tv_usec / 1000000.0);
DOUBLE dif = timeNow - timeStart;
DOUBLE fps = 0.0;
if(dif > 0.0)
fps = 10.0 / dif;
gettimeofday(&start, NULL);
return fps;
}
virtual void update(osg::NodeVisitor *nv, osg::Drawable *node) {
if(updateCounter > 10) {
osgText::Text *t = static_cast<osgText::Text*>(node);
std::ostringstream strs;
strs << "Frames per second (FPS): " << (DWORD32)updateFPS();
t->setText(strs.str());
updateCounter = 0;
} else
updateCounter++;
}
};
class AnimationCallBack: public osg::NodeCallback {
public:
AnimationCallBack();
void operator()(osg::Node *node, osg::NodeVisitor *nv);
};
class CameraUpdateCallBack: public osg::NodeCallback {
public:
CameraUpdateCallBack();
void operator()(osg::Node *node, osg::NodeVisitor *nv);
};
class ThreadMilWagonFixCallBack: public osg::NodeCallback {
public:
ThreadMilWagonFixCallBack();
void operator()(osg::Node *node, osg::NodeVisitor *nv);
};
class LightSequenceCallBack: public osg::NodeCallback {
public:
LightSequenceCallBack();
void operator()(osg::Node *node, osg::NodeVisitor *nv);
};
class SunMovementCallBack: public osg::NodeCallback {
public:
SunMovementCallBack();
void operator()(osg::Node *node, osg::NodeVisitor *nv);
};
}
#endif