Compare commits
No commits in common. "849b9af9f1028950b830bf156fc171cbe18fcb0a" and "8b425898a1479fb0d85d3c9c40c6b5ec1ca282e7" have entirely different histories.
849b9af9f1
...
8b425898a1
|
@ -6,23 +6,13 @@ require "./gravity"
|
|||
class Projectable(N)
|
||||
property :gravity_body, :color, :size, :outline_color, :outline_size
|
||||
|
||||
@@hook_new : Proc(Projectable(2), Nil) = ->(obj : Projectable(2)) { nil }
|
||||
def self.set_hook_new(hook_proc : Proc(Projectable(2), Nil))
|
||||
@@hook_new = hook_proc
|
||||
end
|
||||
|
||||
def trigger_hook_new
|
||||
@@hook_new.call(self)
|
||||
end
|
||||
|
||||
def initialize(
|
||||
@gravity_body : Gravity::Body(N),
|
||||
@color : Tuple(Int32, Int32, Int32),
|
||||
@size : Int32,
|
||||
@outline_color : Tuple(Int32, Int32, Int32) = {0, 0, 0},
|
||||
@outline_size : Int32 = 0
|
||||
)
|
||||
trigger_hook_new
|
||||
)
|
||||
end
|
||||
|
||||
def position
|
||||
|
|
|
@ -24,7 +24,6 @@ class Game
|
|||
@screen_center_position : Vector(Float64, 2)
|
||||
@center_position : Vector(Float64, 2)
|
||||
@joystick_moved : Vector(Float64, 2)
|
||||
@selected_body : Gravity::Body(2)
|
||||
|
||||
SECOND_IN_NANO = 1_000_000_000
|
||||
DEFAULT_ZOOM = 5/16
|
||||
|
@ -86,11 +85,6 @@ class Game
|
|||
# # What's the current position of the Y axis on joystick #0?
|
||||
# position = SF::Joystick.get_axis_position(0, SF::Joystick::Y)
|
||||
|
||||
@projectables = Array(Projectable(2)).new
|
||||
Projectable(2).set_hook_new ->(projectable : Projectable(2)) {
|
||||
@projectables << projectable
|
||||
}
|
||||
|
||||
sun_offset = Vector[3*10.0**11, 3*10.0**11]
|
||||
@bodies = {
|
||||
vessel: Gravity::MovingBody(2).new(mass: 1.0, g: 0.1, position: Vector[10.0, 10.0]),
|
||||
|
@ -130,10 +124,9 @@ class Game
|
|||
color: {50, 150, 50},
|
||||
size: 10,
|
||||
)
|
||||
# @projectables = {
|
||||
# @star, @pla1, @pla2, @pla3, @star, @vessel_p,
|
||||
# }
|
||||
@selected_body = @bodies[:vessel]
|
||||
@projectables = {
|
||||
@star, @pla1, @pla2, @pla3, @star, @vessel_p,
|
||||
}
|
||||
@g = Gravity::Field(2).new(@gravited)
|
||||
@vessel = Vessel(2).new(name: "Starbird", gravity_body: @bodies[:vessel], gravity_field: @g)
|
||||
@vessel.navigation.zoom_ratio = DEFAULT_ZOOM
|
||||
|
@ -155,10 +148,6 @@ class Game
|
|||
Log.debug "KeyPressed #{event}"
|
||||
when SF::Event::MouseMoved
|
||||
when SF::Event::MouseButtonEvent
|
||||
click_coord = @window.map_pixel_to_coords({event.x, event.y}, @view)
|
||||
# mmhhhh it does not work as expected, bugged
|
||||
nearest_proj = @projectables.sort_by { |proj| (proj.position - Vector[event.x, event.y]).magnitude }.first
|
||||
@selected_body = nearest_proj.gravity_body
|
||||
Log.debug "MouseButtonEvent #{event}"
|
||||
when SF::Event::JoystickButtonPressed
|
||||
@joystick_moved.zero! # reset 0
|
||||
|
|
|
@ -36,8 +36,7 @@ module PhysicsSandboxDraw
|
|||
label: "Set timescale###set_timescale",
|
||||
data: @timescale,
|
||||
min: 0.1,
|
||||
max: 60,
|
||||
# max: 3600 * 24 * 7,
|
||||
max: 3600 * 24 * 7,
|
||||
flags: (
|
||||
ImGui::ImGuiSliderFlags::Logarithmic
|
||||
),
|
||||
|
@ -296,22 +295,15 @@ module PhysicsSandboxDraw
|
|||
|
||||
def draw_navigation(gravity_field)
|
||||
# ImGui.text "Total Accele is : [#{acceleration[0].round(4)}, #{acceleration[1].round(4)}] m/s²"
|
||||
draw_table(title: "Applied forces", headers: {"Name", "X", "Y", "unit"}) do
|
||||
draw_table_line "Pulse Accele", "#{@vessel.gravity_body.acceleration[0].round(4)}", "#{@vessel.gravity_body.acceleration[1].round(4)}", "m/s²"
|
||||
draw_table_line "Gravitic Field", "#{gravity_field[0].round(4)}", "#{gravity_field[1].round(4)}", "m/s²"
|
||||
end
|
||||
ImGui.text "Current speed #{@vessel.gravity_body.speed.magnitude.round(4)} m/s"
|
||||
ImGui.text ""
|
||||
ImGui.text "Pulse Accele is : [#{@vessel.gravity_body.acceleration[0].round(4)}, #{@vessel.gravity_body.acceleration[1].round(4)}] m/s²"
|
||||
ImGui.text "GraviticBody is : [#{gravity_field[0].round(4)}, #{gravity_field[1].round(4)}] m/s²"
|
||||
ImGui.text "Current speed is : #{@vessel.gravity_body.speed.magnitude.round(4)} m/s"
|
||||
|
||||
relative_speed = @vessel.gravity_body.speed - @selected_body.speed
|
||||
draw_table(title: "Actual vectors", headers: {"Name", "X", "Y", "unit"}) do
|
||||
draw_table_line "Position", @vessel.gravity_body.position[0].round(3).to_s, @vessel.gravity_body.position[1].round(3).to_s, "m"
|
||||
draw_table_line "Speed", @vessel.gravity_body.speed[0].round(3).to_s, @vessel.gravity_body.speed[1].round(3).to_s, "m/s"
|
||||
draw_table_line "Acceleration", @vessel.gravity_body.acceleration[0].round(3).to_s, @vessel.gravity_body.acceleration[1].round(3).to_s, "m/s²"
|
||||
draw_table_line "Selected body", "#{@selected_body.position[0].round(4)}", "#{@selected_body.position[1].round(4)}", "m"
|
||||
draw_table_line "Relative speed", "#{relative_speed[0].round(4)}", "#{relative_speed[1].round(4)}", "m/s"
|
||||
end
|
||||
ImGui.text ""
|
||||
|
||||
ImGui.text "Zoom on"
|
||||
ImGui.radio_button("vessel##navigation_zoom", pointerof(@vessel.navigation.zoom_select), 0)
|
||||
|
@ -344,6 +336,7 @@ module PhysicsSandboxDraw
|
|||
end
|
||||
|
||||
def draw_bridge(gravity_field)
|
||||
|
||||
if ImGui.begin("Bridge")
|
||||
if ImGui.tree_node_ex("Captain", ImGui::ImGuiTreeNodeFlags.new(ImGui::ImGuiTreeNodeFlags::DefaultOpen))
|
||||
draw_captain
|
||||
|
|
Loading…
Reference in New Issue
Block a user