CameraLearning demo project (MIT)

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)

6 Likes

It would be good to upload the zip here so it’s more likely to be preserved. Even better to put it up on github. :slight_smile:

1 Like

Thanks I didn’t know zip was supported just assumed it wouldn’t be :blush: I uploaded it now. Maybe I’ll create a GitHub project for it as well in case others have some contribution ideas. One of the more confusing things when learning Defold for me was figuring out the camera system and I ended up using Rendercam for my project. However, I think there’s merit in a smaller project that teaches how the view/projection can be set to accurately view a certain area of a collection.

2 Likes