mirror of
				https://github.com/GayPizzaSpecifications/voxelotl-engine.git
				synced 2025-11-03 18:49:38 +00:00 
			
		
		
		
	prep for chunk meshing
This commit is contained in:
		@ -1,45 +1,45 @@
 | 
			
		||||
import simd
 | 
			
		||||
 | 
			
		||||
struct AABB {
 | 
			
		||||
public struct AABB {
 | 
			
		||||
  private var _bounds: simd_float2x3
 | 
			
		||||
 | 
			
		||||
  var lower: SIMD3<Float> {
 | 
			
		||||
  public var lower: SIMD3<Float> {
 | 
			
		||||
    get { _bounds[0] }
 | 
			
		||||
    set(row) { self._bounds[0] = row }
 | 
			
		||||
  }
 | 
			
		||||
  var upper: SIMD3<Float> {
 | 
			
		||||
  public var upper: SIMD3<Float> {
 | 
			
		||||
    get { _bounds[1] }
 | 
			
		||||
    set(row) { self._bounds[1] = row }
 | 
			
		||||
  }
 | 
			
		||||
  var center: SIMD3<Float> {
 | 
			
		||||
  public var center: SIMD3<Float> {
 | 
			
		||||
    get { (self._bounds[0] + self._bounds[1]) / 2 }
 | 
			
		||||
  }
 | 
			
		||||
  var size: SIMD3<Float> {
 | 
			
		||||
  public var size: SIMD3<Float> {
 | 
			
		||||
    get { self._bounds[1] - self._bounds[0] }
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  var left: Float   { self._bounds[0].x }
 | 
			
		||||
  var bottom: Float { self._bounds[0].y }
 | 
			
		||||
  var far: Float    { self._bounds[0].z }
 | 
			
		||||
  var right: Float  { self._bounds[1].x }
 | 
			
		||||
  var top: Float    { self._bounds[1].y }
 | 
			
		||||
  var near: Float   { self._bounds[1].z }
 | 
			
		||||
  public var left: Float   { self._bounds[0].x }
 | 
			
		||||
  public var bottom: Float { self._bounds[0].y }
 | 
			
		||||
  public var far: Float    { self._bounds[0].z }
 | 
			
		||||
  public var right: Float  { self._bounds[1].x }
 | 
			
		||||
  public var top: Float    { self._bounds[1].y }
 | 
			
		||||
  public var near: Float   { self._bounds[1].z }
 | 
			
		||||
 | 
			
		||||
  private init(bounds: simd_float2x3) {
 | 
			
		||||
    self._bounds = bounds
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  init(from: SIMD3<Float>, to: SIMD3<Float>) {
 | 
			
		||||
  public init(from: SIMD3<Float>, to: SIMD3<Float>) {
 | 
			
		||||
    self.init(bounds: .init(from, to))
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  static func fromUnitCube(position: SIMD3<Float> = .zero, scale: SIMD3<Float> = .one) -> Self {
 | 
			
		||||
  public static func fromUnitCube(position: SIMD3<Float> = .zero, scale: SIMD3<Float> = .one) -> Self {
 | 
			
		||||
    self.init(
 | 
			
		||||
      from: position - scale,
 | 
			
		||||
      to:   position + scale)
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  func touching(_ other: Self) -> Bool{
 | 
			
		||||
  public func touching(_ other: Self) -> Bool{
 | 
			
		||||
    let distLower = other._bounds[0] - self._bounds[1]  // x: left, y: bottom, z: far
 | 
			
		||||
    let distUpper = self._bounds[0] - other._bounds[1]  // x: right, y: top, z: near
 | 
			
		||||
 | 
			
		||||
@ -51,8 +51,8 @@ struct AABB {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
extension AABB {
 | 
			
		||||
  static func + (lhs: Self, rhs: SIMD3<Float>) -> Self {
 | 
			
		||||
public extension AABB {
 | 
			
		||||
  public static func + (lhs: Self, rhs: SIMD3<Float>) -> Self {
 | 
			
		||||
    .init(bounds: lhs._bounds + .init(rhs, rhs))
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -22,11 +22,13 @@ public extension SIMD3 {
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension SIMD3 where Scalar: FloatingPoint {
 | 
			
		||||
  @inline(__always) static var X: Self      { Self(1, 0, 0) }
 | 
			
		||||
  @inline(__always) static var Y: Self      { Self(0, 1, 0) }
 | 
			
		||||
  @inline(__always) static var Z: Self      { Self(0, 0, 1) }
 | 
			
		||||
public extension SIMD3 where Scalar: Numeric {
 | 
			
		||||
  @inline(__always) static var X: Self { Self(1, 0, 0) }
 | 
			
		||||
  @inline(__always) static var Y: Self { Self(0, 1, 0) }
 | 
			
		||||
  @inline(__always) static var Z: Self { Self(0, 0, 1) }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension SIMD3 where Scalar: FloatingPoint {
 | 
			
		||||
  @inline(__always) static var up: Self      {  Y }
 | 
			
		||||
  @inline(__always) static var down: Self    { -Y }
 | 
			
		||||
  @inline(__always) static var left: Self    { -X }
 | 
			
		||||
@ -35,6 +37,15 @@ public extension SIMD3 where Scalar: FloatingPoint {
 | 
			
		||||
  @inline(__always) static var back: Self    {  Z }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension SIMD3 where Scalar: SignedInteger & FixedWidthInteger {
 | 
			
		||||
  @inline(__always) static var up: Self      {      Y }
 | 
			
		||||
  @inline(__always) static var down: Self    { 0 &- Y }
 | 
			
		||||
  @inline(__always) static var left: Self    { 0 &- X }
 | 
			
		||||
  @inline(__always) static var right: Self   {      X }
 | 
			
		||||
  @inline(__always) static var forward: Self { 0 &- Z }
 | 
			
		||||
  @inline(__always) static var back: Self    {      Z }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
public extension SIMD3 where Scalar: Numeric & AdditiveArithmetic {
 | 
			
		||||
  @inline(__always) func dot(_ b: Self) -> Scalar { self.x * b.x + self.y * b.y + self.z * b.z }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user