-
Notifications
You must be signed in to change notification settings - Fork 0
/
cam.go
53 lines (45 loc) · 896 Bytes
/
cam.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package glvox
type Cam struct {
Pos, Dir, Up, Left Vec3
}
func NewCam() *Cam {
c := new(Cam)
c.Dir = Vec3 { 0.0, 0.0, -1.0 }
c.Up = Vec3 { 0.0, 1.0, 0.0 }
c.Left = Vec3 {-1.0, 0.0, 0.0 }
return c
}
// forward/backward
func (c *Cam) Move(a float32) {
c.Pos = c.Pos.Plus(c.Dir.Mul(a))
}
// left/right
func (c *Cam) Strafe(a float32) {
strafe := c.Dir.Cross(c.Up)
c.Pos = c.Pos.Plus(strafe.Mul(a))
}
// up/down
func (c *Cam) Updown(a float32) {
c.Pos = c.Pos.Plus(c.Up.Mul(a))
}
// Rotate up/down
func (c *Cam) Pitch(a float32) {
q := NewQuat(a, c.Left)
m := q.Mat3()
c.Dir = m.Mul(c.Dir)
c.Up = m.Mul(c.Up)
}
// Rotate left/right
func (c *Cam) Yaw(a float32) {
q := NewQuat(a, c.Up)
m := q.Mat3()
c.Dir = m.Mul(c.Dir)
c.Left = m.Mul(c.Left)
}
// Rotate z
func (c *Cam) Roll(a float32) {
q := NewQuat(a, c.Dir)
m := q.Mat3()
c.Left = m.Mul(c.Left)
c.Up = m.Mul(c.Up)
}