Просмотр исходного кода

Merge pull request #57 from amyadzuki/patch-5

Added SetAspect and ran `go fmt`
Daniel Salvadori 7 лет назад
Родитель
Сommit
43e744fefd
1 измененных файлов с 12 добавлено и 1 удалено
  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) {