Explorar o código

Merge pull request #57 from amyadzuki/patch-5

Added SetAspect and ran `go fmt`
Daniel Salvadori %!s(int64=7) %!d(string=hai) anos
pai
achega
43e744fefd
Modificáronse 1 ficheiros con 12 adicións e 1 borrados
  1. 12 1
      camera/orthographic.go

+ 12 - 1
camera/orthographic.go

@@ -5,8 +5,8 @@
 package camera
 
 import (
-	"github.com/g3n/engine/math32"
 	"github.com/g3n/engine/core"
+	"github.com/g3n/engine/math32"
 )
 
 // Orthographic is an orthographic camera.
@@ -39,6 +39,17 @@ func NewOrthographic(left, right, top, bottom, near, far float32) *Orthographic
 	return cam
 }
 
+// SetAspect sets the camera aspect ratio (width/height).
+func (cam *Orthographic) SetAspect(aspect float32) {
+
+	height := cam.top - cam.bottom
+	halfwidth := height * aspect * 0.5
+	center := (cam.left + cam.right) * 0.5
+	cam.left = center - halfwidth
+	cam.right = center + halfwidth
+	cam.projChanged = true
+}
+
 // SetZoom sets the zoom factor of the camera.
 func (cam *Orthographic) SetZoom(zoom float32) {