Anonymous avatar Anonymous committed 8ea9fa8

OgreVideoCanvas (refactored) with specific OgreVideoTexture

Comments (0)

Files changed (6)

ogre-movingcube/OgreVideoCanvas.cpp

 #include "OgreVideoCanvas.h"
 
-OgreVideoCanvas::OgreVideoCanvas(void)
+//------------------------------------------------------------------------------
+OgreVideoCanvas::OgreVideoCanvas(const String &_filename, SceneManager *_sceneMgr)
+    :mSceneMgr(_sceneMgr)
+    ,mVideoFileName(_filename)
+    ,mCanvas(NULL)
+    ,mVideoTexture(NULL)
+    ,mCanvasNode(NULL)
+    ,mWidth(640)
+    ,mHeight(480)
+    ,mTextureSize(1024)
 {
 }
-
+//------------------------------------------------------------------------------
 OgreVideoCanvas::~OgreVideoCanvas(void)
 {
 }
+//------------------------------------------------------------------------------
+void OgreVideoCanvas::buildCanvas(SceneNode *_parentNode)
+{
+    
+    float uMin = 0, vMin = 0;
+    float uMax = float(mWidth)  / mTextureSize;
+    float vMax = float(mHeight) / mTextureSize;
+
+    mCanvas = mSceneMgr->createManualObject("Video Canvas " + mVideoFileName);
+    mCanvas->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP);
+
+    mCanvas->position(-mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMin, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position( mWidth/2,  mHeight/2, 0);   mCanvas->textureCoord(uMax, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position(-mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMin, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+    mCanvas->position( mWidth/2, -mHeight/2, 0);   mCanvas->textureCoord(uMax, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
+
+    mCanvas->end();
+
+    mCanvasNode = _parentNode->createChildSceneNode("Canvas Node " + mVideoFileName);
+    mCanvasNode ->attachObject(mCanvas);
+    mCanvasNode->yaw(Degree(180.0));
+    mCanvasNode->roll(Degree(180.0));
+
+    mVideoTexture = new OgreVideoTexture(mVideoFileName);
+    mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
+    
+}
+//--------------------------------------------------------------------------------
+void OgreVideoCanvas::nextFrame()
+{
+    mVideoTexture->nextFrame();
+}
+//--------------------------------------------------------------------------------

ogre-movingcube/OgreVideoCanvas.h

 #pragma once
 
+#include <Ogre.h>
+#include "OgreVideoTexture.h"
+
+using namespace Ogre;
+
 class OgreVideoCanvas
 {
 public:
-    OgreVideoCanvas(void);
+    OgreVideoCanvas(const String&, SceneManager*);
     ~OgreVideoCanvas(void);
+
+    void buildCanvas(SceneNode*);
+    void nextFrame();
+
+protected:
+    void _initVideoTexture(){};
+
+protected:
+    SceneManager *mSceneMgr;
+    String mVideoFileName;
+    SceneNode *mCanvasNode;
+    ManualObject *mCanvas;
+    OgreVideoTexture *mVideoTexture;
+    int mWidth, mHeight, mTextureSize;
+
 };

ogre-movingcube/OgreVideoTexture.cpp

     ,mCurrentVideoFrame(NULL)
     ,mCurrentFrameIndex(0)
 {
-    mLog = Ogre::LogManager::getSingletonPtr()->createLog("OgreVideoTexture.log");
+    mLog = Ogre::LogManager::getSingletonPtr()->createLog("OgreVideoTexture_"+_filename+".log");
+    mMaterialName = "Video Material "+ mVideoFileName;
+    mTextureName = "Video Texture " + mVideoFileName;
     _init();
 }
 //------------------------------------------------------------------------------
 
     _updateTextureFromImage(mCurrentVideoFrame);
 
-    mMaterialName = "Video Texture "+ mVideoFileName;
+
     mTimeSinceLastUpdate.reset();
 
      
     w = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_WIDTH);
     h = cvGetCaptureProperty(_capture, CV_CAP_PROP_FRAME_HEIGHT);
 
+    Ogre::TextureManager *TM = Ogre::TextureManager::getSingletonPtr();
 
     // Create the texture
     mVideoTexture = Ogre::TextureManager::getSingleton().createManual(
-        "DynamicTexture", // name
+        mTextureName, // name
         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
         Ogre::TEX_TYPE_2D,      // type
         1024, 1024,         // width & height
         mMaterialName, // name
         Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
 
-    mVideoMaterial->getTechnique(0)->getPass(0)->createTextureUnitState("DynamicTexture");
+    mVideoMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mTextureName);
     //mVideoMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
 
 }

ogre-movingcube/OgreVideoTexture.h

     IplImage *mCurrentVideoFrame;
     Ogre::TexturePtr mVideoTexture;
     Ogre::MaterialPtr mVideoMaterial;
-    Ogre::String mMaterialName;
+    Ogre::String mTextureName, mMaterialName;
     Ogre::Timer mTimeSinceLastUpdate;
     int mFrameCount, mCurrentFrameIndex;
     Ogre::Log *mLog;

ogre-movingcube/ogre-movingcube.cpp

 
 
-#include "OgreVideoTexture.h"
+#include <map>
+#include <boost/foreach.hpp>
+
+#include "OgreVideoCanvas.h"
+//#include "OgreVideoTexture.h"
 #include "ExampleApplication.h"
 
 
 class TutorialFrameListener : public ExampleFrameListener
 {
 public:
-    TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr, SceneNode *canvasNode, OgreVideoTexture *_videoTexture)
+    TutorialFrameListener(RenderWindow* win, Camera* cam, SceneManager *sceneMgr
+                          , SceneNode *canvasNode
+                          , OgreVideoCanvas *_videoCanvas
+                          , OgreVideoCanvas *_videoCanvas2)
 		: ExampleFrameListener(win, cam, false, false)
 	{
 		// key and mouse state tracking
 		mMoveSpeed = 500;
 
 		mCanvasNode = canvasNode;
-        mVideoTexture = _videoTexture;
+        mVideoCanvas = _videoCanvas;
+        mVideoCanvas2 = _videoCanvas2;
 	}
 
-	//// Overriding the default processUnbufferedKeyInput so the key updates we define
-	//// later on work as intended.
-	//bool processUnbufferedKeyInput(const FrameEvent& evt)
-	//{
-	//	return true;
-	//}
-
-	//// Overriding the default processUnbufferedMouseInput so the Mouse updates we define
-	//// later on work as intended. 
-	//bool processUnbufferedMouseInput(const FrameEvent& evt)
-	//{
-	//	return true;
-	//}
 
 	bool frameStarted(const FrameEvent &evt)
 	{
-        mCanvasNode->roll(Degree(1.0) * evt.timeSinceLastFrame * 100);
-
-        mVideoTexture->nextFrame();
-
+        //mCanvasNode->roll(Degree(1.0) * evt.timeSinceLastFrame * 100);
+        mVideoCanvas->nextFrame();
+        mVideoCanvas2->nextFrame();
 
 		if(mKeyboard->isKeyDown(OIS::KC_ESCAPE))
 			return false;
 	SceneManager *mSceneMgr;   // The current SceneManager
 	SceneNode *mCamNode;   // The SceneNode the camera is currently attached to
     SceneNode *mCanvasNode;
-    OgreVideoTexture *mVideoTexture;
-	char *mBuffer;
+    OgreVideoCanvas *mVideoCanvas, *mVideoCanvas2;
+	
 };
 
 class TutorialApplication : public ExampleApplication
         
 		mSceneMgr->setAmbientLight(ColourValue(0.25, 0.25, 0.25));
 
-        float uMin = 0, vMin = 0;
-        float uMax = 640.0/1024, vMax = 480.0/1024;
-
-        mCanvas = mSceneMgr->createManualObject("video canvas");
-        mCanvas->begin("BaseWhiteNoLighting", RenderOperation::OT_TRIANGLE_STRIP);
-   
-        /*mCanvas->position(-0.65,  0.5, 0);   mCanvas->textureCoord(uMin, vMax);     mCanvas->normal(Ogre::Vector3::UNIT_Y);
-        mCanvas->position( 0.65,  0.5, 0);   mCanvas->textureCoord(uMax, vMax);     mCanvas->normal(Ogre::Vector3::UNIT_Y);
-        mCanvas->position(-0.65, -0.5, 0);   mCanvas->textureCoord(uMin, vMin);     mCanvas->normal(Ogre::Vector3::UNIT_Y);
-        mCanvas->position( 0.65, -0.5, 0);   mCanvas->textureCoord(uMax, vMin);     mCanvas->normal(Ogre::Vector3::UNIT_Y);*/
-   
-        mCanvas->position(-320,  240, 0);   mCanvas->textureCoord(uMin, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-        mCanvas->position( 320,  240, 0);   mCanvas->textureCoord(uMax, vMax);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-        mCanvas->position(-320, -240, 0);   mCanvas->textureCoord(uMin, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-        mCanvas->position( 320, -240, 0);   mCanvas->textureCoord(uMax, vMin);     mCanvas->normal(Ogre::Vector3::NEGATIVE_UNIT_Z);
-
-        mCanvas->end();
-
-
-
-        SceneNode *node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Canvas Node", Vector3(0, 100, 0));
-        node->attachObject(mCanvas);
-        //node->scale(100, 100, 100);
-        node->yaw(Degree(180.0));
-        node->roll(Degree(180.0));
-        mCanvasNode = node;
-
-
-
 		Light *light = mSceneMgr->createLight("Light1");
 		light->setType(Light::LT_POINT);
 		light->setPosition(Vector3(0, 300, 600));
 
 		// Create the scene node
 		SceneNode *yawnode = mSceneMgr->getRootSceneNode()->createChildSceneNode("YawCamNode1");
-		node = yawnode->createChildSceneNode("CamNode1", Vector3(0, 100, 1000));
+        Ogre::SceneNode *node = yawnode->createChildSceneNode("CamNode1", Vector3(0, 100, 1000));
 		node->attachObject(mCamera);
 
 
-        mVideoTexture = new OgreVideoTexture("liege.avi");
-        mCanvas->setMaterialName(0, mVideoTexture->getMaterialName());
-        
+        mCanvasNode = mSceneMgr->getRootSceneNode()->createChildSceneNode("Canvas Node", Vector3(0, 100, 0));       
+        mVideoCanvas = new OgreVideoCanvas("liege.avi", mSceneMgr);
+        mVideoCanvas->buildCanvas(mCanvasNode);
+
+
+        mCanvasNode2 = mSceneMgr->getRootSceneNode()->createChildSceneNode("Canvas Node2", Vector3(700, 100, 0));       
+        mVideoCanvas2 = new OgreVideoCanvas("indochine.avi", mSceneMgr);
+        mVideoCanvas2->buildCanvas(mCanvasNode2);
 	}
 
 
 
-
-
-
 	void createFrameListener(void)
 	{
 		// Create the FrameListener
-		mFrameListener = new TutorialFrameListener(mWindow, mCamera, mSceneMgr, mCanvasNode, mVideoTexture);
+		mFrameListener = 
+            new TutorialFrameListener(mWindow, mCamera, mSceneMgr
+                                    , mCanvasNode, mVideoCanvas, mVideoCanvas2);
 		mRoot->addFrameListener(mFrameListener);
 	}
 
 protected:
-    SceneNode *mCanvasNode;
-    ManualObject *mCanvas;
-    OgreVideoTexture *mVideoTexture;
+    SceneNode *mCanvasNode, *mCanvasNode2;
+    //typedef VideoCanvasItem std::pair<String, OgreVideoCanvas*>;
+    //std::map<String, OgreVideoCanvas*> mVideoCanvases;
+    OgreVideoCanvas *mVideoCanvas;
+    OgreVideoCanvas *mVideoCanvas2;
 };
 
+
+
+
+
+
+
+
+
+
+
+
+
+
 #if OGRE_PLATFORM == PLATFORM_WIN32 || OGRE_PLATFORM == OGRE_PLATFORM_WIN32
 #define WIN32_LEAN_AND_MEAN
 #include "windows.h"
 	}
 
 	return 0;
-}
+}

ogre-movingcube/ogre-movingcube.vcproj

 				>
 			</File>
 			<File
+				RelativePath=".\OgreVideoCanvas.cpp"
+				>
+			</File>
+			<File
 				RelativePath=".\OgreVideoTexture.cpp"
 				>
 			</File>
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}"
 			>
 			<File
+				RelativePath=".\OgreVideoCanvas.h"
+				>
+			</File>
+			<File
 				RelativePath=".\OgreVideoTexture.h"
 				>
 			</File>
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.