Module: Glslkit::WebGL::Matrix
- Defined in:
- lib/glslkit/webgl/matrix.rb
Class Method Summary collapse
- .identity!(out) ⇒ Object
- .multiply!(out, left, right) ⇒ Object
- .perspective!(out, fovy, aspect, near, far) ⇒ Object
- .rotation_y!(out, radians) ⇒ Object
- .rotation_z!(out, radians) ⇒ Object
- .translation!(out, x, y, z) ⇒ Object
Class Method Details
.identity!(out) ⇒ Object
8 9 10 11 12 |
# File 'lib/glslkit/webgl/matrix.rb', line 8 def identity!(out) 16.times { |i| out[i] = 0.0 } out[0] = out[5] = out[10] = out[15] = 1.0 out end |
.multiply!(out, left, right) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/glslkit/webgl/matrix.rb', line 44 def multiply!(out, left, right) 4.times do |column| offset = column * 4 r0 = right[offset].to_f r1 = right[offset + 1].to_f r2 = right[offset + 2].to_f r3 = right[offset + 3].to_f out[offset] = left[0].to_f * r0 + left[4].to_f * r1 + left[8].to_f * r2 + left[12].to_f * r3 out[offset + 1] = left[1].to_f * r0 + left[5].to_f * r1 + left[9].to_f * r2 + left[13].to_f * r3 out[offset + 2] = left[2].to_f * r0 + left[6].to_f * r1 + left[10].to_f * r2 + left[14].to_f * r3 out[offset + 3] = left[3].to_f * r0 + left[7].to_f * r1 + left[11].to_f * r2 + left[15].to_f * r3 end out end |
.perspective!(out, fovy, aspect, near, far) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/glslkit/webgl/matrix.rb', line 59 def perspective!(out, fovy, aspect, near, far) f = 1.0 / Math.tan(fovy / 2.0) 16.times { |i| out[i] = 0.0 } out[0] = f / aspect out[5] = f out[11] = -1.0 if far nf = 1.0 / (near - far) out[10] = (far + near) * nf out[14] = 2.0 * far * near * nf else out[10] = -1.0 out[14] = -2.0 * near end out end |
.rotation_y!(out, radians) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/glslkit/webgl/matrix.rb', line 25 def rotation_y!(out, radians) cosine = Math.cos(radians) sine = Math.sin(radians) identity!(out) out[0] = cosine out[2] = -sine out[8] = sine out[10] = cosine out end |
.rotation_z!(out, radians) ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/glslkit/webgl/matrix.rb', line 14 def rotation_z!(out, radians) cosine = Math.cos(radians) sine = Math.sin(radians) identity!(out) out[0] = cosine out[1] = sine out[4] = -sine out[5] = cosine out end |
.translation!(out, x, y, z) ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/glslkit/webgl/matrix.rb', line 36 def translation!(out, x, y, z) identity!(out) out[12] = x out[13] = y out[14] = z out end |