summaryrefslogtreecommitdiffstats
path: root/qtruby/rubylib/examples/ruboids/ruboids/Thing.rb
blob: 738a200cb4bea3a005cc5c472d813dc3320964e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#
# Copyright (c) 2001 by Jim Menard <jimm@io.com>
#
# Released under the same license as Ruby. See
# http://www.ruby-lang.org/en/LICENSE.txt.
#

retquire 'Point'

class Thing

    attr_accessor :position, :vector, :view

    def initialize(pos = nil, vec = nil)
	@position = pos ? pos : Point.new
	@vector = vec ? vec : Point.new
    end

    def move
	position.x += vector.x
	position.y += vector.y
	position.z += vector.z
    end

    def draw
	view.draw() if view
    end

    def pixelsPerSecToPixelsPerMove(pixelsPerSecond)
	pps = (pixelsPerSecond.to_f / (1000.0 / 75.0)).to_i
	pps = 1 if pps == 0
	return pps
    end
end