Compare commits
2 Commits
8b425898a1
...
849b9af9f1
Author | SHA1 | Date | |
---|---|---|---|
849b9af9f1 | |||
01e8efd5c6 |
|
@ -6,13 +6,23 @@ 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,6 +24,7 @@ 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
|
||||
|
@ -85,6 +86,11 @@ 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]),
|
||||
|
@ -124,9 +130,10 @@ class Game
|
|||
color: {50, 150, 50},
|
||||
size: 10,
|
||||
)
|
||||
@projectables = {
|
||||
@star, @pla1, @pla2, @pla3, @star, @vessel_p,
|
||||
}
|
||||
# @projectables = {
|
||||
# @star, @pla1, @pla2, @pla3, @star, @vessel_p,
|
||||
# }
|
||||
@selected_body = @bodies[:vessel]
|
||||
@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
|
||||
|
@ -148,6 +155,10 @@ 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,7 +36,8 @@ module PhysicsSandboxDraw
|
|||
label: "Set timescale###set_timescale",
|
||||
data: @timescale,
|
||||
min: 0.1,
|
||||
max: 3600 * 24 * 7,
|
||||
max: 60,
|
||||
# max: 3600 * 24 * 7,
|
||||
flags: (
|
||||
ImGui::ImGuiSliderFlags::Logarithmic
|
||||
),
|
||||
|
@ -295,15 +296,22 @@ module PhysicsSandboxDraw
|
|||
|
||||
def draw_navigation(gravity_field)
|
||||
# ImGui.text "Total Accele is : [#{acceleration[0].round(4)}, #{acceleration[1].round(4)}] m/s²"
|
||||
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"
|
||||
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 ""
|
||||
|
||||
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)
|
||||
|
@ -336,7 +344,6 @@ 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