Sha256: f27ce0ec91616c5cdf2e8f42ea1538581e20b248a6f8083e8d89839e2ccfe6de

Contents?: true

Size: 1.16 KB

Versions: 1

Compression:

Stored size: 1.16 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: '09 Line Example'

ball = Mittsu::Mesh.new(
  Mittsu::SphereGeometry.new(0.1),
  Mittsu::MeshBasicMaterial.new(color: 0xff00ff)
)
scene.add(ball)

material = Mittsu::LineBasicMaterial.new(color: 0xff00ff)

geometry = Mittsu::Geometry.new()
NP = 10000
MD = 10.0
NR = 200
NP.times do |i|
	d = (i.to_f / NP) * MD
	r = (i.to_f / NP) * Math::PI * NR
	x = Math.sin(r) * d
	y = Math.cos(r) * d
	geometry.vertices.push(Mittsu::Vector3.new(x, y, 0.0))
end

line = Mittsu::Line.new(geometry, material)
scene.add(line)

camera.position.z = 5.0
camera.position.y = 0.0
camera.look_at(line.position)

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

x = 0
renderer.window.run do
  # break if x > 0
  x += 1
	line.rotation.z = x * 0.1

  renderer.render(scene, camera)
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
mittsu-0.1.0 examples/09_line_example.rb