문제

I am trying to create a realistic scene in OSG, and I have a problem with sizes.

Lets assume I will always play my little game in the same screen and therefore I know precisely the resolution and the pixel density of it.

Now, in real life, a box of 1x1x1 meters places a 10 meters from you would have an apparnet size of 10cmx10cmx10cm. I want to create the same effect.

I have a model of a box of 1x1x1 meters made on Sketchup and I place it in the scene 10 meters from the camera (I have experiemented, and I can tell OSG uses the right units). The thing is that in a window of 800x800 pixels the box is 100x100 pixels (lets say) and ina window of 80x80 pixels, the box is 10x10 pixels. What I want is the box to be 10cm always. The good thing is that I know th size,resolution and dpi of the screen I want to use for this exact project and so I can use "constants".

Still, I have no idea how to do this. My first guess would be to scale the world to match the correct size. But I am not sure what chould be the scale factor.

I haven't found any direct way to do this in OSG...

Do you have any suggestion? Thanks!

도움이 되었습니까?

해결책

My first two thoughts are:

  1. You might be able to override the reshape (that's what it is in GLUT, search for the call that pushes a resizeWindow event on the OSG event queue for your particular window system) - always pass it the full width/height of your screen instead of your window, and tell it to use 0,0 as origin, or alternatively just override it with an empty function if you'll always start with a full screen window.

  2. If that doesn't work, you can reset your camera's view frustum based on your window's dimensions and your previous knowledge of the full screen dimensions. There should be lots of info out there on changing your projection matrix - if you can't find OSG-specific info, any OpenGL info about the projection matrix is valid for OSG as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top