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

updating 3D rendering #30

Merged
merged 4 commits into from
Jan 17, 2022
Merged
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
15 changes: 9 additions & 6 deletions Sources/Lindenmayer/Examples3D.swift
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ public enum Detailed3DExamples {
MainBranch(growthDistance: trunk.growthDistance * params.contractionRatioForBranch,
diameter: trunk.diameter * params.widthContraction),
Modules.EndBranch(),
Modules.TurnLeft(angle: params.divergence),
Modules.RollLeft(angle: params.divergence),
Trunk(growthDistance: trunk.growthDistance * params.contractionRatioForTrunk,
diameter: trunk.diameter * params.widthContraction),
]
Expand All @@ -208,7 +208,7 @@ public enum Detailed3DExamples {
StaticTrunk(growthDistance: branch.growthDistance, diameter: branch.diameter),
Modules.Branch(),

Modules.RollLeft(angle: params.lateralBranchAngle),
Modules.TurnLeft(angle: params.lateralBranchAngle),
Modules.LevelOut(),
SecondaryBranch(growthDistance: branch.growthDistance * params.contractionRatioForBranch,
diameter: branch.diameter * params.widthContraction),
Expand All @@ -225,7 +225,7 @@ public enum Detailed3DExamples {
StaticTrunk(growthDistance: branch.growthDistance, diameter: branch.diameter),
Modules.Branch(),

Modules.RollRight(angle: params.branchAngle),
Modules.TurnRight(angle: params.branchAngle),
Modules.LevelOut(),

MainBranch(growthDistance: branch.growthDistance * params.contractionRatioForBranch,
Expand Down Expand Up @@ -283,11 +283,14 @@ public enum Detailed3DExamples {
// p1 : A(l,w) : * → !(w)F(l)[&(a1)B(l*r1,w*wr)] /(180)[&(a2 )B(l*r2 ,w*wr )]
[
StaticTrunk(growthDistance: node.growthDistance, diameter: node.diameter),

Modules.Branch(),
Modules.PitchDown(angle: params.a1),
SecondaryBranch(growthDistance: node.growthDistance * params.r1, diameter: node.diameter * params.wr),
Modules.EndBranch(),
Modules.TurnLeft(angle: 180),

Modules.RollLeft(angle: 180),

Modules.Branch(),
Modules.PitchDown(angle: params.a2),
SecondaryBranch(growthDistance: node.growthDistance * params.r2, diameter: node.diameter * params.wr),
Expand All @@ -299,12 +302,12 @@ public enum Detailed3DExamples {
[
StaticTrunk(growthDistance: node.growthDistance, diameter: node.diameter),
Modules.Branch(),
Modules.RollRight(angle: params.a1),
Modules.TurnRight(angle: params.a1),
Modules.LevelOut(),
SecondaryBranch(growthDistance: node.growthDistance * params.r1, diameter: node.diameter * params.wr),
Modules.EndBranch(),
Modules.Branch(),
Modules.RollLeft(angle: params.a2),
Modules.TurnLeft(angle: params.a2),
Modules.LevelOut(),
SecondaryBranch(growthDistance: node.growthDistance * params.r2, diameter: node.diameter * params.wr),
Modules.EndBranch(),
Expand Down
12 changes: 9 additions & 3 deletions Sources/Lindenmayer/LSystemDefinesRNG.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,23 @@ public struct LSystemDefinesRNG<PType, PRNG>: LSystem where PRNG: SeededRandomNu
return LSystemDefinesRNG<PType, PRNG>(axiom: axiom, state: nil, newStateIndicators: nil, parameters: parameters, prng: prng, rules: rules)
}

public func setSeed(seed: UInt64) {
@discardableResult
public func setSeed(seed: UInt64) -> Self {
prng.resetRNG(seed: seed)
return self
}

public func setParameters(params: PType) {
@discardableResult
public func setParameters(params: PType) -> Self {
parameters.update(params)
return self
}

public func set(seed: UInt64, params: PType) {
@discardableResult
public func set(seed: UInt64, params: PType) -> Self {
prng.resetRNG(seed: seed)
parameters.update(params)
return self
}
}

Expand Down
13 changes: 12 additions & 1 deletion Sources/Lindenmayer/SIMD_Float4x4+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,18 @@ extension simd_float4x4 {
return result
}

/// Calculate a heading vector, originally vertical, based on the 4x4 transform
func rotationTransform() -> matrix_float3x3 {
// extract the rotational component from the transform matrix
let (col1, col2, col3, _) = columns
let rotationTransform = matrix_float3x3(
simd_float3(x: col1.x, y: col1.y, z: col1.z),
simd_float3(x: col2.x, y: col2.y, z: col2.z),
simd_float3(x: col3.x, y: col3.y, z: col3.z)
)
return rotationTransform
}

/// Calculate a normalized heading vector, originally vertical, using a 4x4 state transform
/// - Returns: a 3D unit vector of the heading
func headingVector() -> simd_float3 {
// extract the rotational component from the transform matrix
Expand Down
Loading