LEFT | RIGHT |
(no file at all) | |
| 1 // Copyright 2014 The Go 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 |
| 5 package f32 |
| 6 |
| 7 import "fmt" |
| 8 |
| 9 type Vec4 [4]float32 |
| 10 |
| 11 func (v *Vec4) Normalize() { |
| 12 sq := v.Dot(v) |
| 13 inv := 1 / Sqrt(sq) |
| 14 v[0] *= inv |
| 15 v[1] *= inv |
| 16 v[2] *= inv |
| 17 v[3] *= inv |
| 18 } |
| 19 |
| 20 func (v *Vec4) Sub(v0, v1 *Vec4) { |
| 21 v[0] = v0[0] - v1[0] |
| 22 v[1] = v0[1] - v1[1] |
| 23 v[2] = v0[2] - v1[2] |
| 24 v[3] = v0[3] - v1[3] |
| 25 } |
| 26 |
| 27 func (v *Vec4) Add(v0, v1 *Vec4) { |
| 28 v[0] = v0[0] + v1[0] |
| 29 v[1] = v0[1] + v1[1] |
| 30 v[2] = v0[2] + v1[2] |
| 31 v[3] = v0[3] + v1[3] |
| 32 } |
| 33 |
| 34 func (v *Vec4) Mul(v0, v1 *Vec4) { |
| 35 v[0] = v0[0] * v1[0] |
| 36 v[1] = v0[1] * v1[1] |
| 37 v[2] = v0[2] * v1[2] |
| 38 v[3] = v0[3] * v1[3] |
| 39 } |
| 40 |
| 41 func (v *Vec4) Dot(v1 *Vec4) float32 { |
| 42 return v[0]*v1[0] + v[1]*v1[1] + v[2]*v1[2] + v[3]*v1[3] |
| 43 } |
| 44 |
| 45 func (v Vec4) String() string { |
| 46 return fmt.Sprintf("Vec4[% 0.3f, % 0.3f, % 0.3f, % 0.3f]", v[0], v[1], v
[2], v[3]) |
| 47 } |
LEFT | RIGHT |