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 

Resize Geometry in a HUD on Resize of Window


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum]
View previous topic :: View next topic  
Author Message
jlguitar287
Newbie


Joined: 17 Dec 2014
Posts: 5

PostPosted: Wed Dec 17, 2014 9:04 pm    Post subject:
Resize Geometry in a HUD on Resize of Window
Reply with quote

Hi all,

My goal is to have a HUD that consists of one circle drawn programmatically.
I followed the osgHUD example and was able remove the text they draw and draw my circle instead. I did this by adding a (circle) Geometry to the Geode and removing the text and bounding box from the Geode.

My problems:
1) When I resize my window, my circle gets deformed into an ellipse. Why is this? And how do I keep my circle from deforming on window resize?

2) Currently I am using:
hud_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1280, 0, 1024));
but I want my program to work with any screen resolution (not just 1280x1024). How do I obtain the screen resolution of the screen my program is running on?

If you could give me an answer using osgHUD as a reference that'd be especially great!

Thanks so much!
John-Luke
Back to top
View user's profile Send private message
robertosfield
OSG Project Lead


Joined: 18 Mar 2009
Posts: 10890

PostPosted: Thu Dec 18, 2014 9:12 am    Post subject:
Resize Geometry in a HUD on Resize of Window
Reply with quote

Hi John-Luke,

Uf the HUD camera is assigned to the GraphicsContext then when it's
resized the projection matrix can be adjusted automatically if
required. In osg::Camera there is the following control:

enum ProjectionResizePolicy
{
FIXED, /**< Keep the projection matrix fixed, despite
window resizes.*/
HORIZONTAL, /**< Adjust the HORIZONTAL field of view on
window resizes.*/
VERTICAL /**< Adjust the VERTICAL field of view on window resizes.*/

};

/** Set the policy used to determine if and how the projection
matrix should be adjusted on window resizes. */
inline void setProjectionResizePolicy(ProjectionResizePolicy
policy) { _projectionResizePolicy = policy; }

/** Get the policy used to determine if and how the projection
matrix should be adjusted on window resizes. */
inline ProjectionResizePolicy getProjectionResizePolicy()
const { return _projectionResizePolicy; }


If the HUD Camera is embedded in the scene graph this automatic
adjustment isn't active so you'd need to manually manage it by
checking for resize events.

Robert.


On 17 December 2014 at 21:04, John-Luke <> wrote:
Quote:
Hi all,

My goal is to have a HUD that consists of one circle drawn programmatically.
I followed the osgHUD example and was able remove the text they draw and draw my circle instead. I did this by adding a (circle) Geometry to the Geode and removing the text and bounding box from the Geode.

My problems:
1) When I resize my window, my circle gets deformed into an ellipse. Why is this? And how do I keep my circle from deforming on window resize?

2) Currently I am using:
hud_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, 1280, 0, 1024));
but I want my program to work with any screen resolution (not just 1280x1024). How do I obtain the screen resolution of the screen my program is running on?

If you could give me an answer using osgHUD as a reference that'd be especially great!

Thanks so much!
John-Luke

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








------------------
Post generated by Mail2Forum
Back to top
View user's profile Send private message
jlguitar287
Newbie


Joined: 17 Dec 2014
Posts: 5

PostPosted: Sat Dec 20, 2014 2:54 am    Post subject:
Reply with quote

Hi Robert,

Thanks for your help but I think I might have not asked my question very well. Regardless, I was able to find a solution to my problem. I case anybody wants my answer, it is below:

Using osgHud as a reference.

1)
Set up the camera's projection matrix such that
hud_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, width_of_viewer, 0, height_of_viewer));
//the osgHud example gives some default numbers (0,1280,0,1024), but your geometry will deform if you shrink your viewer to be less than 1280 x 1024
//Note, I use qt's qwidget to hold my viewer so I just use qwidget->size() to obtain width and height

2)
draw your geometry (use the osgHud rectangle that you draw text onto as a starting point) and add it to the camera. I also translate my geometry to the center of the screen which is just width_of_viewer/2, height_of_viewer/2

3)
somehow capture the resize event of your viewer when it resizes. I use qt so I just use the QWidget::resizeEvent.

4)
In your resize event function:

hud_camera->setProjectionMatrix(osg::Matrix::ortho2D(0, new_viewer_width, 0, new_viewer_height));

And reposition your Geometry after. Luckily for me this is easy because I always want my geometry in the center: new_viewer_width/2, new_viewer_height/2

Your Geometry will now stay the same proportion AND size AND position (if you do everything I do) as it was in the beginning. It will not shrink or grow in any way on resize on the viewer/window.


Cheers,
John-Luke
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General [forum] 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 draw primitive sets and geometry shad... wernerM General 0 Wed May 24, 2017 3:20 pm View latest post
No new posts Using Geometry with packed vertex arrays ravidavi General 2 Sat Mar 25, 2017 4:39 am View latest post
No new posts Camera resize vs setViewport ravidavi General 3 Fri Feb 24, 2017 3:13 am View latest post
No new posts How to use frame buffer object in exi... saedrna1 General 2 Sat Feb 18, 2017 3:54 am View latest post
No new posts Jittering/Flickering geometry problem umesh General 3 Tue Feb 14, 2017 10:53 am 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