15 #include <osg/LightSource>
17 #include <osg/MatrixTransform>
18 #include <osg/Projection>
19 #include <osg/Version>
20 #include <osgShadow/ShadowedScene>
23 #include <osg/PositionAttitudeTransform>
24 #include <osg/ImageStream>
25 #include <osgDB/ReadFile>
26 #include <osgGA/StateSetManipulator>
27 #include <osgViewer/ViewerEventHandlers>
28 #include <osgViewer/Viewer>
30 #include <osg/ShapeDrawable>
32 #define VLC_PLUGIN_PATH "G://umasoft//vtp-src//vlc//plugins//"
68 void SetOsgNode(osg::Node *n);
78 void SetOsgTransform(osg::MatrixTransform *xform) { m_pNode = m_pTransform = xform; }
121 void Scale(
float factor);
123 void Scale3(
float x,
float y,
float z);
135 osg::MatrixTransform *m_pTransform;
146 osg::ref_ptr<osg::Texture2D> m_pTexture;
162 void EnableMultiTexture(osg::Node *node,
vtMultiTexture *mt,
bool bEnable);
167 FSphere GetGlobalBoundSphere(osg::Node *node);
168 bool ContainsParticleSystem(osg::Node *node);
170 void SetEnabled(osg::Node *node,
bool bOn);
171 bool GetEnabled(osg::Node *node);
172 bool NodeIsEnabled(osg::Node *node);
177 void vtLogGraph(osg::Node *node,
bool bExtents =
false,
bool bRefCounts =
false,
int indent=0);
178 void WriteDotFile(osg::Group *node,
const char *filename);
186 osg::Node *
vtLoadModel(
const char *filename,
bool bAllowCache =
true,
187 bool bDisableMipmaps =
false);
188 bool vtSaveModel(osg::Node *node,
const char *filename);
189 void SetLoadModelCallback(osg::Node *callback(osg::Transform *input));
190 extern bool g_bDisableMipmaps;
197 typedef osg::ref_ptr<osg::Node> NodePtr;
207 typedef osg::ref_ptr<vtGroup> vtGroupPtr;
208 typedef osg::ref_ptr<osg::Group> GroupPtr;
219 typedef osg::ref_ptr<vtTransform> vtTransformPtr;
230 void SetFog(
bool bOn,
float start = 0,
float end = 10000,
const RGBf &color = s_white, osg::Fog::Mode eType = osg::Fog::LINEAR);
233 osg::ref_ptr<osg::StateSet> m_pFogStateSet;
234 osg::ref_ptr<osg::Fog> m_pFog;
236 typedef osg::ref_ptr<vtFog> vtFogPtr;
251 vtShadow(
const int ShadowTextureUnit,
int LightNumber);
258 void AddAdditionalTerrainTextureUnit(
const uint Unit,
const uint Mode);
259 void RemoveAdditionalTerrainTextureUnit(
const uint Unit);
260 void RemoveAllAdditionalTerrainTextureUnits();
267 bool GetRecalculateEveryFrame()
const;
269 void SetShadowSphereRadius(
const float ShadowSphereRadius);
271 void AddLodGridToIgnore(
vtLodGrid* pLodGrid);
272 void ForceShadowUpdate();
274 void SetDebugHUD(
vtGroup *pGroup);
277 const int m_ShadowTextureUnit;
278 const int m_LightNumber;
280 typedef osg::ref_ptr<vtShadow> vtShadowPtr;
295 void SetDiffuse(
const RGBf &color);
296 RGBf GetDiffuse()
const;
297 void SetAmbient(
const RGBf &color);
298 RGBf GetAmbient()
const;
299 void SetSpecular(
const RGBf &color);
300 RGBf GetSpecular()
const;
324 void CloneFromGeode(
const vtGeode *rhs);
356 void SetMeshMatIndex(
vtMesh *pMesh,
int iMatIdx);
359 osg::ref_ptr<const vtMaterialArray> m_pMaterialArray;
366 typedef osg::ref_ptr<vtGeode> vtGeodePtr;
377 m_pGeode = pContained;
382 typedef osg::ref_ptr<vtMovGeode> vtMovGeodePtr;
446 typedef osg::ref_ptr<vtCamera> vtCameraPtr;
474 enum Operation { SIN };
476 virtual void operator() ( osg::Uniform* uniform, osg::NodeVisitor* nv )
478 float angle = 2.0 * nv->getFrameStamp()->getSimulationTime();
479 float sine = sinf( angle );
481 case SIN : uniform->set( sine );
break;
485 Operation _operation;
489 osg::Drawable*
viewing_frustum(
double near_val,
double far_val,
double fov_val);
500 static void* lockFunc(
void* data,
void** p_pixels )
503 *p_pixels = (
void*)stream->data();
507 static void unlockFunc(
void* data,
void*
id,
void*
const* p_pixels )
513 static void displayFunc(
void* data,
void*
id )
517 static void videoEndFunc(
const libvlc_event_t*,
void* data )
520 stream->_status = INVALID;
524 : osg::ImageStream(), _vlcMedia(0)
528 const char* vlc_args[] = {
530 "--data-path="VLC_PLUGIN_PATH
532 _vlc = libvlc_new(
sizeof(vlc_args)/
sizeof(vlc_args[0]), vlc_args );
535 _vlc = libvlc_new(
sizeof(vlc_argv)/
sizeof(vlc_argv[0]), vlc_argv );
536 _vlcPlayer = libvlc_media_player_new( _vlc );
538 libvlc_event_attach( libvlc_media_player_event_manager(_vlcPlayer), libvlc_MediaPlayerStopped,
539 &VLCImageStream::videoEndFunc,
this );
544 : osg::ImageStream(copy, op), _vlc(copy._vlc), _vlcMedia(copy._vlcMedia),
545 _vlcPlayer(copy._vlcPlayer) {}
560 void open( const std::
string& file,
bool needPlay=true )
562 _vlcMedia = libvlc_media_new_path( _vlc, file.c_str() );
563 libvlc_media_player_set_media( _vlcPlayer, _vlcMedia );
564 libvlc_video_set_callbacks( _vlcPlayer, &VLCImageStream::lockFunc, &VLCImageStream::unlockFunc,
565 &VLCImageStream::displayFunc,
this );
567 unsigned int width = 512, height = 512;
568 libvlc_media_track_info_t* info = NULL;
569 int numTracks = libvlc_media_get_tracks_info( _vlcMedia, &info );
570 for (
int i=0; i<numTracks; ++i )
572 if(info[i].i_type == libvlc_track_video)
574 width = info[i].u.video.i_width;
575 height = info[i].u.video.i_height;
578 libvlc_video_set_format( _vlcPlayer,
"RV32", width, height, width*4 );
580 allocateImage( width, height, 1, GL_RGBA, GL_UNSIGNED_BYTE );
581 if ( needPlay ) play();
586 if ( _status==PAUSED )
588 libvlc_media_player_set_pause( _vlcPlayer,
false );
590 else if ( _status!=PLAYING )
592 libvlc_media_player_play( _vlcPlayer );
599 libvlc_media_player_set_pause( _vlcPlayer,
true );
603 virtual void rewind()
605 libvlc_media_player_stop( _vlcPlayer );
606 libvlc_media_player_set_time( _vlcPlayer, 0 );
607 libvlc_media_player_next_frame( _vlcPlayer );
611 virtual void quit(
bool waitForThreadToExit=
true )
613 libvlc_media_player_stop( _vlcPlayer );
614 libvlc_media_player_release( _vlcPlayer );
618 virtual void setReferenceTime(
double time ) { libvlc_media_player_set_time(_vlcPlayer, (
int)time); }
619 virtual double getReferenceTime()
const {
return (
int)libvlc_media_player_get_time(_vlcPlayer); }
621 virtual void setTimeMultiplier(
double m ) { libvlc_video_set_scale(_vlcPlayer, m); }
622 virtual double getTimeMultiplier()
const {
return libvlc_video_get_scale(_vlcPlayer); }
624 virtual void setVolume(
float vol ) { libvlc_audio_set_volume(_vlcPlayer, (
int)vol); }
625 virtual float getVolume()
const {
return (
int)libvlc_audio_get_volume(_vlcPlayer); }
630 if ( _status!=INVALID )
632 libvlc_media_player_stop( _vlcPlayer );
633 libvlc_media_player_release( _vlcPlayer );
635 libvlc_release( _vlc );
638 libvlc_instance_t* _vlc;
639 libvlc_media_t* _vlcMedia;
640 libvlc_media_player_t* _vlcPlayer;
643 osg::Node*
createVideoQuad(
const osg::Vec3& corner,
const std::string& file,
double near,
double far,
double fov );
644 void AddCylinderBetweenPoints(osg::Vec3 StartPoint, osg::Vec3 EndPoint,
float radius, osg::Vec4 CylinderColor,osg::PositionAttitudeTransform *pAddToThisGroup);
658 bool positionchanged;
662 double rotatex,rotatey;
665 osg::ref_ptr<osg::PositionAttitudeTransform> frustum;
666 osg::ref_ptr<osg::PositionAttitudeTransform> model;
667 osg::PositionAttitudeTransform *video_data;
671 std::vector< osg::ref_ptr<osg::PositionAttitudeTransform> > camline;
680 positionchanged=
false;
690 void calculate_viewfrustum();
704 _anglex=cam->rotatex;
705 _height=cam->height_val;
708 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
728 bool positionchanged;
732 osg::PositionAttitudeTransform *model;
743 positionchanged=
false;
755 models3dupdate=model;
758 virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
779 vtHUD(
bool bPixelCoords =
true);
781 void SetWindowSize(
int w,
int h);
782 osg::Group *GetContainer() {
return modelview_abs.get(); }
785 osg::ref_ptr<osg::MatrixTransform> modelview_abs;
802 virtual osg::Object* cloneType()
const {
return new OsgDynMesh; }
803 virtual osg::Object* clone(
const osg::CopyOp &foo)
const {
return new OsgDynMesh; }
804 virtual bool isSameKindAs(
const osg::Object* obj)
const {
return dynamic_cast<const OsgDynMesh*
>(obj)!=NULL; }
805 virtual const char* className()
const {
return "OsgDynMesh"; }
808 virtual osg::BoundingBox computeBound()
const;
809 virtual void drawImplementation(osg::RenderInfo& renderInfo)
const;
812 osg::State *m_pDrawState;
821 #define VT_AllVisible 2
855 const float fTolerance = 0.0f)
const;
864 virtual void DoRender() = 0;
865 virtual void DoCalcBoundBox(
FBox3 &box) = 0;
866 virtual void DoCull(
const vtCamera *pCam) = 0;
874 typedef osg::ref_ptr<vtDynGeom> vtDynGeomPtr;
888 bool operator < (
const vtHit &i)
const {
return distance < i.distance; }
894 typedef std::vector<vtHit> vtHitList;
896 vtHitList &hitlist,
bool bLocalCoords =
false,
bool bNativeNodes =
true);
937 #endif // VTOSG_NODEH