try to get the force right
This commit is contained in:
parent
2e4d083094
commit
758ab419d5
@ -25,6 +25,7 @@ class MainView
|
||||
ParseTask.parse(1).then do |result|
|
||||
is = Ast::Expression.from_basic(result)
|
||||
Virtual::Compiler.compile( is , Virtual.machine.space.get_main )
|
||||
Virtual.machine.run_before Virtual::Machine::FIRST_PASS
|
||||
end.fail do |error|
|
||||
raise "Error: #{error}"
|
||||
end
|
||||
|
@ -6,14 +6,23 @@ class ObjectView
|
||||
def initialize o
|
||||
super()
|
||||
self.text = PIXI::Text.new("no")
|
||||
self.text.position = PIXI::Point.new( rand(1000) , rand(550))
|
||||
puts "NO O " unless o
|
||||
self.object = o
|
||||
self.text.text = o.object_id.to_s
|
||||
self.text.text = short
|
||||
@attributes = {}
|
||||
end
|
||||
|
||||
def short
|
||||
object.class.name.split("::").last[0 .. 3]
|
||||
end
|
||||
|
||||
def is_parfait
|
||||
object.class.name.split("::").first == "Parfait"
|
||||
end
|
||||
def set name , val
|
||||
@attributes[name] = val
|
||||
self.text.text = short + @attributes.length.to_s
|
||||
end
|
||||
def get(name)
|
||||
@attributes[name]
|
||||
|
@ -1,11 +1,18 @@
|
||||
|
||||
require "math"
|
||||
|
||||
PIXI::Point.class_eval do
|
||||
alias_native :y=
|
||||
|
||||
def add point
|
||||
self.x += point.x
|
||||
self.x = 0 if self.x < 0
|
||||
self.x = 1100 if self.x > 1100
|
||||
self.y += point.y
|
||||
self.y = 0 if self.y < 0
|
||||
self.y = 550 if self.y > 550
|
||||
end
|
||||
|
||||
def scale_by num
|
||||
min = 0.001
|
||||
num = min if num <= min
|
||||
@ -24,6 +31,7 @@ class SpaceView < PIXI::Graphics
|
||||
# occurence.object is the object
|
||||
objects = Sof::Members.new(space).objects
|
||||
@objects = objects
|
||||
puts "Objects #{objects.length}"
|
||||
# create a mapping from id to volt models
|
||||
@view_objects = {}
|
||||
|
||||
@ -40,50 +48,59 @@ class SpaceView < PIXI::Graphics
|
||||
def draw_me
|
||||
update_positions
|
||||
self.clear
|
||||
prev = nil
|
||||
@view_objects.each do |i , view|
|
||||
if prev
|
||||
self.lineStyle(4, 0xffd900, 2)
|
||||
puts "p" if prev.nil?
|
||||
puts "v" if view.nil?
|
||||
self.moveTo( prev.position.x , prev.position.y )
|
||||
self.lineTo( view.position.x , view.position.y )
|
||||
self.lineStyle(4, 0xffd900, 2)
|
||||
puts "v" if view.nil?
|
||||
view.attributes.each do |n , v |
|
||||
next if n == :id
|
||||
next unless v.is_a? ObjectView
|
||||
next unless v.is_parfait
|
||||
puts "v2" if view.nil?
|
||||
puts "0" if v.nil?
|
||||
self.moveTo( view.position.x , view.position.y )
|
||||
self.lineTo( v.position.x , v.position.y )
|
||||
end
|
||||
prev = view
|
||||
end
|
||||
end
|
||||
|
||||
def force from , to
|
||||
puts "force"
|
||||
dir_x = from.x - to.x
|
||||
dir_x = from.x - to.x - 100
|
||||
dir_x2 = dir_x * dir_x
|
||||
dir_y = from.y - to.y
|
||||
dir_y = from.y - to.y - 100
|
||||
dir_y2 = dir_y * dir_y
|
||||
if( dir_x2 < 0.1 and dir_y2 < 0.1 )
|
||||
puts "Were close"
|
||||
dir_x = rand(10)
|
||||
dir_y = rand(10)
|
||||
dir_x = rand(10) - 5
|
||||
dir_y = rand(10) - 5
|
||||
end
|
||||
f = dir_x * dir_x + dir_y * dir_y
|
||||
f = 0.1 if f < 0.1
|
||||
f = 0.01 if f < 0.01
|
||||
f = f / 100
|
||||
#puts "force #{f}"
|
||||
PIXI::Point.new( dir_x / f , dir_y / f)
|
||||
end
|
||||
|
||||
def update_positions
|
||||
@view_objects.each do |i , view|
|
||||
view.each do |n , v |
|
||||
view.attributes.each do |n , v |
|
||||
next if n == :id
|
||||
next unless o = @view_objects[v]
|
||||
next unless v.is_a? ObjectView
|
||||
next unless v.is_parfait
|
||||
puts "v2" if view.nil?
|
||||
puts "0" if o.nil?
|
||||
view.position.add force( view.position , o.position )
|
||||
puts "0" if v.nil?
|
||||
view.position.add force( view.position , v.position )
|
||||
end
|
||||
offset = 0.0
|
||||
view.position.add force( view.position , PIXI::Point.new(view.position.x , -offset) )
|
||||
view.position.add force( view.position , PIXI::Point.new(-offset , view.position.y) )
|
||||
view.position.add force( view.position , PIXI::Point.new(view.position.x , 550 + offset) )
|
||||
view.position.add force( view.position , PIXI::Point.new(1000 + offset , view.position.y) )
|
||||
end
|
||||
end
|
||||
|
||||
def fill_attributes
|
||||
@view_objects.each do |i , view|
|
||||
ob = view._object
|
||||
ob = view.object
|
||||
next if is_value?(ob)
|
||||
case ob.class.name
|
||||
when "Array" , "Parfait::List"
|
||||
@ -106,7 +123,7 @@ class SpaceView < PIXI::Graphics
|
||||
next if a == "position"
|
||||
val = get_value( ob , a)
|
||||
if( @view_objects[val.object_id])
|
||||
#ref
|
||||
val = @view_objects[val.object_id]
|
||||
end
|
||||
#puts "set #{a}"
|
||||
view.set(a , val )
|
||||
|
Loading…
Reference in New Issue
Block a user