Page 1 of 1

CameraProjectionMode

Posted: Fri Jan 08, 2010 6:37 am
by IdeasVacuum
Engine3D, OpenWindowedScreen

Here is another interesting issue - I have used CameraLocate to provide a means of zooming in/out.

The following chopped-down code shows that this appears to work well:

Code: Select all

#Camera1    = 1
#Window     = 2
#MeshModel  = 3
#MeshEntity = 4
#Light1     = 5
#BtnBrowse  = 6

iFileSelected = 0
    iLoadOK.i = 0
iZoomChange.i = 0
      iZoom.i = 1000


If OpenWindow(#Window, 0, 0, 800, 600, "Esc to Quit", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

      ButtonGadget(#BtnBrowse, 20, 12, 200, 24, "Browse for Ogre Mesh File")

      InitEngine3D()
      InitSprite()
      InitKeyboard()
      InitMouse()

      If OpenWindowedScreen(WindowID(#Window), 100, 100, 600, 400, 0, 0, 0, #PB_Screen_NoSynchronization)

                    CreateCamera(#Camera1, 0, 0, 100, 100)
                    CameraLocate(#Camera1, 0, 0, iZoom)
                    CameraLookAt(#Camera1, 0, 0, 0)
                 CameraBackColor(#Camera1, 7615787)

            ;########### CameraProjectionMode ###############
            CameraProjectionMode(#Camera1, #PB_Camera_Perspective)
            ;CameraProjectionMode(#Camera1, #PB_Camera_Orthographic)

                     CreateLight(#Light1, RGB(51, 51, 51), 20.0, -20.0, 20.0)
              LightSpecularColor(#Light1, RGB(250, 250, 250))

                      Repeat

                                  iEvent = WaitWindowEvent(1)
                               iGadgetID = EventGadget()

                              If (iEvent = #PB_Event_Gadget)

                                    If iGadgetID = #BtnBrowse

                                                       sDir.s = GetHomeDirectory()
                                                       sPat.s = "Ogre Mesh (*.MESH *.mesh)|*.MESH;*.mesh"
                                                     iPatPosn = 0

                                              sFileFullPath.s = OpenFileRequester("Pick an Ogre Mesh File", sDir, sPat, iPatPosn)

                                              iFileSelected = Len(sFileFullPath)

                                          If (iFileSelected > 1)

                                                        sPath.s = GetPathPart(sFileFullPath)

                                                    Add3DArchive(sPath, #PB_3DArchive_FileSystem)

                                          EndIf

                                    EndIf

                              ElseIf (iEvent = #PB_Event_CloseWindow)

                                      CloseScreen()
                                      End

                              EndIf

                      Until iFileSelected > 1


            iLoadOK = LoadMesh(#MeshModel, sFileFullPath)

            If (iLoadOK > 0)

                  CreateEntity(#MeshEntity, MeshID(#MeshModel), #PB_Material_None)

            Else

                  MessageRequester("Problem","Mesh load failure",#PB_MessageRequester_Ok)
                  End

            EndIf

            Repeat

                  ; ### WindowedScreen

                  ExamineMouse()
                  ExamineKeyboard()

                  If KeyboardPushed(#PB_Key_Escape) : CloseScreen() : End : EndIf

                  iZoomChange = MouseWheel()
                        iZoom = iZoom + (iZoomChange * 50)

                  CameraLocate(#Camera1, 0, 0, iZoom)

                  RenderWorld()
                  FlipBuffers()
                  Delay(1)

            Until KeyboardPushed(#PB_Key_Escape)

      EndIf

EndIf

CloseScreen()
End
To test, run the code, load a Mesh file and roll the mouse wheel to zoom. Looks OK.

However, the view is in perspective. Try changing CameraProjectionMode(#Camera1, #PB_Camera_Perspective) to CameraProjectionMode(#Camera1, #PB_Camera_Orthographic). If you load the same Mesh file again, the zoom now has no effect. Anyone hit this problem before? Is it a problem or am I simply going about it the wrong way? :?

Re: CameraProjectionMode

Posted: Fri Jan 08, 2010 12:52 pm
by djes
There's no zoom in orthographic mode. You have to scale your objects :)

Re: CameraProjectionMode

Posted: Fri Jan 08, 2010 3:32 pm
by IdeasVacuum
Hi djes

I had thought about doing that, it's a means to an end, but it's ugly. Then again, may be the Camera function is doing so too. So, is this actually a PB bug? After all, the notion is that the Camera does not have a zoom lens, we are simply moving it closer to or further away from the Object - I just thought that was so simple, it had to be right :|

Re: CameraProjectionMode

Posted: Sat Jan 09, 2010 12:07 am
by djes
Zoom is normally achieved with FOV. In your example, you're simulating zoom by moving your camera, because perspective is defined by a formulae like (point coords)/(dist from camera). But in orthographic mode, a point is rendered whatever is the distance from the camera, so moving the camera has no effect. Zoom doesn't mean anything in this mode!
Do you know what is perspective?

Re: CameraProjectionMode

Posted: Sat Jan 09, 2010 3:22 am
by IdeasVacuum
Hello djes

I see - in my mind's eye, the orthographic mode would be more real-world when viewing single Objects. If you hold a cup in your hand and move it in a straight line from your nose to as far as your arm will reach, the effect of perspective is there but it is indiscernible, that is what I need. I have used ScaleEntity now and it does perform much better so thank you again for that tip.

Re: CameraProjectionMode

Posted: Sun Jan 10, 2010 12:40 am
by djes
:shock:
The cup is only filling all your sight at start, and then becoming a little part of it... Is it what you're calling indiscernible?

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 3:22 am
by citystate
the basic difference between Perspective and Orthographic modes is that Perspective mode considers the camera to be a point 'looking' through a screen; by tracing a line from the point to each corner of the screen gives you the field of view, this also provides the illusion of perspective, making distant objects smaller.

Orthographic mode considers the camera to be a plane segment the same dimensions as (and parallel to) the viewing 'screen' - each ray that passes through the screen, therefore, does so at right angles, providing NO depth information or perceptual illusion.

by moving the camera to zoom, it works with Perspective mode, because the closer an object is, the larger it appears; in Orthographic mode there would be no change at all - moving or rotating the camera would provide a different view, but it would still show all objects, regardless of distance to the camera, as being a constant size.

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 4:12 am
by IdeasVacuum
djes wrote::shock:
The cup is only filling all your sight at start, and then becoming a little part of it... Is it what you're calling indiscernible?
Er no djes, what I meant was that you still can't see any depth to the cup - perspective really kicks in when you have a large area or scene coupled with a long depth of view, in the real world. A classic perspective view would be standing at the end of a long railway track (though not to be recommended :) ), the track appearing to taper from your position to a distant point. So, if I wanted to view a game scene nicely, perspective is helpful to portray the feeling of depth, but if viewing a single object like a small threaded bolt, perspective view is not helpful. Hence engineering CAD programs usually display the model orthographically, with perspective as an option.

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 4:41 am
by Kaeru Gaman
perspective does not "kick in"...
it's an always present effect, the question is just if you're aware of it or not.

when you look at a square post-it in an almost upright angle from a yard away,
the upper side of the post-it still IS shorter mesured in arc degrees,
but you won't percieve it at all, because your brain makes a square out of it.

if you want an object-friendly view of entities, put your cam in a far distance and use a really narrow viewing angle.
this will provide an almost "orthographic" look of the object, but still provides perspective functionality when moving the cam forth and back.

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 5:30 am
by IdeasVacuum
Hello Kaeru - working late/early too? :)
Kaeru Gaman wrote:perspective does not "kick in"...
it's an always present effect, the question is just if you're aware of it or not.
By "kick in", I was referring to perceived usefulness on screen. I.e, perspective is really discernible when you have a large area or scene coupled with a long depth of view, as per my railway track example. Applying that analogy to a game scene, perspective view does kick-in in terms of it's usefulness.

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 5:32 am
by Kaeru Gaman
some weeks I'm just working the night thru... ;)

Seeing is believing.

Image
Left: distance 480, angle 62.5 (standard for a lot of game cams)
Middle: distance 1250, angle 24.0
Right: distance 5250, angle 6.0 (looks orthogonal, but is perspective)

all three use the same perspective cam, only distance and angle differs.

Rendered with POV-Ray

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 9:42 am
by djes
Kaeru> It's an old trick I'm used to in CGI when there isn't orthographic cams ;)

Re: CameraProjectionMode

Posted: Tue Jan 12, 2010 1:47 pm
by IdeasVacuum
Nice illustration with POV Kaeru