The Skung Rockification of Ziggy Skungdust and the SIMD's
This commit is contained in:
@ -22,8 +22,8 @@ import JolkEngine
|
||||
|
||||
class CavesOfJolk: ApplicationImplementation
|
||||
{
|
||||
private lazy var scene = Scene1()
|
||||
//private lazy var scene = CaveScene()
|
||||
//private lazy var scene = Scene1()
|
||||
private lazy var scene = CaveScene()
|
||||
private var aspect: Float = 0
|
||||
private var frameCount = 0
|
||||
private var frameTimer: Float = 1
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import Maths
|
||||
import JolkEngine
|
||||
|
||||
|
||||
|
@ -1,4 +1,6 @@
|
||||
import JolkEngine
|
||||
import Maths
|
||||
|
||||
|
||||
protocol Actor
|
||||
{
|
||||
|
@ -1,4 +1,5 @@
|
||||
import SDL2
|
||||
import Maths
|
||||
import simd
|
||||
import OpenGL.GL
|
||||
import JolkEngine
|
||||
@ -13,7 +14,19 @@ struct Colin: Actor
|
||||
{
|
||||
//.rotate(yaw: angle.x, pitch: angle.y, roll: sin(time)) *
|
||||
//.scale(Vec3f(1.0 + 0.25 * cos(time), 1.0 + 0.25 * sin(time), 1.0)) *
|
||||
.rotate(yawPitch: angle) * .translate(-position - Vec3f(0, 1, 0))
|
||||
.rotate(yawPitch: angle)
|
||||
//.rotate(x: angle.y) * .rotate(y: angle.x)
|
||||
//.rotate(axis: .left, angle: angle.y) * .rotate(y: angle.x)
|
||||
//.rotate(axis: .left, angle: angle.y) * .rotate(axis: .up, angle: angle.x)
|
||||
//Mat4f(quat: Quatf(axis: .X, angle: angle.y) * Quatf(axis: .Y, angle: angle.x))
|
||||
//simd_matrix4x4(simd_quatf(angle: angle.y, axis: .X) * simd_quatf(angle: angle.x, axis: .Y))
|
||||
//.lookAt(to: Mat4f.rotate(yawPitch: angle) * -Vec3f.Z * 20.0)
|
||||
//Mat4f(quat: Quatf.lookAt(to: .rotate(yawPitch: angle).transpose * -Vec3f.Z)).transpose
|
||||
//Mat4f(Mat3f.lookAt(to: .rotate(yawPitch: angle) * -Vec3f.Z))
|
||||
//.lookAt(from: _pos, to: .zero)
|
||||
|
||||
* .translate(-position - Vec3f(0, 1, 0))
|
||||
|
||||
}
|
||||
|
||||
var angle: Vec2f { return Vec2f(ofsAngle.x + _angle, ofsAngle.y) }
|
||||
@ -45,13 +58,13 @@ struct Colin: Actor
|
||||
for edge in edges
|
||||
{
|
||||
let diff = _pos2D - lastPos
|
||||
if simd_dot(edge.n, diff) > 0 && simd_dot(edge.n, velocity) > 0 { continue }
|
||||
if edge.n.dot(diff) > 0 && edge.n.dot(velocity) > 0 { continue }
|
||||
|
||||
let deltaPos = _pos2D - edge.p
|
||||
let something = deltaPos.cross(edge.n)
|
||||
if abs(something) * 2.0 < edge.w
|
||||
{
|
||||
let dot = simd_dot(edge.n, deltaPos)
|
||||
let dot = edge.n.dot(deltaPos)
|
||||
if dot > 0 && dot < colinWidth
|
||||
{
|
||||
lastPos = _pos2D
|
||||
@ -246,5 +259,10 @@ struct Colin: Actor
|
||||
// jumpVel = max(jumpVel, 0.0)
|
||||
// _pos.y = 0.0
|
||||
//}
|
||||
|
||||
|
||||
//let piss = Quatf(axis: .X, angle: angle.y) * Quatf(axis: .Y, angle: angle.x)
|
||||
//let shit = simd_quatf(angle: angle.y, axis: .X) * simd_quatf(angle: angle.x, axis: .Y)
|
||||
//print(piss.w - shit.real, piss.x - shit.imag.x, piss.y - shit.imag.y, piss.z - shit.imag.z)
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import Maths
|
||||
import simd
|
||||
import JolkEngine
|
||||
|
||||
|
BIN
Sources/Test/Resources/Models/Axis.obj.cache
Normal file
BIN
Sources/Test/Resources/Models/Axis.obj.cache
Normal file
Binary file not shown.
BIN
Sources/Test/Resources/Models/rock.mesh
Normal file
BIN
Sources/Test/Resources/Models/rock.mesh
Normal file
Binary file not shown.
BIN
Sources/Test/Resources/Textures/AxisTex.png
Normal file
BIN
Sources/Test/Resources/Textures/AxisTex.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 216 B |
BIN
Sources/Test/Resources/Textures/rock.dds
Normal file
BIN
Sources/Test/Resources/Textures/rock.dds
Normal file
Binary file not shown.
BIN
Sources/Test/Resources/Textures/rocknorm.dds
Normal file
BIN
Sources/Test/Resources/Textures/rocknorm.dds
Normal file
Binary file not shown.
@ -1,4 +1,5 @@
|
||||
import Foundation
|
||||
import Maths
|
||||
import simd
|
||||
import JolkEngine
|
||||
|
||||
@ -8,12 +9,18 @@ struct CaveScene: Scene
|
||||
private var colin = Colin()
|
||||
private var world = Collision()
|
||||
private var worldModel = RenderMesh<VertexPositionNormalColourTexcoord>.empty
|
||||
private var rockModel = RenderMesh<VMeshVertex>.empty, axisModel = RenderMesh<VMeshVertex>.empty
|
||||
private var rockAlbedo = Texture2D.empty, rockNormal = Texture2D.empty, axisAlbedo = Texture2D.empty
|
||||
private var skung = Quatf.init(), skungFrom = Quatf.init(), skungTo = Quatf.init()
|
||||
private var skungx: Float = 0.0
|
||||
private var axisPos = Vec3f(2.0, 0.5, 0.0)
|
||||
private var drawEdges = false
|
||||
|
||||
mutating func setup(render: inout any JolkEngine.Renderer)
|
||||
{
|
||||
colin.setPosition(Vec3f(3.55475903, 0.0667395443, 0.221960306))
|
||||
colin.setAngle(Vec2f(-1.47447872, 0.0))
|
||||
skungTo = .lookAt(from: axisPos, to: colin.position + .up)
|
||||
}
|
||||
|
||||
mutating func loadContent(content: inout JolkEngine.ContentManager) throws
|
||||
@ -21,6 +28,11 @@ struct CaveScene: Scene
|
||||
let obj = try ObjReader.read(url: try content.getResource("CaveScene.obj"))
|
||||
let mesh: Mesh = try ObjLoader.read(model: obj, content: &content)
|
||||
worldModel = try content.create(mesh: mesh)
|
||||
rockModel = try content.load("rock.mesh")
|
||||
rockAlbedo = try content.load("rock.dds")
|
||||
rockNormal = try content.load("rocknorm.dds")
|
||||
axisModel = try content.load("Axis.obj.cache")
|
||||
axisAlbedo = try content.load("AxisTex.png")
|
||||
|
||||
if let collision = obj.objects["Collision3D"]
|
||||
{
|
||||
@ -31,6 +43,23 @@ struct CaveScene: Scene
|
||||
mutating func update(deltaTime: Float)
|
||||
{
|
||||
colin.update(deltaTime: deltaTime, world: world)
|
||||
|
||||
skungx = skungx + deltaTime
|
||||
if skungx >= 1
|
||||
{
|
||||
skungx = fmod(skungx, 1.0)
|
||||
skungFrom = skungTo
|
||||
skungTo = .lookAt(from: axisPos, to: colin.position + .up)
|
||||
}
|
||||
skung = skungFrom.slerp(skungTo, skungx.smoothStep())
|
||||
|
||||
if let pad = GamePad.current?.state
|
||||
{
|
||||
if pad.down(.north)
|
||||
{
|
||||
axisPos += .forward * skung * deltaTime
|
||||
}
|
||||
}
|
||||
if Input.instance.keyboard.keyPressed(.c) { drawEdges = !drawEdges }
|
||||
}
|
||||
|
||||
@ -41,7 +70,7 @@ struct CaveScene: Scene
|
||||
aspect: aspect, zNear: 0.1, zFar: 4000.0))
|
||||
render.setView(matrix: colin.transform)
|
||||
|
||||
let env = Environment()
|
||||
var env = Environment()
|
||||
let drawRanges =
|
||||
{ [render](range: any Sequence<Int>) in
|
||||
for i in range
|
||||
@ -53,6 +82,25 @@ struct CaveScene: Scene
|
||||
}
|
||||
if colin.position.x < 14 { drawRanges([ 0, 1, 2, 6 ]) }
|
||||
else { drawRanges(3...5) }
|
||||
|
||||
//print(Mat4f.rotate(yawPitch: colin.angle) * -Vec3f.Z)
|
||||
env.addDirectionalLight(direction: -.init(-0.6199881, 0.7049423, 0.34448668), colour: .white)
|
||||
render.setMaterial(.init(
|
||||
//specular: .init(grey: 0.5),
|
||||
specular: .white,
|
||||
gloss: 1,
|
||||
texture: axisAlbedo.id))
|
||||
render.draw(mesh: axisModel, model: .translate(axisPos) * Mat4f(quat: skung), environment: env)
|
||||
|
||||
render.setMaterial(.init(
|
||||
diffuse: XnaColour.DarkGray.lighten(by: -0.1),
|
||||
//specular: .init(grey: 0.9),
|
||||
specular: .white,
|
||||
emmision: XnaColour.Green.mix(with: .black, 0.876),
|
||||
gloss: 20,
|
||||
texture: rockAlbedo.id))
|
||||
render.draw(mesh: rockModel, model: .translate(.init(27.622196, 0.8187093, -19.366903)), environment: env)
|
||||
|
||||
if drawEdges { world.draw(render, position: colin.position) }
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import JolkEngine
|
||||
import Foundation
|
||||
import Maths
|
||||
import simd
|
||||
|
||||
|
||||
@ -57,18 +58,18 @@ struct Scene1: Scene
|
||||
try loadWorld(&content)
|
||||
cube = try content.create(mesh: .init(
|
||||
vertices: [
|
||||
.init(position: Vec3f(-1, -1, 1), normal: .forward, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f( 1, -1, 1), normal: .forward, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f(-1, 1, 1), normal: .forward, texCoord: Vec2f(0, 1)),
|
||||
.init(position: Vec3f( 1, 1, 1), normal: .forward, texCoord: Vec2f(1, 1)),
|
||||
.init(position: Vec3f(-1, -1, 1), normal: .back, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f( 1, -1, 1), normal: .back, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f(-1, 1, 1), normal: .back, texCoord: Vec2f(0, 1)),
|
||||
.init(position: Vec3f( 1, 1, 1), normal: .back, texCoord: Vec2f(1, 1)),
|
||||
.init(position: Vec3f( 1, -1, 1), normal: .right, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f( 1, -1, -1), normal: .right, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f( 1, 1, 1), normal: .right, texCoord: Vec2f(0, 1)),
|
||||
.init(position: Vec3f( 1, 1, -1), normal: .right, texCoord: Vec2f(1, 1)),
|
||||
.init(position: Vec3f( 1, -1, -1), normal: .back, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f(-1, -1, -1), normal: .back, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f( 1, 1, -1), normal: .back, texCoord: Vec2f(0, 1)),
|
||||
.init(position: Vec3f(-1, 1, -1), normal: .back, texCoord: Vec2f(1, 1)),
|
||||
.init(position: Vec3f( 1, -1, -1), normal: .forward, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f(-1, -1, -1), normal: .forward, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f( 1, 1, -1), normal: .forward, texCoord: Vec2f(0, 1)),
|
||||
.init(position: Vec3f(-1, 1, -1), normal: .forward, texCoord: Vec2f(1, 1)),
|
||||
.init(position: Vec3f(-1, -1, -1), normal: .left, texCoord: Vec2f(0, 0)),
|
||||
.init(position: Vec3f(-1, -1, 1), normal: .left, texCoord: Vec2f(1, 0)),
|
||||
.init(position: Vec3f(-1, 1, -1), normal: .left, texCoord: Vec2f(0, 1)),
|
||||
@ -158,37 +159,33 @@ struct Scene1: Scene
|
||||
// Draw world
|
||||
for s in worldMesh.subMeshes
|
||||
{
|
||||
//render.setMaterial(Material(
|
||||
// specular: XnaColour.BlanchedAlmond.mix(with: .black, 0.12),
|
||||
// texture: texture.id))
|
||||
if s.material != -1
|
||||
{
|
||||
render.setMaterial(worldMesh.materials[s.material])
|
||||
}
|
||||
else
|
||||
{
|
||||
render.setMaterial(.init())
|
||||
}
|
||||
let material = s.material != -1
|
||||
? worldMesh.materials[s.material]
|
||||
: .init(specular: XnaColour.BlanchedAlmond.mix(with: .black, 0.12))
|
||||
render.setMaterial(material)
|
||||
render.draw(mesh: worldMesh, subMesh: s, environment: env)
|
||||
}
|
||||
|
||||
// Draw jolked up shit
|
||||
render.setMaterial(Material(
|
||||
specular: XnaColour.Gray,
|
||||
gloss: 20.0,
|
||||
gloss: 28.0,
|
||||
texture: jolkTex.id))
|
||||
render.draw(mesh: cube, model: jolkCube.transform, environment: env)
|
||||
|
||||
render.setMaterial(Material(texture: suzanneDiffuse.id))
|
||||
render.draw(mesh: suzanne, model: .translate(.up + Vec3f(3.0, 0.0, -3.5) * 2.5), environment: env)
|
||||
render.setMaterial(Material(
|
||||
specular: .init(grey: 0.5),
|
||||
gloss: 15.0,
|
||||
texture: suzanneDiffuse.id))
|
||||
let suzannePos = .up + Vec3f(3.0, 0.0, -3.5) * 2.5
|
||||
render.draw(mesh: suzanne, model:
|
||||
.translate(suzannePos) *
|
||||
.lookAt(from: suzannePos, to: colin.position + .up) * .rotate(y: .pi), environment: env)
|
||||
|
||||
render.draw(mesh: toybox,
|
||||
model: .translate(Vec3f(6.0, 0.667, -3.5) * Vec3f(2.5, 1, 2.5))
|
||||
* .rotate(y: lightTheta * 0.5) * .scale(scalar: 0.25), environment: env)
|
||||
|
||||
if drawEdges
|
||||
{
|
||||
world.draw(render, position: colin.position)
|
||||
}
|
||||
if drawEdges { world.draw(render, position: colin.position) }
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user