I’ve created a demo project for those trying to learn views/projections. I figure the more examples, the better. The following project demonstrates how to setup a virtual “camera” which pans around a mockup image of a platformer area I created. One can simply set the “vc_width” and “vc_height” properties of main to change the size of the viewable area. However, the demo divides this area by 2.0 to create a pixelated look/feel using the following two lines of code:
go.set("#main", "vc_width", math.floor(self.vc_width / 2.0)) go.set("#main", "vc_height", math.floor(self.vc_height / 2.0))
If you remove the division by 2.0 then it should be pixel accurate (however the panning demo effect used won’t have the proper offsets then.) A frustum is created with precise bounds to emulate an orthographic projection. However, one can modify the eye and look_at locals within the virtual camera function to create a perspective view (however you will have to recalculate the far_z parameter to allow the “camera” to see far enough.)
Hopefully this will help people trying to learn how to setup a view for their game. I personally prefer using matrices for the view/projection directly since it seems easier to understand the exact viewing area that will be rendered.
Here’s the project download link: https://www.dropbox.com/s/gh15nn64ztxur34/cameralearning.zip?dl=0
cameralearning.zip (233.3 KB)