00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef _3D_CAMERA_SHAKE_H
00028 #define _3D_CAMERA_SHAKE_H
00029
00030 #include <PVLE/Export.h>
00031 #include <PVLE/3D/AutoDeleteChildCallback.h>
00032
00033 #include <vector>
00034 #include <osg/ref_ptr>
00035 #include <osg/observer_ptr>
00036 #include <osg/Camera>
00037 #include <osg/NodeVisitor>
00038
00039
00040
00041
00042
00043
00044
00046 class PVLE_EXPORT CameraShakeParams {
00047 public:
00048 CameraShakeParams()
00049 : frequency(3), amplitude(1), angleTheta(0), anglePhi(0), dispersionTheta(0), dispersionPhi(0), timeFullAmplitude(1), totalTime(2)
00050 {
00051 }
00052
00053 enum EDistanceModel {
00054 DIST_NONE,
00055 DIST_LINEAR,
00056 DIST_QUADRATIC,
00057 };
00058
00059 float frequency;
00060 float amplitude;
00061 float angleTheta;
00062 float anglePhi;
00063 float dispersionTheta;
00064 float dispersionPhi;
00065 float timeFullAmplitude;
00066 float totalTime;
00067
00069 void setAngles(const osg::Vec3f & dir);
00071 void setAnglesRandom();
00072
00073 EDistanceModel distanceModel;
00074
00075 };
00076
00077
00082 class PVLE_EXPORT CameraShake : public osg::Node {
00083 public:
00084 META_Node(PVLE, CameraShake);
00085
00086 CameraShake();
00087 CameraShake(const CameraShakeParams & params);
00088 CameraShake(const CameraShake & v, const osg::CopyOp& copyop);
00089
00092 inline void addCamera(osg::Camera * pCamera) { vCameras.push_back(CameraData(pCamera)); }
00093
00095 inline bool ended() const { return curTime >= params.totalTime; }
00096 inline bool autoDelete() const { return ended(); }
00097
00098 protected:
00099 friend class CameraShakeUpdateCallback;
00100 virtual ~CameraShake();
00101
00102 CameraShakeParams params;
00103 float curTime;
00104 unsigned int curNumHalfOscillation;
00105
00107 class CameraData {
00108 public:
00109 CameraData(osg::Camera * pCamera) : pCamera(pCamera) {}
00110 osg::observer_ptr<osg::Camera> pCamera;
00111 osg::Vec3f curOffset;
00112 };
00113 std::vector<CameraData> vCameras;
00114
00115 void updateCameras(const osg::Vec3f & pos);
00116 void setCamera(CameraData & cameraData, const osg::Vec3f & newOffset);
00117
00119 inline float timedAmplitude() {
00120 if (curTime <= params.timeFullAmplitude) return params.amplitude;
00121 if (ended()) return 0;
00122 return (1 - (curTime - params.timeFullAmplitude) / (params.totalTime - params.timeFullAmplitude)) * params.amplitude;
00123 }
00124 };
00125
00126
00127 #endif // _3D_CAMERA_SHAKE_H