Heaps.io orthographic camera

With Heaps.io game engine’s lack of proper documentation a pinch of banging your head against the wall is needed. Especially if you’re like me and have very little knowledge about game-making or just programming in general. Orthographic view example with additional camera controls

I only saw a mention in the Heaps.io community that in order to use an orthographic camera projection, you need to set the bound for s3d.camera.orthoBounds. But that by itself wasn’t very useful because a nincompoop like me is too stupid to infer the vast mathematical perverseness that is needed to do just that.

var instance = hxd.Window.getInstance();
var zoom = Math.min(instance.height, instance.width) / 8;
s3d.camera.orthoBounds = Bounds.fromValues(
    -instance.width / zoom / 2,
    -instance.height / zoom / 2,
    instance.width / zoom,
    instance.height / zoom,
s3d.camera.target.set(0, 0, 0);
s3d.camera.pos.load(s3d.camera.target.add(new h3d.Vector(1, 1, 1)));

To make use of orthographic projection on your camera, you need to set the bounds. For the bounds, you need to pass it the width and height of your game’s window, and offset it by half the width and height of your game’s window. By doing so the camera should be centered at the (0,0,0) coordinates of your game’s world. I use -99 and 999 values with the assumption that it define the depth of the view volume as using small values like 0 and 1 would clip the 3d models in my case.

To set the camera’s angle, I set the camera’s target to (0,0,0) and offset the camera’s own position by (1,1,1) from the target’s position. This way it produces a good enough looking isometric angle.

The scene might look uncomfortably too zoomed in, and that’s why the variable zoom takes one of the window’s dimensions and divides it by some random number. The bigger said random number is, the farther away the camera will be from your scene and the smaller everything will look.

Is this the best way to do it? Most likely not. Is this even correct? No clue. But it seems to be working 🙂

Tags: haxe heaps.io