|
@@ -2,7 +2,7 @@
|
|
|
// Use of this source code is governed by a BSD-style
|
|
// Use of this source code is governed by a BSD-style
|
|
|
// license that can be found in the LICENSE file.
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
-// Package camera contain common camera types used for rendering 3D scenes.
|
|
|
|
|
|
|
+// Package camera contains common camera types used for rendering 3D scenes.
|
|
|
package camera
|
|
package camera
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
@@ -10,7 +10,7 @@ import (
|
|
|
"github.com/g3n/engine/math32"
|
|
"github.com/g3n/engine/math32"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
-// ICamera is interface for all camera types
|
|
|
|
|
|
|
+// ICamera is interface for all camera types.
|
|
|
type ICamera interface {
|
|
type ICamera interface {
|
|
|
GetCamera() *Camera
|
|
GetCamera() *Camera
|
|
|
ViewMatrix(*math32.Matrix4)
|
|
ViewMatrix(*math32.Matrix4)
|
|
@@ -20,16 +20,16 @@ type ICamera interface {
|
|
|
SetRaycaster(rc *core.Raycaster, x, y float32) error
|
|
SetRaycaster(rc *core.Raycaster, x, y float32) error
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Camera is the base camera which is normally embedded in other camera types
|
|
|
|
|
|
|
+// Camera is the base camera which is normally embedded in other camera types.
|
|
|
type Camera struct {
|
|
type Camera struct {
|
|
|
core.Node // Embedded Node
|
|
core.Node // Embedded Node
|
|
|
- target math32.Vector3 // camera target in world coordinates
|
|
|
|
|
- up math32.Vector3 // camera Up vector
|
|
|
|
|
- viewMatrix math32.Matrix4 // last calculated view matrix
|
|
|
|
|
|
|
+ target math32.Vector3 // Camera target in world coordinates
|
|
|
|
|
+ up math32.Vector3 // Camera Up vector
|
|
|
|
|
+ viewMatrix math32.Matrix4 // Last calculated view matrix
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Initialize initializes the base camera.
|
|
// Initialize initializes the base camera.
|
|
|
-// It is used by other camera types which embed this base camera
|
|
|
|
|
|
|
+// Normally used by other camera types which embed this base camera.
|
|
|
func (cam *Camera) Initialize() {
|
|
func (cam *Camera) Initialize() {
|
|
|
|
|
|
|
|
cam.Node.Init()
|
|
cam.Node.Init()
|
|
@@ -55,58 +55,38 @@ func (cam *Camera) LookAt(target *math32.Vector3) {
|
|
|
cam.SetQuaternionQuat(&q)
|
|
cam.SetQuaternionQuat(&q)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// GetCamera satisfies the ICamera interface
|
|
|
|
|
|
|
+// GetCamera satisfies the ICamera interface.
|
|
|
func (cam *Camera) GetCamera() *Camera {
|
|
func (cam *Camera) GetCamera() *Camera {
|
|
|
|
|
|
|
|
return cam
|
|
return cam
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Target get the current target position
|
|
|
|
|
|
|
+// Target get the current target position.
|
|
|
func (cam *Camera) Target() math32.Vector3 {
|
|
func (cam *Camera) Target() math32.Vector3 {
|
|
|
|
|
|
|
|
return cam.target
|
|
return cam.target
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// Up get the current up position
|
|
|
|
|
|
|
+// Up get the current camera up vector.
|
|
|
func (cam *Camera) Up() math32.Vector3 {
|
|
func (cam *Camera) Up() math32.Vector3 {
|
|
|
|
|
|
|
|
return cam.up
|
|
return cam.up
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// SetUp sets the camera up vector
|
|
|
|
|
|
|
+// SetUp sets the camera up vector.
|
|
|
func (cam *Camera) SetUp(up *math32.Vector3) {
|
|
func (cam *Camera) SetUp(up *math32.Vector3) {
|
|
|
|
|
|
|
|
cam.up = *up
|
|
cam.up = *up
|
|
|
cam.LookAt(&cam.target) // TODO Maybe remove and let user call LookAt explicitly
|
|
cam.LookAt(&cam.target) // TODO Maybe remove and let user call LookAt explicitly
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// ViewMatrix returns the current view matrix of this camera
|
|
|
|
|
|
|
+// ViewMatrix returns the current view matrix of this camera.
|
|
|
func (cam *Camera) ViewMatrix(m *math32.Matrix4) {
|
|
func (cam *Camera) ViewMatrix(m *math32.Matrix4) {
|
|
|
|
|
|
|
|
|
|
+ cam.UpdateMatrixWorld()
|
|
|
matrixWorld := cam.MatrixWorld()
|
|
matrixWorld := cam.MatrixWorld()
|
|
|
err := m.GetInverse(&matrixWorld)
|
|
err := m.GetInverse(&matrixWorld)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
panic("Camera.ViewMatrix: Couldn't invert matrix")
|
|
panic("Camera.ViewMatrix: Couldn't invert matrix")
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
-// Project satisfies the ICamera interface and must
|
|
|
|
|
-// be implemented for specific camera types.
|
|
|
|
|
-func (cam *Camera) Project(v *math32.Vector3) (*math32.Vector3, error) {
|
|
|
|
|
-
|
|
|
|
|
- panic("Not implemented")
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// Unproject satisfies the ICamera interface and must
|
|
|
|
|
-// be implemented for specific camera types.
|
|
|
|
|
-func (cam *Camera) Unproject(v *math32.Vector3) (*math32.Vector3, error) {
|
|
|
|
|
-
|
|
|
|
|
- panic("Not implemented")
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
-// SetRaycaster satisfies the ICamera interface and must
|
|
|
|
|
-// be implemented for specific camera types.
|
|
|
|
|
-func (cam *Camera) SetRaycaster(rc *core.Raycaster, x, y float32) error {
|
|
|
|
|
-
|
|
|
|
|
- panic("Not implemented")
|
|
|
|
|
-}
|
|
|