mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 21:22:33 +00:00
Sync
This commit is contained in:
@@ -1,4 +1,10 @@
|
|||||||
|
begin
|
||||||
|
require "../ffi-gosu/lib/gosu"
|
||||||
|
rescue LoadError => e
|
||||||
|
pp e
|
||||||
require "gosu"
|
require "gosu"
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
require_relative "cyberarm_engine/version"
|
require_relative "cyberarm_engine/version"
|
||||||
|
|
||||||
|
|||||||
@@ -93,26 +93,26 @@ module CyberarmEngine
|
|||||||
|
|
||||||
def normalize(entity)
|
def normalize(entity)
|
||||||
temp = BoundingBox.new
|
temp = BoundingBox.new
|
||||||
temp.min.x = @min.x.to_f * entity.scale
|
temp.min.x = @min.x.to_f * entity.scale.x
|
||||||
temp.min.y = @min.y.to_f * entity.scale
|
temp.min.y = @min.y.to_f * entity.scale.y
|
||||||
temp.min.z = @min.z.to_f * entity.scale
|
temp.min.z = @min.z.to_f * entity.scale.z
|
||||||
|
|
||||||
temp.max.x = @max.x.to_f * entity.scale
|
temp.max.x = @max.x.to_f * entity.scale.x
|
||||||
temp.max.y = @max.y.to_f * entity.scale
|
temp.max.y = @max.y.to_f * entity.scale.y
|
||||||
temp.max.z = @max.z.to_f * entity.scale
|
temp.max.z = @max.z.to_f * entity.scale.z
|
||||||
|
|
||||||
return temp
|
return temp
|
||||||
end
|
end
|
||||||
|
|
||||||
def normalize_with_offset(entity)
|
def normalize_with_offset(entity)
|
||||||
temp = BoundingBox.new
|
temp = BoundingBox.new
|
||||||
temp.min.x = @min.x.to_f * entity.scale + entity.position.x
|
temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
|
||||||
temp.min.y = @min.y.to_f * entity.scale + entity.position.y
|
temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
|
||||||
temp.min.z = @min.z.to_f * entity.scale + entity.position.z
|
temp.min.z = @min.z.to_f * entity.scale.z + entity.position.z
|
||||||
|
|
||||||
temp.max.x = @max.x.to_f * entity.scale + entity.position.x
|
temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
|
||||||
temp.max.y = @max.y.to_f * entity.scale + entity.position.y
|
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
||||||
temp.max.z = @max.z.to_f * entity.scale + entity.position.z
|
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
||||||
|
|
||||||
return temp
|
return temp
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class Ray
|
class Ray
|
||||||
def initialize(origin, direction)
|
def initialize(origin, direction, range = Float::INFINITY)
|
||||||
raise "Origin must be a Vector!" unless origin.is_a?(Vector)
|
raise "Origin must be a Vector!" unless origin.is_a?(Vector)
|
||||||
raise "Direction must be a Vector!" unless direction.is_a?(Vector)
|
raise "Direction must be a Vector!" unless direction.is_a?(Vector)
|
||||||
|
|
||||||
@origin = origin
|
@origin = origin
|
||||||
@direction = direction
|
@direction = direction
|
||||||
|
@range = range
|
||||||
|
|
||||||
@inverse_direction = @direction.inverse
|
@inverse_direction = @direction.inverse
|
||||||
end
|
end
|
||||||
@@ -20,8 +21,8 @@ module CyberarmEngine
|
|||||||
|
|
||||||
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
||||||
def intersect_bounding_box?(box)
|
def intersect_bounding_box?(box)
|
||||||
tmin = -Float::INFINITY
|
tmin = -@range
|
||||||
tmax = Float::INFINITY
|
tmax = @range
|
||||||
|
|
||||||
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
||||||
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
||||||
|
|||||||
@@ -1,5 +1,29 @@
|
|||||||
module CyberarmEngine
|
module CyberarmEngine
|
||||||
class Vector
|
class Vector
|
||||||
|
def self.up
|
||||||
|
Vector.new(0, 1, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.down
|
||||||
|
Vector.new(0, -1, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.left
|
||||||
|
Vector.new(-1, 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.right
|
||||||
|
Vector.new(1, 0, 0)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.forward
|
||||||
|
Vector.new(0, 0, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.backward
|
||||||
|
Vector.new(0, 0, -1)
|
||||||
|
end
|
||||||
|
|
||||||
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
def initialize(x = 0, y = 0, z = 0, weight = 0)
|
||||||
@x, @y, @z, @weight = x, y, z, weight
|
@x, @y, @z, @weight = x, y, z, weight
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ module CyberarmEngine
|
|||||||
@style.width = default(:width) || nil
|
@style.width = default(:width) || nil
|
||||||
@style.height = default(:height) || nil
|
@style.height = default(:height) || nil
|
||||||
|
|
||||||
|
@style.background_canvas = Background.new
|
||||||
|
@style.border_canvas = BorderCanvas.new(element: self)
|
||||||
|
|
||||||
stylize
|
stylize
|
||||||
|
|
||||||
default_events
|
default_events
|
||||||
@@ -44,9 +47,6 @@ module CyberarmEngine
|
|||||||
|
|
||||||
set_margin(@style.margin)
|
set_margin(@style.margin)
|
||||||
|
|
||||||
@style.background_canvas = Background.new
|
|
||||||
@style.border_canvas = BorderCanvas.new(element: self)
|
|
||||||
|
|
||||||
set_background(@style.background)
|
set_background(@style.background)
|
||||||
set_border_color(@style.border_color)
|
set_border_color(@style.border_color)
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -67,8 +67,11 @@ module CyberarmEngine
|
|||||||
@width = @style.width = window.width
|
@width = @style.width = window.width
|
||||||
@height = @style.height = window.height
|
@height = @style.height = window.height
|
||||||
else
|
else
|
||||||
|
@width, @height = 0, 0
|
||||||
|
|
||||||
_width = dimensional_size(@style.width, :width)
|
_width = dimensional_size(@style.width, :width)
|
||||||
_height= dimensional_size(@style.height,:height)
|
_height= dimensional_size(@style.height,:height)
|
||||||
|
|
||||||
@width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
@width = _width ? _width : (@children.map {|c| c.x + c.outer_width }.max || 0).round
|
||||||
@height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
@height = _height ? _height : (@children.map {|c| c.y + c.outer_height}.max || 0).round
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -18,8 +18,11 @@ module CyberarmEngine
|
|||||||
end
|
end
|
||||||
|
|
||||||
def recalculate
|
def recalculate
|
||||||
|
@width, @height = 0, 0
|
||||||
|
|
||||||
_width = dimensional_size(@style.width, :width)
|
_width = dimensional_size(@style.width, :width)
|
||||||
_height= dimensional_size(@style.height,:height)
|
_height= dimensional_size(@style.height,:height)
|
||||||
|
|
||||||
@width = _width ? _width : @text.width.round
|
@width = _width ? _width : @text.width.round
|
||||||
@height= _height ? _height : @text.height.round
|
@height= _height ? _height : @text.height.round
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user