Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Camera an Actor and improve performance #67

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions Examples/BallWithAreaLight/BallWithAreaLight.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct BallWithAreaLight: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))

var world: World = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))
AreaLight(corner: Point(-5, 5, -5),
uVec: Vector(2, 0, 0),
uSteps: 10,
Expand Down
14 changes: 7 additions & 7 deletions Examples/BarthSextic/BarthSextic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ import ScintillaLib

let φ: Double = 1.61833987

@available(macOS 12.0, *)
@main
struct BarthSextic: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world: World = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-5, 5, -5))
ImplicitSurface(center: (0.0, 0.0, 0.0), radius: 2.0) { x, y, z in
4.0*(φ*φ*x*x-y*y)*(φ*φ*y*y-z*z)*(φ*φ*z*z-x*x) - (1.0+2.0*φ)*(x*x+y*y+z*z-1.0)*(x*x+y*y+z*z-1.0)
Expand Down
14 changes: 7 additions & 7 deletions Examples/Blob/Blob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Darwin
import ScintillaLib

@available(macOS 12.0, *)
@main
struct Blob: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ImplicitSurface(bottomFrontLeft: (-2, -2, -2),
topBackRight: (2, 2, 2), { x, y, z in
Expand Down
14 changes: 7 additions & 7 deletions Examples/Breather/Breather.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ func z(u: Double, v: Double) -> Double {
}

// ACHTUNG: This takes a while to render!
@available(macOS 12.0, *)
@main
struct Breather: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -15),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -15),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-8, -5, -5),
topBackRight: (8, 5, 5),
Expand Down
14 changes: 7 additions & 7 deletions Examples/Cavatappi/Cavatappi.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Darwin
import ScintillaLib

@available(macOS 12.0, *)
@main
struct Cavatappi: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 7, -15),
to: Point(0, 7, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 7, -15),
to: Point(0, 7, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
PointLight(position: Point(10, 10, -10))
ParametricSurface(bottomFrontLeft: (-3.5, 0, -3.5),
Expand Down
14 changes: 7 additions & 7 deletions Examples/DecoCube/DecoCube.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,16 @@ func decoCubeColor(_ x: Double, _ y: Double, _ z: Double) -> (Double, Double, Do
return (pow(x*x + y*y + z*z, 0.5)/3.0, 1.0, 0.5)
}

@available(macOS 12.0, *)
@main
struct DecoCube: ScintillaApp {
var camera = Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(2, 1, -6),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(2, 1, -6),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ImplicitSurface(bottomFrontLeft: (-2.5, -2.5, -2.5),
topBackRight: (2.5, 2.5, 2.5), { x, y, z in
Expand Down
14 changes: 7 additions & 7 deletions Examples/Die/Die.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct Die: ScintillaApp {
var camera = Camera(width: 800,
height: 600,
viewAngle: PI/3,
from: Point(0, 5, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world: World {
let orange: Material = .solidColor(1, 0.5, 0)
.reflective(0.2)

return World {
Camera(width: 800,
height: 600,
viewAngle: PI/3,
from: Point(0, 5, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Cube()
.material(orange)
Expand Down
15 changes: 8 additions & 7 deletions Examples/DimlyLitScene/DimlyLitScene.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct DimlyLitScene: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

PointLight(position: Point(-10, 10, 0),
fadeDistance: 10)
Sphere()
Expand Down
14 changes: 7 additions & 7 deletions Examples/FishEye/FishEye.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct FishEye: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 0, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(
Expand Down
14 changes: 7 additions & 7 deletions Examples/HappyHalloween/HappyHalloween.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@ func stem(x: Double, y: Double, z: Double) -> Double {
0.2*sin(5.0*atan2(x, z)) - 1 // Adds periodic ribbing on the surface
}

@available(macOS 12.0, *)
@main
struct HappyHalloween: ScintillaApp {
var camera = Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world: World = World {
Camera(width: 600,
height: 600,
viewAngle: PI/3,
from: Point(0, 2, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-2, 5, -5))
ImplicitSurface(center: (0.0, 0.0, 0.0), radius: 2.0) { x, y, z in
pumpkin(x: x, y: y, z: z)
Expand Down
14 changes: 7 additions & 7 deletions Examples/HollowedSphere/HollowedSphere.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct HollowedSphere: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1.5, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1.5, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.solidColor(0, 0, 1))
Expand Down
14 changes: 7 additions & 7 deletions Examples/Hourglass/Hourglass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Darwin
import ScintillaLib

@available(macOS 12.0, *)
@main
struct Hourglass: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 1, -5),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-1.0, -1.0, -1.0),
topBackRight: (1.0, 1.0, 1.0),
Expand Down
14 changes: 7 additions & 7 deletions Examples/QuickStart/QuickStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct QuickStart: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.solidColor(1, 0, 0))
Expand Down
14 changes: 7 additions & 7 deletions Examples/RainbowBall/RainbowBall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Darwin
import ScintillaLib

@available(macOS 12.0, *)
@main
struct RainbowBall: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 2, -2),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
Sphere()
.material(.colorFunction(.hsl) { x, y, z in
Expand Down
14 changes: 7 additions & 7 deletions Examples/Rings/Rings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@
import Darwin
import ScintillaLib

@available(macOS 12.0, *)
@main
struct Rings: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(-10, 7, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(-10, 7, -10),
to: Point(0, 0, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-10, 10, -10))
ParametricSurface(bottomFrontLeft: (-6, -3, -6),
topBackRight: (6, 3, 6),
Expand Down
14 changes: 7 additions & 7 deletions Examples/StarPrism/StarPrism.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@

import ScintillaLib

@available(macOS 12.0, *)
@main
struct StarPrism: ScintillaApp {
var camera = Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 5, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))

var world = World {
Camera(width: 400,
height: 400,
viewAngle: PI/3,
from: Point(0, 5, -5),
to: Point(0, 1, 0),
up: Vector(0, 1, 0))
PointLight(position: Point(-5, 5, -5))
Prism(bottomY: 0.0,
topY: 2.0,
Expand Down
Loading