|
@@ -17,6 +17,7 @@ type
|
|
|
target*: Node3DRef
|
|
|
front*: Vector3Obj
|
|
|
up*: Vector3Obj
|
|
|
+ right*: Vector3Obj
|
|
|
Camera3DRef* = ref Camera3DObj
|
|
|
|
|
|
|
|
@@ -38,6 +39,7 @@ proc Camera3D*(name: string = "Camera3D"): Camera3DRef =
|
|
|
result.kind = CAMERA_3D_NODE
|
|
|
result.front = Vector3(0, 0, 1)
|
|
|
result.up = Vector3(0, 1, 0)
|
|
|
+ result.right = Vector3()
|
|
|
result.pitch = 0f
|
|
|
result.yaw = 90f
|
|
|
nodes.add(result)
|
|
@@ -60,8 +62,8 @@ method draw*(self: Camera3DRef, w, h: GLfloat) =
|
|
|
self.front = Vector3(
|
|
|
cos(degToRad(self.yaw)) * cos(degToRad(self.pitch)),
|
|
|
sin(degToRad(self.pitch)),
|
|
|
- sin(degToRad(self.yaw)) * cos(degToRad(self.pitch)))
|
|
|
- self.front.normalize()
|
|
|
+ sin(degToRad(self.yaw)) * cos(degToRad(self.pitch))).normalized()
|
|
|
+ self.right = self.front.cross(self.up).normalized()
|
|
|
|
|
|
method setCurrent*(self: Camera3DRef) {.base.} =
|
|
|
## Changes the current camera. It also automatically disable other cameras.
|
|
@@ -69,3 +71,14 @@ method setCurrent*(self: Camera3DRef) {.base.} =
|
|
|
c.current = false
|
|
|
self.current = true
|
|
|
current_camera = self
|
|
|
+
|
|
|
+method rotateCameraX*(self: Camera3DRef, val: float) {.base.} =
|
|
|
+ self.yaw += val
|
|
|
+
|
|
|
+method rotateCameraY*(self: Camera3DRef, val: float) {.base.} =
|
|
|
+ self.pitch += val
|
|
|
+
|
|
|
+method rotateCamera*(self: Camera3DRef, x, y: float) {.base.} =
|
|
|
+ ## Rotates camera by `x` and `y` values.
|
|
|
+ self.yaw += x
|
|
|
+ self.pitch += y
|