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