Sha256: 6e4bf2c09fc0dc7888a1bfbfa4edb438d45147e26f2616378d72637dc877fe68

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

require_relative './example_helper'

SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600
ASPECT = SCREEN_WIDTH.to_f / SCREEN_HEIGHT.to_f

scene = Mittsu::Scene.new
camera = Mittsu::PerspectiveCamera.new(75.0, ASPECT, 0.1, 1000.0)

renderer = Mittsu::OpenGLRenderer.new width: SCREEN_WIDTH, height: SCREEN_HEIGHT, title: '11 Keyboard Input Example'

geometry = Mittsu::BoxGeometry.new(1.0, 1.0, 1.0)
material = Mittsu::MeshBasicMaterial.new(color: 0x00ff00)
cube = Mittsu::Mesh.new(geometry, material)
scene.add(cube)

camera.position.z = 5.0

renderer.window.on_resize do |width, height|
  renderer.set_viewport(0, 0, width, height)
  camera.aspect = width.to_f / height.to_f
  camera.update_projection_matrix
end

renderer.window.on_key_typed do |key|
  case key
  when GLFW_KEY_UP
    cube.position.y += 0.5
  when GLFW_KEY_DOWN
    cube.position.y -= 0.5
  when GLFW_KEY_LEFT
    cube.position.x -= 0.5
  when GLFW_KEY_RIGHT
    cube.position.x += 0.5
  end
end

renderer.window.run do
  cube.rotation.x += 0.1
  cube.rotation.y += 0.1

  renderer.render(scene, camera)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mittsu-0.1.0 examples/11_keyboard_input_example.rb