Commits

Anonymous committed 640275c

Canvas does not create the texture anymore, added OgreVideoCanvas::(un)setVideoTexture() & OgreVideoTexture::resetVideo()

  • Participants
  • Parent commits 6c03673

Comments (0)

Files changed (6)

File OgreVideoCanvas/include/OgreVideoCanvas.h

 
     void buildCanvas(SceneNode*);
     void nextFrame();
+    void pauseVideo();
+    void setVideoTexture(OgreVideoTexture*);
+    void unsetVideoTexture();
 
 protected:
     void _initVideoTexture(){};

File OgreVideoCanvas/include/OgreVideoTexture.h

     ~OgreVideoTexture(void);
     Ogre::String getMaterialName() const { return mVideoMaterial->getName();};
     void nextFrame();
+    void resetVideo();
 
 protected:
     void _init();
 protected:
     Ogre::String mVideoFileName, mVideoBaseName;
     Ogre::String mTextureName, mMaterialName;
-    CvCapture *mCvCapture;
-    IplImage *mCurrentVideoFrame;
     Ogre::TexturePtr mVideoTexture;
     Ogre::MaterialPtr mVideoMaterial;
     Ogre::Timer mTimeSinceLastUpdate;
+
+    CvCapture *mCvCapture;
+    IplImage *mCurrentVideoFrame;
+
     int mFrameCount, mCurrentFrameIndex;
     Ogre::Timer mTimer;
     Ogre::Log *mLog;

File OgreVideoCanvas/src/OgreVideoCanvas.cpp

     mCanvasNode->yaw(Degree(180.0));
     mCanvasNode->roll(Degree(180.0));
 
-    mVideoTexture = new OgreVideoTexture(mVideoFileName);
-    mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
-    
+     mCanvas->setMaterialName(0, "VideoCanvas/NoVideo");
 }
-//--------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
 void OgreVideoCanvas::nextFrame()
 {
-    mVideoTexture->nextFrame();
+    if (mVideoTexture)
+        mVideoTexture->nextFrame();
 }
-//--------------------------------------------------------------------------------
+//------------------------------------------------------------------------------
+void OgreVideoCanvas::setVideoTexture(OgreVideoTexture *_videoTexture)
+{
+    if (_videoTexture && _videoTexture != mVideoTexture)
+    {
+        mVideoTexture = _videoTexture;
+        mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
+    }
+}
+//------------------------------------------------------------------------------
+void OgreVideoCanvas::unsetVideoTexture()
+{
+    mVideoTexture = NULL;
+    mCanvas->setMaterialName(0, "VideoCanvas/NoVideo");
+}
+//------------------------------------------------------------------------------

File OgreVideoCanvas/src/OgreVideoTexture.cpp

     }
 }
 //------------------------------------------------------------------------------
+void OgreVideoTexture::resetVideo()
+{
+    _reinitCapture();
+}
+//------------------------------------------------------------------------------
 void OgreVideoTexture::_createTextureFromCapture(CvCapture *_capture)
 {
 

File media/VideoCanvas.material

+material VideoCanvas/NoVideo
+{
+
+	technique
+	{
+		pass
+		{
+
+      ambient 0.7 0.7 0.7
+      diffuse 0.5 0.5 0.5
+      //specular 0.3 0.3 0.3 15.0
+      //emissive 0.0 0.0 0.0
+		}
+	}
+}
+
+
+material VideoCanvas/OgreLogo
+{
+	technique
+	{
+		pass
+		{
+			ambient 0.8 0.8 0.8
+
+			texture_unit
+			{
+				texture ogrelogo.png
+			}
+		}
+	}
+}
+

File ogre-testscene/ogre-testscene.cpp

 class TutorialFrameListener : public ExampleFrameListener
 {
 public:
-    TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr
-                          , SceneNode *canvasNode
-                          , OgreVideoCanvas *_videoCanvas
-                          , OgreVideoCanvas *_videoCanvas2)
+    TutorialFrameListener( RenderWindow* win
+                         , Camera* cam
+                         , SceneManager *sceneMgr
+                         , SceneNode *_canvasNode
+                         , SceneNode *_canvasNode2
+                         , OgreVideoCanvas *_videoCanvas
+                         , OgreVideoCanvas *_videoCanvas2)
 		: ExampleFrameListener(win, cam, false, false)
 	{
 		// key and mouse state tracking
 		mRotate = 0.13;
 		mMoveSpeed = 500;
 
-		mCanvasNode = canvasNode;
+        mCanvasNode2 = _canvasNode2;
+		mCanvasNode = _canvasNode;
         mVideoCanvas = _videoCanvas;
         mVideoCanvas2 = _videoCanvas2;
 	}
 
 	bool frameStarted(const FrameEvent &evt)
 	{
-        //mCanvasNode->roll(Degree(1.0) * evt.timeSinceLastFrame * 100);
+        mCanvasNode->roll(Degree(1.0) * evt.timeSinceLastFrame * 100);
+        mCanvasNode2->roll(-Degree(1.0) * evt.timeSinceLastFrame * 100);
+
         mVideoCanvas->nextFrame();
         mVideoCanvas2->nextFrame();
 
 	Real mMove;            // The movement constant
 	SceneManager *mSceneMgr;   // The current SceneManager
 	SceneNode *mCamNode;   // The SceneNode the camera is currently attached to
-    SceneNode *mCanvasNode;
+    SceneNode *mCanvasNode, *mCanvasNode2;
     OgreVideoCanvas *mVideoCanvas, *mVideoCanvas2;
 	
 };
         mCanvasNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Canvas Node", Vector3(0, 100, 0));       
         mVideoCanvas = new OgreVideoCanvas("../media/videos/liege.avi", mSceneMgr);
         mVideoCanvas->buildCanvas(mCanvasNode);
-
+        mVideoTexture = new OgreVideoTexture("../media/videos/liege.avi");
+        mVideoCanvas->setVideoTexture(mVideoTexture);
 
         mCanvasNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Canvas Node2", Vector3(700, 100, 0));       
         mVideoCanvas2 = new OgreVideoCanvas("../media/videos/indochine.avi", mSceneMgr);
         mVideoCanvas2->buildCanvas(mCanvasNode2);
+        mVideoTexture2 = new OgreVideoTexture("../media/videos/indochine.avi");
+        mVideoCanvas2->setVideoTexture(mVideoTexture2);
+
 	}
 
 
 		// Create the FrameListener
 		mFrameListener = 
             new TutorialFrameListener(mWindow, mCamera, mSceneMgr
-                                    , mCanvasNode, mVideoCanvas, mVideoCanvas2);
+                                    , mCanvasNode, mCanvasNode2
+                                    , mVideoCanvas, mVideoCanvas2);
 		mRoot->addFrameListener(mFrameListener);
 	}
 
     //std::map<String, OgreVideoCanvas*> mVideoCanvases;
     OgreVideoCanvas *mVideoCanvas;
     OgreVideoCanvas *mVideoCanvas2;
+    OgreVideoTexture *mVideoTexture, *mVideoTexture2;
 };