OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

osgWidget and rotation


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [3rdparty]
View previous topic :: View next topic  
Author Message
lokida
User


Joined: 11 Sep 2009
Posts: 48

PostPosted: Tue Aug 28, 2012 9:05 am    Post subject:
osgWidget and rotation
Reply with quote

Hi,

I want to use an osgWidget to draw a compass. So, I need to use the rotation. The problem is that the origin of the osgWidget is at the bottom left and not at the center of the widget.

How can I specify the center of my widget (since set Origin only move the widget) in order to have a good rotation.

Thank you!
Back to top
View user's profile Send private message
Jeremy Moles
Guest





PostPosted: Tue Aug 28, 2012 1:38 pm    Post subject:
osgWidget and rotation
Reply with quote

On Tue, 2012-08-28 at 11:05 +0200, Miguel Lokida wrote:
Quote:
Hi,

I want to use an osgWidget to draw a compass. So, I need to use the rotation. The problem is that the origin of the osgWidget is at the bottom left and not at the center of the widget.

How can I specify the center of my widget (since set Origin only move the widget) in order to have a good rotation.

A Widget's origin should be relative to the Window it is parented in.
Rotations should occur properly in that respect, can you provide some
code that isn't behaving properly?

Quote:
Thank you!

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49609#49609










------------------
Post generated by Mail2Forum
Back to top
lokida
User


Joined: 11 Sep 2009
Posts: 48

PostPosted: Tue Aug 28, 2012 2:59 pm    Post subject:
Reply with quote

So i see what you mean. But how can I declare the position of my widget relative to the parented window ?

Here's the code I use:

Code:

const unsigned int MASK_2D = 0xF0000000;

// note: osgViewer::Viewer* ptrViewer;
// note: osg::ref_ptr<osg::Group> _rootScene;
// note: ptrViewer->setSceneData(_rootScene);

osgWidget::WindowManager* wm = new osgWidget::WindowManager(
   ptrViewer,
   ptrViewer->width(),
   ptrViewer->height(),
   MASK_2D,
   osgWidget::WindowManager::WM_PICK_DEBUG
         );

osgWidget::Window* box = new osgWidget::Box("HBOX", osgWidget::Box::VERTICAL, true);

osgWidget::Widget * testWidget = new osgWidget::Widget("test", 100.0f, 100.0f);
testWidget->setColor(1, 0, 0, 1.0);
box->addWidget(testWidget);

//box->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
//box->setAnchorVertical(osgWidget::Window::VA_TOP);

box->setVisibilityMode(osgWidget::Window::VM_ENTIRE);

wm->addChild(box);

// rotation
box->setRotate(45.0);

osg::Group*  group  = new osg::Group();
osg::Camera* camera = wm->createParentOrthoCamera();

_rootScene->addChild(camera);

wm->resizeAllWindows();
 


may be I am wrong with this code ?

Thanks !
Back to top
View user's profile Send private message
Jeremy Moles
Guest





PostPosted: Tue Aug 28, 2012 4:37 pm    Post subject:
osgWidget and rotation
Reply with quote

On Tue, 2012-08-28 at 16:59 +0200, Miguel Lokida wrote:
Quote:
So i see what you mean. But how can I declare the position of my widget relative to the parented window ?

Here's the code I use:

Code:

const unsigned int MASK_2D = 0xF0000000;

// note: osgViewer::Viewer* ptrViewer;
// note: osg::ref_ptr<osg::Group> _rootScene;
// note: ptrViewer->setSceneData(_rootScene);

osgWidget::WindowManager* wm = new osgWidget::WindowManager(
   ptrViewer,
   ptrViewer->width(),
   ptrViewer->height(),
   MASK_2D,
   osgWidget::WindowManager::WM_PICK_DEBUG
         );

osgWidget::Window* box = new osgWidget::Box("HBOX", osgWidget::Box::VERTICAL, true);

osgWidget::Widget * testWidget = new osgWidget::Widget("test", 100.0f, 100.0f);
testWidget->setColor(1, 0, 0, 1.0);
box->addWidget(testWidget);

//box->setAnchorHorizontal(osgWidget::Window::HA_RIGHT);
//box->setAnchorVertical(osgWidget::Window::VA_TOP);

box->setVisibilityMode(osgWidget::Window::VM_ENTIRE);

wm->addChild(box);

// rotation
box->setRotate(45.0);

osg::Group*  group  = new osg::Group();
osg::Camera* camera = wm->createParentOrthoCamera();

_rootScene->addChild(camera);

wm->resizeAllWindows();



may be I am wrong with this code ?

I've done some testing and you aren't really doing anything wrong here;
it is simply a weakness in osgWidget I never thought of. I'm not sure
how to best proceed, but you have at least two reasonable options:

1) An osgWidget::Window is a MatrixTransform, and an osgWidget::Widget
is just an osg::Geometry. You could attach an
osg::Drawable::UpdateCallback to your widget, but you'd need to do some
fancy calculations to get it to rotate in place. I tried quickly doing
this, but couldn't get the math right in the few minutes I had to test
it... I've attached this code, but you'll need to "fix" it to make it
work.

2) Create one Window for your compass outline and another for your
compass spinner; add the spinner to the outline and call setRotate() on
the spinner window as needed.

In the long run, osgWidget should be rewritten to be more modern and use
my (and utilizing feedback from the community) improved understanding of
OSG in general. Alas, the bills don't stop coming, and the little free
time I have (I do Linux development as my 40+/week) goes to the
occasional contract I can secure or other such activities.

I would really like to go back and fix all the things I know are wrong,
I just need a solid, uninterrupted 2 weeks to do so. :)

Quote:
Thanks !

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=49635#49635










------------------
Post generated by Mail2Forum
Back to top
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [3rdparty] All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts extending the osgWidget example osgWi... rkiser General 3 Thu May 12, 2016 6:39 pm View latest post
No new posts osgWidget update function Meldryt General 0 Mon Apr 18, 2016 8:04 am View latest post
No new posts Sync main camera with slave camera ro... Bruno Oliveira General 2 Tue Apr 05, 2016 7:19 pm View latest post
No new posts setPadding inside osgWidget::Canvas (... Meldryt General 0 Tue Mar 22, 2016 3:47 pm View latest post
No new posts osgWidget::Label size adjustment Meldryt General 0 Mon Mar 21, 2016 2:19 pm View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP