Hi Tran,
It is probably best for you to upgrade to OSG-2.2 which I'm about to
tag. It has an osgviewerMFC example and well as osgcompositeviewer
example that may well be able to help your out.
Robert.
On 10/4/07, Tran Thanh Hiep <[EMAIL PROTECTED]> wrote:
>
> Thank! Robert
> I 'm using osg1.2 and os windowxp. I develop my project on Visual
> C++.Net-2003(MFC).
> I have using 4 same class follow to render scene:
>
> class CMyView : public CView
> {
> DECLARE_DYNCREATE(CMyView)
> protected:
> CMyView(); // protected constructor used by dynamic creation
> virtual ~CMyView();
> void DoFrame();
> // Attributes
> osg::ref_ptr<Producer::KeyboardMouse> m_KBM;
> // Callback
> osg::ref_ptr<MFCKeyboardMouseCallback> m_KBMCallback;
> // We will use Producer render surface
> //osg::ref_ptr<Producer::RenderSurface> m_RenderSurface;
> Producer::RenderSurface *m_RenderSurface;
> // THE scene
> //osg::ref_ptr<osgUtil::SceneView> m_SceneView;
> osgUtil::SceneView * m_SceneView;
> // Database Pager
> osgDB:atabasePager* m_DatabasePager;
> // Tell is the render surface has been realized
> BOOL m_bRenderSurfaceRealized;
> // Tell is the model was loaded
> BOOL m_bModelLoaded;
> // Start
> osg::Timer_t m_StartTick;
> // Frame Number
> unsigned int m_uiFrameNum;
> BOOL m_bGotFocus;
> public:
> CMultiSplitterSampleDoc *GetDocument() const
> {
> ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CMultiSplitterSampleDoc)));
> return (CMultiSplitterSampleDoc*) m_pDocument;
> }
> virtual void OnDraw(CDC* pDC); // overridden to draw this view
> #ifdef _DEBUG
> virtual void AssertValid() const;
> virtual void Dump(CDumpContext& dc) const;
> #endif
> virtual void OnUpdate(CView *pSender,LPARAM lHint,CObject *pHint);
> virtual void OnInitialUpdate();
> protected:
> DECLARE_MESSAGE_MAP()
> afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
> afx_msg void OnShowWindow(BOOL bShow,UINT nStatus);
> afx_msg BOOL OnEraseBkgnd(CDC* pDC);
> afx_msg void OnSize(UINT nType, int cx, int cy);
> afx_msg void OnPaint();
> afx_msg void OnMouseMove(UINT nFlags, CPoint point);
> afx_msg LRESULT OnMouseLeaveMessage(WPARAM wp, LPARAM lp);
> afx_msg LRESULT OnStartRendering(WPARAM,LPARAM);
> };
>
>
> and with KeyboardMouseCallback i use class follow:
>
>
>
> // CMyView view
> class MFCKeyboardMouseCallback : public Producer::KeyboardMouseCallback
> {
> public:
> MFCKeyboardMouseCallback(osgUtil::SceneView* sceneView)
> :
> Producer::KeyboardMouseCallback(),
> _mx(0.0f),
> _my(0.0f),
> _mbutton(0),
> _done(false),
>
> _trackBall(new Producer::Trackball),
> _sceneView(sceneView)
> {
> resetTrackball();
> _mouseMovingOnPreviousRelease = false;
> }
> //friend osg::Node * __classFriend::CreateBoundBox(float
> s,osg::Vec3 pos);
> void home()
> {
> resetTrackball();
> _mouseMovingOnPreviousRelease = false;
> }
> virtual void keyPress( Producer::KeyCharacter key)
> {
> if (key==' ') resetTrackball();
> }
> virtual void mouseMotion( float mx, float my )
> {
> _mx = mx;
> _my = my;
> }
> virtual void buttonPress( float mx, float my, unsigned int mbutton )
> {
> _mx = mx;
> _my = my;
> _mbutton |= (1<<(mbutton-1));
>
> _mx_buttonPress = _mx;
> _my_buttonPress = _my;
> }
> virtual void buttonRelease( float mx, float my, unsigned int mbutton )
> {
> _mx = mx;
> _my = my;
> _mbutton &= ~(1<<(mbutton-1));
>
> if (_mx==_mx_buttonPress && _my_buttonPress==_my)
> {
> if (!_mouseMovingOnPreviousRelease)
> {
> // button press and release without moving so assume this
> means
> // the users wants to pick.
> pick(mx,my);
> }
> _mouseMovingOnPreviousRelease = false;
> }
> else
> {
> _mouseMovingOnPreviousRelease = true;
> }
> }
> virtual void shutdown()
> {
> _done = true;
> }
> float mx() { return _mx; }
> float my() { return _my; }
> unsigned int mbutton() { return _mbutton; }
>
> void resetTrackball()
> {
> osg::Node* scene = _sceneView->getSceneData();
> if (scene)
> {
> const osg::BoundingSphere& bs = scene->getBound();
> _trackBall->reset();
> _trackBall->setOrientation( Producer::Trackball::Z_UP );
> _trackBall->setDistance(bs.radius()*2.0);
>
> _trackBall->translate(-bs.center().x(),-bs.center().y(),-bs.center().z());
> _trackBall->translate(-bs.center().x(),-bs.center().y(),0);
> }
> }
>
> osg::Matrixd getViewMatrix()
> {
> _trackBall->input( mx(), my(), mbutton() );
> return osg::Matrixd(_trackBall->getMatrix().ptr());
> }
> bool done(){ return _done; }
> void pick(float x, float y)
> {
> osg::Node* scene = _sceneView->getSceneData();
> if (scene)
> {
> int origX, origY, width, height;
>
> _sceneView->getViewport(origX,origY,width,height);
> // convert Produce's non dimensional x,y coords back into pixel
> coords.
> int winX = (int)((x+1.0f)*0.5f*(float)width);
> int winY = (int)((y+1.0f)*0.5f*(float)height);
> osg::Vec3 nearPoint, farPoint;
>
> _sceneView->projectWindowXYIntoObject(winX,winY,nearPoint,farPoint);
> // make a line segment
> osg::ref_ptr<osg::LineSegment> lineSegment = new
> osg::LineSegment(nearPoint,farPoint);
> // create the IntersectVisitor to do the line intersection
> traversals.
> osgUtil::IntersectVisitor intersector;
> intersector.addLineSegment(lineSegment.get());
>
> scene->accept(intersector);
>
> osgUtil::IntersectVisitor::HitList&
> hits=intersector.getHitList(lineSegment.get());
> if (!hits.empty())
> {
> // just take the first hit - nearest the eye point.
> osgUtil::Hit& hit = hits.front();
> /*
> osg::NodePath& nodePath = hit._nodePath;
> osg::Node* node =
> (nodePath.size()>=1)?nodePath[nodePath.size()-1]:0;
> osg::Group* parent =
> (nodePath.size()>=2)?dynamic_cast<osg::Group*>(nodePath[nodePath.size()-2]):0;
> osg::Matrix m=node->getWorldMatrices()[0];
> osg::Vec3 v44=m.getTrans();
> v44.z()+=node->computeBound().center().z();
> */
> //__classFriend *f_cf=new __classFriend();
>
> //scene->asGroup()->replaceChild(scene->asGroup()->getChild(0),f_cf->CreateBoundBox(node->getBound().radius()*1.5,/*node->computeBound().center()+*/v44));//createPoint(v1,v2,v3)
> }
>
> }
>
> }
>
> //friend class __classFriend;
> private:
> bool
> _mouseMovingOnPreviousRelease;
> float _mx, _my;
> float _mx_buttonPress,
> _my_buttonPress;
> unsigned int _mbutton;
> bool _done;
>
> osg::ref_ptr<Producer::Trackball> _trackBall;
> osg::ref_ptr<osgUtil::SceneView> _sceneView;
>
> };
>
> //UINT WM_OSGSTARTRENDERING =
> ::RegisterWindowMessage(_T("WM_OSGSTARTRENDERING"));
> class GetWorldMatrix : public osg::NodeVisitor
> {
> public:
> GetWorldMatrix():
>
> osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
>
> {
> }
>
> virtual void apply(osg::Node& node)
> {
> osg::NodePath p = this->getNodePath();
> mt=osg::computeWorldToLocal(p);
>
> //int i=mt(0,0);
> osgFX::Scribe* scribe =
> dynamic_cast<osgFX::Scribe*>(&node);
> if (scribe)
> {
>
> }
> else
> {
> traverse(node);
> }
> }
> virtual void apply(osg::Geode& node)
> {
> osg::NodePath p = this->getNodePath();
> osg::Matrix m=osg::computeWorldToLocal(p);
> //osg::Matrix m=osg::computeLocalToWorld(p);
> osg::Vec3 vcenter=node.computeBound().center();
>
> osg::Vec3 vt= m.getTrans();
> // node.getWorldMatrices();
>
> traverse(node);
> }
> osg::Matrix matrixTransform()
> {
> return mt;
> }
> osg::Matrix mt;
> };
> class CreateModelToSaveVisitor : public osg::NodeVisitor
> {
> public:
> CreateModelToSaveVisitor(osg::Vec3 vTemp,int i=0):
>
> osg::NodeVisitor(osg::NodeVisitor::TRAVERSE_ALL_CHILDREN)
>
> {
> rs=false;
> NowPoint=vTemp;
> iID=i;
> }
>
> virtual void apply(osg::Node& node)
> {
> osgFX::Scribe* scribe =
> dynamic_cast<osgFX::Scribe*>(&node);
> if (scribe)
> {
>
> }
> else
> {
> traverse(node);
> }
> }
> virtual void apply(osg::Geode& node)
> {
> osg::NodePath p = this->getNodePath();
> osg::Matrix m=osg::computeWorldToLocal(p);
> //osg::Matrix m=osg::computeLocalToWorld(p);
> osg::Vec3 vcenter=node.computeBound().center();
>
> osg::Vec3 vt= m.getTrans();
> // node.getWorldMatrices();
> for(unsigned int i=0;i<node.getNumDrawables();++i)
> {
> osg::Drawable* drawable = node.getDrawable(i);
> if (drawable)
> {
> osg::BoundingSphere b=drawable->getBound();
> osg::Geometry
> *pgeo=dynamic_cast<osg::Geometry*>(drawable);
> if(pgeo)
> {
>
> osg::Vec3Array
> *parray=dynamic_cast<osg::Vec3Array*>(pgeo->getVertexArray());
> float space=50.0;
> int u=parray->getNumElements();
> for(int id=0;id<u;id++)
> {
> osg::Vec3 p1=(*parray)[id];
> //p1.z()=0;
> //p1+=vcenter;
> b.center().z()=0;
> //osg::Vec3 v=p1*b.center();
> float a1=NowPoint.x()-p1.x()+vt.x();
> float a2=NowPoint.y()-p1.y()+vt.y();
> float a3=NowPoint.z()-p1.z()+vt.z();
> float distance;
> distance=sqrtf(a1*a1+a2*a2+a3*a3);
> if(distance<space)
> {
> rs=true;
> if((iID<=14)||((iID>=21)&&(iID<=25)))
> {
> p1.y()+=10;
> }
> else if((iID>=15)&&(iID<=20))
> p1.x()-=10;
> else if(iID>=26)
> p1.x()+=10;
> //AfxMessageBox("aaaa");
> //if(!this->getIntersection(iTemp,p1,pPs))
> p1.y()+=10;
>
> }
> (*parray)[id]=p1;
> }
> pgeo->setVertexArray(parray);
> }
> }
> }
>
> traverse(node);
> }
> bool kq()
> {
> return rs;
> }
> bool rs;
> int iID;
> osg::Vec3 NowPoint;
> };
>
>
>
>
>
> ----- Original Message ----
> From: Robert Osfield <[EMAIL PROTECTED]>
> To: OpenSceneGraph Users
> <[email protected]>
> Sent: Thursday, October 4, 2007 3:28:47 PM
> Subject: Re: [osg-users] how to configure camera to multi window
>
>
> Hi Tran,
>
> You'll have to explain more about what the problem is. A screenshot
> of what you are getting. Please also specify which version of the OSG
> your are using, what operating system, what graphics hardware, and
> what viewer classes you are using. Without this information no body
> has enough information to know what might be wrong and won't be able
> to help you.
>
> Robert.
>
> On 10/4/07, Tran Thanh Hiep <[EMAIL PROTECTED]> wrote:
> >
> > hi all!
> > I split my window to 4 paths and i want each window that will render 1
> face
> > of object.(front, left, right and perpactive). but when i debug each
> > rendered window doesn't display true. Could you help me to slove this?
> >
> > ________________________________
> > Check out the hottest 2008 models today at Yahoo! Autos.
> > _______________________________________________
> > osg-users mailing list
> > [email protected]
> >
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
> >
> >
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
> ________________________________
> Building a website is a piece of cake.
> Yahoo! Small Business gives you all the tools to get online.
> _______________________________________________
> osg-users mailing list
> [email protected]
> http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org
>
>
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org