Method: VoxelammingGem::BuildBox#translate

Defined in:
lib/voxelamming_gem.rb

#translate(x, y, z, pitch: 0, yaw: 0, roll: 0) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/voxelamming_gem.rb', line 98

def translate(x, y, z, pitch: 0, yaw: 0, roll: 0)
  if @is_allowed_matrix > 0
    # 移動用のマトリックスを計算する
    matrix = @saved_matrices.last
    puts "before matrix: #{matrix}"
    base_position = matrix[0..2]

    if matrix.length == 6
      base_rotation_matrix = get_rotation_matrix(matrix[3], matrix[4], matrix[5])
    else
      base_rotation_matrix = [matrix[3..5], matrix[6..8], matrix[9..11]]
    end

    # Compute the new position after translation
    add_x, add_y, add_z = transform_point_by_rotation_matrix([x, y, z], transpose_3x3(base_rotation_matrix))
    x, y, z = add_vectors(base_position, [add_x, add_y, add_z])
    x, y, z = round_numbers([x, y, z])

    # Compute the rotation after translation
    translate_rotation_matrix = get_rotation_matrix(-pitch, -yaw, -roll)
    rotate_matrix = matrix_multiply(translate_rotation_matrix, base_rotation_matrix)
    @matrix_translation = [x, y, z, *rotate_matrix[0], *rotate_matrix[1], *rotate_matrix[2]]
  else
    x, y, z = round_numbers([x, y, z])

    if @is_framing
      @frame_translations.append([x, y, z, pitch, yaw, roll, @frame_id])
    else
      @translation = [x, y, z, pitch, yaw, roll]
    end
  end
end