Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
265ad75
commit 8fad3f3
Showing
13 changed files
with
255 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
// | ||
// Billboard.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 05/06/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public struct Billboard { | ||
public var start: Vector | ||
public var direction: Vector | ||
public var length: Double | ||
|
||
public init(start: Vector, direction: Vector, length: Double) { | ||
self.start = start | ||
self.direction = direction | ||
self.length = length | ||
} | ||
} | ||
|
||
public extension Billboard { | ||
var end: Vector { | ||
return start + direction * length | ||
} | ||
|
||
func hitTest(_ ray: Ray) -> Vector? { | ||
var lhs = ray, rhs = Ray(origin: start, direction: direction) | ||
|
||
// Ensure rays are never exactly vertical | ||
let epsilon = 0.00001 | ||
if abs(lhs.direction.x) < epsilon { | ||
lhs.direction.x = epsilon | ||
} | ||
if abs(rhs.direction.x) < epsilon { | ||
rhs.direction.x = epsilon | ||
} | ||
|
||
// Calculate slopes and intercepts | ||
let (slope1, intercept1) = lhs.slopeIntercept | ||
let (slope2, intercept2) = rhs.slopeIntercept | ||
|
||
// Check if slopes are parallel | ||
if slope1 == slope2 { | ||
return nil | ||
} | ||
|
||
// Find intersection point | ||
let x = (intercept1 - intercept2) / (slope2 - slope1) | ||
let y = slope1 * x + intercept1 | ||
|
||
// Check intersection point is in range | ||
let distanceAlongRay = (x - lhs.origin.x) / lhs.direction.x | ||
if distanceAlongRay < 0 { | ||
return nil | ||
} | ||
let distanceAlongBillboard = (x - rhs.origin.x) / rhs.direction.x | ||
if distanceAlongBillboard < 0 || distanceAlongBillboard > length { | ||
return nil | ||
} | ||
|
||
return Vector(x: x, y: y) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// | ||
// Monster.swift | ||
// Engine | ||
// | ||
// Created by Nick Lockwood on 02/06/2019. | ||
// Copyright © 2019 Nick Lockwood. All rights reserved. | ||
// | ||
|
||
public struct Monster { | ||
public var position: Vector | ||
|
||
public init(position: Vector) { | ||
self.position = position | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,5 @@ | |
public enum Thing: Int, Decodable { | ||
case nothing | ||
case player | ||
case monster | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
Source/Rampage.xcodeproj/xcshareddata/xcschemes/Engine.xcscheme
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "1010" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "016E41C8228E9A8600ACF137" | ||
BuildableName = "Engine.framework" | ||
BlueprintName = "Engine" | ||
ReferencedContainer = "container:Rampage.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES"> | ||
<Testables> | ||
</Testables> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</TestAction> | ||
<LaunchAction | ||
buildConfiguration = "Debug" | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
debugServiceExtension = "internal" | ||
allowLocationSimulation = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "016E41C8228E9A8600ACF137" | ||
BuildableName = "Engine.framework" | ||
BlueprintName = "Engine" | ||
ReferencedContainer = "container:Rampage.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
buildConfiguration = "Release" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
debugDocumentVersioning = "YES"> | ||
<MacroExpansion> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "016E41C8228E9A8600ACF137" | ||
BuildableName = "Engine.framework" | ||
BlueprintName = "Engine" | ||
ReferencedContainer = "container:Rampage.xcodeproj"> | ||
</BuildableReference> | ||
</MacroExpansion> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
21 changes: 21 additions & 0 deletions
21
Source/Rampage/Assets.xcassets/monster.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"idiom" : "universal", | ||
"filename" : "monster.png", | ||
"scale" : "1x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "2x" | ||
}, | ||
{ | ||
"idiom" : "universal", | ||
"scale" : "3x" | ||
} | ||
], | ||
"info" : { | ||
"version" : 1, | ||
"author" : "xcode" | ||
} | ||
} |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters