mirror of
https://github.com/cyberarm/cyberarm_engine.git
synced 2025-12-16 13:12:34 +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"
|
||||
end
|
||||
|
||||
|
||||
require_relative "cyberarm_engine/version"
|
||||
|
||||
|
||||
@@ -93,26 +93,26 @@ module CyberarmEngine
|
||||
|
||||
def normalize(entity)
|
||||
temp = BoundingBox.new
|
||||
temp.min.x = @min.x.to_f * entity.scale
|
||||
temp.min.y = @min.y.to_f * entity.scale
|
||||
temp.min.z = @min.z.to_f * entity.scale
|
||||
temp.min.x = @min.x.to_f * entity.scale.x
|
||||
temp.min.y = @min.y.to_f * entity.scale.y
|
||||
temp.min.z = @min.z.to_f * entity.scale.z
|
||||
|
||||
temp.max.x = @max.x.to_f * entity.scale
|
||||
temp.max.y = @max.y.to_f * entity.scale
|
||||
temp.max.z = @max.z.to_f * entity.scale
|
||||
temp.max.x = @max.x.to_f * entity.scale.x
|
||||
temp.max.y = @max.y.to_f * entity.scale.y
|
||||
temp.max.z = @max.z.to_f * entity.scale.z
|
||||
|
||||
return temp
|
||||
end
|
||||
|
||||
def normalize_with_offset(entity)
|
||||
temp = BoundingBox.new
|
||||
temp.min.x = @min.x.to_f * entity.scale + entity.position.x
|
||||
temp.min.y = @min.y.to_f * entity.scale + entity.position.y
|
||||
temp.min.z = @min.z.to_f * entity.scale + entity.position.z
|
||||
temp.min.x = @min.x.to_f * entity.scale.x + entity.position.x
|
||||
temp.min.y = @min.y.to_f * entity.scale.y + entity.position.y
|
||||
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.y = @max.y.to_f * entity.scale + entity.position.y
|
||||
temp.max.z = @max.z.to_f * entity.scale + entity.position.z
|
||||
temp.max.x = @max.x.to_f * entity.scale.x + entity.position.x
|
||||
temp.max.y = @max.y.to_f * entity.scale.y + entity.position.y
|
||||
temp.max.z = @max.z.to_f * entity.scale.z + entity.position.z
|
||||
|
||||
return temp
|
||||
end
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
module CyberarmEngine
|
||||
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 "Direction must be a Vector!" unless direction.is_a?(Vector)
|
||||
|
||||
@origin = origin
|
||||
@direction = direction
|
||||
@range = range
|
||||
|
||||
@inverse_direction = @direction.inverse
|
||||
end
|
||||
@@ -20,8 +21,8 @@ module CyberarmEngine
|
||||
|
||||
# Based on: https://tavianator.com/fast-branchless-raybounding-box-intersections/
|
||||
def intersect_bounding_box?(box)
|
||||
tmin = -Float::INFINITY
|
||||
tmax = Float::INFINITY
|
||||
tmin = -@range
|
||||
tmax = @range
|
||||
|
||||
tx1 = (box.min.x - @origin.x) * @inverse_direction.x
|
||||
tx2 = (box.max.x - @origin.x) * @inverse_direction.x
|
||||
|
||||
@@ -1,5 +1,29 @@
|
||||
module CyberarmEngine
|
||||
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)
|
||||
@x, @y, @z, @weight = x, y, z, weight
|
||||
end
|
||||
|
||||
@@ -32,6 +32,9 @@ module CyberarmEngine
|
||||
@style.width = default(:width) || nil
|
||||
@style.height = default(:height) || nil
|
||||
|
||||
@style.background_canvas = Background.new
|
||||
@style.border_canvas = BorderCanvas.new(element: self)
|
||||
|
||||
stylize
|
||||
|
||||
default_events
|
||||
@@ -44,9 +47,6 @@ module CyberarmEngine
|
||||
|
||||
set_margin(@style.margin)
|
||||
|
||||
@style.background_canvas = Background.new
|
||||
@style.border_canvas = BorderCanvas.new(element: self)
|
||||
|
||||
set_background(@style.background)
|
||||
set_border_color(@style.border_color)
|
||||
end
|
||||
|
||||
@@ -67,8 +67,11 @@ module CyberarmEngine
|
||||
@width = @style.width = window.width
|
||||
@height = @style.height = window.height
|
||||
else
|
||||
@width, @height = 0, 0
|
||||
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height= dimensional_size(@style.height,:height)
|
||||
|
||||
@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
|
||||
end
|
||||
|
||||
@@ -18,8 +18,11 @@ module CyberarmEngine
|
||||
end
|
||||
|
||||
def recalculate
|
||||
@width, @height = 0, 0
|
||||
|
||||
_width = dimensional_size(@style.width, :width)
|
||||
_height= dimensional_size(@style.height,:height)
|
||||
|
||||
@width = _width ? _width : @text.width.round
|
||||
@height= _height ? _height : @text.height.round
|
||||
|
||||
|
||||
Reference in New Issue
Block a user