orthographic.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Copyright 2016 The G3N Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package camera
  5. import (
  6. "github.com/g3n/engine/math32"
  7. "github.com/g3n/engine/core"
  8. )
  9. // Orthographic is an orthographic camera.
  10. type Orthographic struct {
  11. Camera // Embedded camera
  12. left float32 // left plane x coordinate
  13. right float32 // right plane x coordinate
  14. top float32 // top plane y coordinate
  15. bottom float32 // bottom plane y coordinate
  16. near float32 // near plane z coordinate
  17. far float32 // far plane z coordinate
  18. zoom float32
  19. projChanged bool // camera projection parameters changed (needs to recalculates projection matrix)
  20. projMatrix math32.Matrix4 // last calculated projection matrix
  21. }
  22. // NewOrthographic creates and returns a pointer to a new orthographic camera with the specified parameters.
  23. func NewOrthographic(left, right, top, bottom, near, far float32) *Orthographic {
  24. cam := new(Orthographic)
  25. cam.Camera.Initialize()
  26. cam.left = left
  27. cam.right = right
  28. cam.top = top
  29. cam.bottom = bottom
  30. cam.near = near
  31. cam.far = far
  32. cam.zoom = 1.0
  33. cam.projChanged = true
  34. return cam
  35. }
  36. // SetZoom sets the zoom factor of the camera.
  37. func (cam *Orthographic) SetZoom(zoom float32) {
  38. cam.zoom = math32.Abs(zoom)
  39. cam.projChanged = true
  40. }
  41. // Zoom returns the zoom factor of the camera.
  42. func (cam *Orthographic) Zoom() float32 {
  43. return cam.zoom
  44. }
  45. // Planes returns the coordinates of the camera planes.
  46. func (cam *Orthographic) Planes() (left, right, top, bottom, near, far float32) {
  47. return cam.left, cam.right, cam.top, cam.bottom, cam.near, cam.far
  48. }
  49. // ProjMatrix satisfies the ICamera interface.
  50. func (cam *Orthographic) ProjMatrix(m *math32.Matrix4) {
  51. if cam.projChanged {
  52. cam.projMatrix.MakeOrthographic(cam.left/cam.zoom, cam.right/cam.zoom, cam.top/cam.zoom, cam.bottom/cam.zoom, cam.near, cam.far)
  53. cam.projChanged = false
  54. }
  55. *m = cam.projMatrix
  56. }
  57. // Project satisfies the ICamera interface and must
  58. // be implemented for specific camera types.
  59. func (cam *Camera) Project(v *math32.Vector3) (*math32.Vector3, error) {
  60. panic("Not implemented")
  61. }
  62. // Unproject satisfies the ICamera interface and must
  63. // be implemented for specific camera types.
  64. func (cam *Camera) Unproject(v *math32.Vector3) (*math32.Vector3, error) {
  65. panic("Not implemented")
  66. }
  67. // SetRaycaster satisfies the ICamera interface and must
  68. // be implemented for specific camera types.
  69. func (cam *Camera) SetRaycaster(rc *core.Raycaster, x, y float32) error {
  70. panic("Not implemented")
  71. }