shed scan and physics in oriel shelved
This commit is contained in:
parent
908c6c3db8
commit
75c529b3b2
7 changed files with 151 additions and 90 deletions
|
@ -53,12 +53,12 @@ float sdBox(float3 p, float3 b) {
|
||||||
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
|
return length(max(q, 0.0)) + min(max(q.x, max(q.y, q.z)), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
float raymarch(float3 ro, float3 rd) {
|
float raymarch(float3 origin, float3 direction) {
|
||||||
ro = mul(float4(ro, 1), _matrix).xyz;
|
origin = mul(float4(origin, 1), _matrix).xyz;
|
||||||
rd = mul(float4(rd, 0), _matrix).xyz;
|
direction = mul(float4(direction, 0), _matrix).xyz;
|
||||||
float dist = 0.0;
|
float dist = 0.0;
|
||||||
for (int i = 0; i < 256; i++) {
|
for (int i = 0; i < 256; i++) {
|
||||||
float3 pos = ro + dist * rd;
|
float3 pos = origin + dist * direction;
|
||||||
float step = sdBox(pos, _dimensions / 2.0);
|
float step = sdBox(pos, _dimensions / 2.0);
|
||||||
if (step < 0.0001 || dist > 100) break; // 100 == distmax
|
if (step < 0.0001 || dist > 100) break; // 100 == distmax
|
||||||
dist += step;
|
dist += step;
|
||||||
|
@ -72,15 +72,15 @@ psOut ps(psIn input) {
|
||||||
o.color = input.color;
|
o.color = input.color;
|
||||||
o.depth = input.position.z;
|
o.depth = input.position.z;
|
||||||
|
|
||||||
float3 ro = input.campos;
|
float3 origin = input.campos;
|
||||||
float3 rd = normalize(input.world - ro);
|
float3 direction = normalize(input.world - origin);
|
||||||
// ro = ;
|
// origin = ;
|
||||||
float ol = raymarch(ro, rd);
|
float ol = raymarch(origin, direction);
|
||||||
clip(100 - (ol + 1));
|
clip(100 - (ol + 1));
|
||||||
|
|
||||||
ro += ol * rd;
|
origin += ol * direction;
|
||||||
|
|
||||||
clip(distance(input.campos, input.world) - distance(input.campos, ro));
|
clip(distance(input.campos, input.world) - distance(input.campos, origin));
|
||||||
|
|
||||||
// normalize(input.world - _center)
|
// normalize(input.world - _center)
|
||||||
float t = 1 - (1 + dot(input.normal, _light)) / 2;
|
float t = 1 - (1 + dot(input.normal, _light)) / 2;
|
||||||
|
@ -90,7 +90,7 @@ psOut ps(psIn input) {
|
||||||
|
|
||||||
|
|
||||||
// backface
|
// backface
|
||||||
if (dot(rd, input.normal) > 0) {
|
if (dot(direction, input.normal) > 0) {
|
||||||
o.color = float4(0.5, 0.5, 0.5, 1);
|
o.color = float4(0.5, 0.5, 0.5, 1);
|
||||||
}
|
}
|
||||||
return o;
|
return o;
|
||||||
|
|
BIN
add/shed/shed.glb
Normal file
BIN
add/shed/shed.glb
Normal file
Binary file not shown.
BIN
add/shed/shed.jpg
Normal file
BIN
add/shed/shed.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 10 MiB |
12
app/App.cs
Normal file
12
app/App.cs
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
using System;
|
||||||
|
using StereoKit;
|
||||||
|
|
||||||
|
interface IApp<T> {
|
||||||
|
void Step();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class App {
|
||||||
|
public App() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -48,6 +48,8 @@ public struct Btn {
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Monolith {
|
public class Monolith {
|
||||||
|
public PullRequest.Noise noise;
|
||||||
|
|
||||||
public MonoNet net;
|
public MonoNet net;
|
||||||
public Scene scene;
|
public Scene scene;
|
||||||
public Mic mic;
|
public Mic mic;
|
||||||
|
@ -90,6 +92,10 @@ public class Monolith {
|
||||||
public void Run() {
|
public void Run() {
|
||||||
Renderer.SetClip(0.02f, 1000f);
|
Renderer.SetClip(0.02f, 1000f);
|
||||||
|
|
||||||
|
noise = new PullRequest.Noise(978235461);
|
||||||
|
|
||||||
|
Console.WriteLine("noise = " + noise.value);
|
||||||
|
|
||||||
scene = new Scene(this);
|
scene = new Scene(this);
|
||||||
net = new MonoNet(this);
|
net = new MonoNet(this);
|
||||||
net.Start();
|
net.Start();
|
||||||
|
@ -333,7 +339,6 @@ public class Monolith {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// colorCube.Step();
|
// colorCube.Step();
|
||||||
|
|
||||||
|
|
||||||
|
@ -499,4 +504,56 @@ public static class PullRequest {
|
||||||
public static Pose WorldPose(this Pose pose, float scale = 1) {
|
public static Pose WorldPose(this Pose pose, float scale = 1) {
|
||||||
return pose;
|
return pose;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Serializable]
|
||||||
|
public class Noise {
|
||||||
|
const uint CAP = 4294967295;
|
||||||
|
const uint BIT_NOISE1 = 0xB5297A4D;
|
||||||
|
const uint BIT_NOISE2 = 0x68E31DA4;
|
||||||
|
const uint BIT_NOISE3 = 0x1B56C4E9;
|
||||||
|
|
||||||
|
public uint seed;
|
||||||
|
|
||||||
|
public Noise(uint seed) {
|
||||||
|
this.seed = seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
int position;
|
||||||
|
public float value {
|
||||||
|
get {
|
||||||
|
float v = RNG(position, seed) / (float)CAP;
|
||||||
|
position++;
|
||||||
|
return v;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float D1(int position) {
|
||||||
|
return RNG(position, seed) / (float)CAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float D2(int x, int y) {
|
||||||
|
// large prime number with non-boring bits
|
||||||
|
const int PRIME = 198491317;
|
||||||
|
return RNG(x + (PRIME * y), seed) / (float)CAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float D3(int x, int y, int z) {
|
||||||
|
// large prime number with non-boring bits
|
||||||
|
const int PRIME1 = 198491317;
|
||||||
|
const int PRIME2 = 6542989;
|
||||||
|
return RNG(x + (PRIME1 * y) + (PRIME2 * z), seed) / (float)CAP;
|
||||||
|
}
|
||||||
|
|
||||||
|
public uint RNG(int position, uint seed) {
|
||||||
|
uint mangled = (uint)position;
|
||||||
|
mangled *= BIT_NOISE1;
|
||||||
|
mangled += seed;
|
||||||
|
mangled ^= mangled >> 8;
|
||||||
|
mangled += BIT_NOISE2;
|
||||||
|
mangled ^= mangled << 8;
|
||||||
|
mangled *= BIT_NOISE3;
|
||||||
|
mangled ^= mangled >> 8;
|
||||||
|
return mangled;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
135
app/Oriel.cs
135
app/Oriel.cs
|
@ -106,7 +106,7 @@ public class Oriel {
|
||||||
lOffset = ori.Inverse * vOffset;
|
lOffset = ori.Inverse * vOffset;
|
||||||
qOffset = (ori.Inverse * rGloveRot).Normalized;
|
qOffset = (ori.Inverse * rGloveRot).Normalized;
|
||||||
mOffset = matrix;
|
mOffset = matrix;
|
||||||
anchor = bounds.center + ori * -(detect * bounds.dimensions / 2);
|
anchor = bounds.center + ori * -(detect * bounds.dimensions / 2);
|
||||||
|
|
||||||
adjusting = false;
|
adjusting = false;
|
||||||
} else {
|
} else {
|
||||||
|
@ -196,18 +196,24 @@ public class Oriel {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Matrix orielSimMatrix = Matrix.TRS(new Vec3(0, -bounds.dimensions.y / 2, 0), Quat.Identity, Vec3.One * 0.5f * bounds.dimensions.y).Inverse;
|
// APP
|
||||||
|
Vec3 playerWorldPos = playerPos * 0.5f * bounds.dimensions.y;
|
||||||
|
Matrix orielSimMatrix = Matrix.TRS(
|
||||||
|
new Vec3(0, -bounds.dimensions.y / 2, -playerWorldPos.z),
|
||||||
|
Quat.Identity,
|
||||||
|
Vec3.One * 0.5f * bounds.dimensions.y
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
if (drawAxis) {
|
if (drawAxis) {
|
||||||
meshAxis.Draw(matOriel,
|
meshAxis.Draw(matOriel,
|
||||||
Matrix.TRS(Vec3.Zero, Quat.Identity, Vec3.One * 1f) * orielSimMatrix.Inverse * matrix.Inverse,
|
Matrix.TRS(Vec3.Zero, Quat.Identity, Vec3.One * 1f) * orielSimMatrix * matrix.Inverse,
|
||||||
Color.White
|
Color.White
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh.Quad.Draw(matOriel,
|
Mesh.Quad.Draw(matOriel,
|
||||||
Matrix.TRS(Vec3.Zero, Quat.FromAngles(90, 0, 0), Vec3.One * 100f) * orielSimMatrix.Inverse * matrix.Inverse,
|
Matrix.TRS(Vec3.Zero, Quat.FromAngles(90, 0, 0), Vec3.One * 100f) * orielSimMatrix * matrix.Inverse,
|
||||||
new Color(1.0f, 1.0f, 1.0f) * 0.3f
|
new Color(1.0f, 1.0f, 1.0f) * 0.3f
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -216,22 +222,23 @@ public class Oriel {
|
||||||
new Color(0.3f, 0.3f, 0.6f)
|
new Color(0.3f, 0.3f, 0.6f)
|
||||||
);
|
);
|
||||||
|
|
||||||
// draw relative to oriel matrix
|
|
||||||
// for (int i = 0; i < asteroids.Count; i++) {
|
|
||||||
// Asteroid asteroid = asteroids[i];
|
|
||||||
// asteroid.pose.orientation = Quat.FromAngles(Time.Elapsedf * 10 * asteroid.scale, 0, 0) * asteroid.pose.orientation;
|
float fwd = Input.Key(Key.W).IsActive() ? 1 : 0;
|
||||||
// meshAsteroid.Draw(matOriel,
|
playerPos += new Vec3(-mono.lCon.device.stick.x, 0, -mono.lCon.device.stick.y + fwd) * Time.Elapsedf;
|
||||||
// asteroid.pose.ToMatrix(Vec3.One * asteroid.scale) * matrix.Inverse,
|
|
||||||
// Color.White * 0.32f
|
|
||||||
// );
|
|
||||||
// }
|
|
||||||
playerPos += new Vec3(-mono.lCon.device.stick.x, 0, -mono.lCon.device.stick.y) * Time.Elapsedf;
|
|
||||||
player.Move(playerPos + simOffset, Quat.Identity);
|
|
||||||
meshCube.Draw(matOriel,
|
meshCube.Draw(matOriel,
|
||||||
Matrix.TRS(player.GetPose().position + (player.GetPose().orientation * Vec3.Up * 0.5f) - simOffset, player.GetPose().orientation, new Vec3(0.4f, 1f, 0.2f)) * orielSimMatrix.Inverse * matrix.Inverse,
|
Matrix.TRS(playerPos, Quat.Identity, new Vec3(0.4f, 1f, 0.2f)) * orielSimMatrix * matrix.Inverse,
|
||||||
new Color(1.0f, 0.0f, 0.05f)
|
new Color(1.0f, 0.0f, 0.05f)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// destroy enemies that are too close to the playerPos
|
||||||
|
for (int i = 0; i < enemies.Count; i++) {
|
||||||
|
if (Vec3.Distance(enemies[i], playerPos) < 0.5f) {
|
||||||
|
enemies.RemoveAt(i);
|
||||||
|
i--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// FULLSTICK
|
// FULLSTICK
|
||||||
// Vec3 Fullstick() {
|
// Vec3 Fullstick() {
|
||||||
|
@ -243,77 +250,61 @@ public class Oriel {
|
||||||
// Vec3 fullstick = Fullstick();
|
// Vec3 fullstick = Fullstick();
|
||||||
// sword.Move(playerPos + simOffset + fullstick, Quat.LookAt(Vec3.Zero, fullstick, Vec3.Up));
|
// sword.Move(playerPos + simOffset + fullstick, Quat.LookAt(Vec3.Zero, fullstick, Vec3.Up));
|
||||||
// meshCube.Draw(matOriel,
|
// meshCube.Draw(matOriel,
|
||||||
// Matrix.TRS(sword.GetPose().position + (Vec3.Up * 0.7f) + (sword.GetPose().orientation * Vec3.Forward * -0.5f) - simOffset, sword.GetPose().orientation, new Vec3(0.1f, 0.03f, 1f)) * orielSimMatrix.Inverse * matrix.Inverse,
|
// Matrix.TRS(sword.GetPose().position + (Vec3.Up * 0.7f) + (sword.GetPose().orientation * Vec3.Forward * -0.5f) - simOffset, sword.GetPose().orientation, new Vec3(0.1f, 0.03f, 1f)) * orielSimMatrix * matrix.Inverse,
|
||||||
// new Color(0.9f, 0.5f, 0.5f)
|
// new Color(0.9f, 0.5f, 0.5f)
|
||||||
// );
|
// );
|
||||||
|
|
||||||
|
if (Time.Totalf > spawnTime) {
|
||||||
|
enemies.Add(playerPos + Quat.FromAngles(0, mono.noise.value * 360f, 0) * Vec3.Forward * 8);
|
||||||
|
spawnTime = Time.Totalf + 1;
|
||||||
|
}
|
||||||
|
|
||||||
for (int i = 0; i < enemies.Count; i++) {
|
for (int i = 0; i < enemies.Count; i++) {
|
||||||
Solid enemy = enemies[i];
|
|
||||||
Pose pose = enemy.GetPose();
|
|
||||||
// move towards player
|
// move towards player
|
||||||
enemy.Move(pose.position + (playerPos - pose.position).Normalized * Time.Elapsedf * 0.5f, pose.orientation);
|
Vec3 toPlayer = (playerPos - enemies[i]).Normalized;
|
||||||
|
Vec3 newPos = enemies[i] + toPlayer * Time.Elapsedf * 0.5f;
|
||||||
|
|
||||||
|
// if far enough away from other enemies than set new pos
|
||||||
|
bool setNewPos = true;
|
||||||
|
for (int j = 0; j < enemies.Count; j++) {
|
||||||
|
if (i == j) continue;
|
||||||
|
if ((newPos - enemies[j]).Length < 0.5f) {
|
||||||
|
setNewPos = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (setNewPos) {
|
||||||
|
enemies[i] = newPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
meshCube.Draw(matOriel,
|
meshCube.Draw(matOriel,
|
||||||
Matrix.TRS(pose.position - simOffset, pose.orientation, new Vec3(0.4f, 1f, 0.2f) * 0.99f) * orielSimMatrix.Inverse * matrix.Inverse,
|
Matrix.TRS(enemies[i],
|
||||||
|
Quat.LookAt(enemies[i], playerPos, Vec3.Up),
|
||||||
|
new Vec3(0.4f, 1f, 0.2f)
|
||||||
|
) * orielSimMatrix * matrix.Inverse,
|
||||||
Color.White * 0.62f
|
Color.White * 0.62f
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Solid ground;
|
// Custom > Physics
|
||||||
Solid player; Vec3 playerPos;
|
// issue that we are having is we don't have enough access to the physics sim
|
||||||
Solid sword;
|
// and because of that we run into issues where solutions we've learned of in Unity
|
||||||
List<Solid> enemies = new List<Solid>();
|
// will not carry over simply due to what we have current access to.
|
||||||
Vec3 simOffset = new Vec3(0, 100, 0);
|
|
||||||
|
|
||||||
Mesh meshAsteroid, meshAxis;
|
// getting over these physics hurdles is worthwhile, but not when we have a viable alternate solution
|
||||||
|
Vec3 playerPos;
|
||||||
|
List<Vec3> enemies = new List<Vec3>();
|
||||||
|
float spawnTime;
|
||||||
|
|
||||||
static Model modelAsteroids = Model.FromFile("asteroids.glb");
|
Mesh meshAxis;
|
||||||
class Asteroid {
|
|
||||||
public Pose pose;
|
|
||||||
public float scale;
|
|
||||||
|
|
||||||
public Asteroid(Pose pose, float scale) {
|
|
||||||
this.pose = pose;
|
|
||||||
this.scale = scale;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
List<Asteroid> asteroids = new List<Asteroid>();
|
|
||||||
void Gen() {
|
void Gen() {
|
||||||
meshAxis = model.GetMesh("Axis");
|
meshAxis = model.GetMesh("Axis");
|
||||||
meshAsteroid = modelAsteroids.GetMesh("1 Meteor");
|
|
||||||
asteroids.Clear();
|
|
||||||
Random random = new Random();
|
|
||||||
|
|
||||||
// for (int i = 0; i < 128; i++) {
|
|
||||||
// Pose pose = new Pose(
|
|
||||||
// PullRequest.RandomInCube(Vec3.Up * bounds.dimensions.y * 1, bounds.dimensions.x * 2),
|
|
||||||
// Quat.FromAngles(
|
|
||||||
// random.Next(360),
|
|
||||||
// random.Next(360),
|
|
||||||
// random.Next(360)
|
|
||||||
// )
|
|
||||||
// );
|
|
||||||
// asteroids.Add(new Asteroid(pose, 0.1f + random.NextSingle() * 0.4f));
|
|
||||||
// }
|
|
||||||
|
|
||||||
ground = new Solid(simOffset, Quat.Identity, SolidType.Immovable);
|
|
||||||
ground.AddBox(new Vec3(20, 1, 20), 1, new Vec3(0, -0.5f, 0));
|
|
||||||
|
|
||||||
player = new Solid(simOffset + Vec3.Up, Quat.Identity, SolidType.Normal);
|
|
||||||
player.AddBox(new Vec3(0.4f, 1f, 0.2f), 1, new Vec3(0, 0.5f, 0));
|
|
||||||
|
|
||||||
sword = new Solid(simOffset + Vec3.Up, Quat.Identity, SolidType.Normal);
|
|
||||||
sword.AddBox(new Vec3(0.1f, 0.03f, 1f), 1, new Vec3(0, 0, -0.5f));
|
|
||||||
|
|
||||||
for (int i = 0; i < 32; i++) {
|
|
||||||
Solid solid = new Solid(
|
|
||||||
simOffset + Vec3.Up * i,
|
|
||||||
Quat.Identity,
|
|
||||||
SolidType.Normal
|
|
||||||
);
|
|
||||||
solid.AddBox(new Vec3(0.4f, 1f, 0.2f), 1);
|
|
||||||
enemies.Add(solid);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -16,7 +16,8 @@ public class Scene {
|
||||||
BufferData data = new BufferData();
|
BufferData data = new BufferData();
|
||||||
|
|
||||||
Material matFloor = new Material(Shader.Default);
|
Material matFloor = new Material(Shader.Default);
|
||||||
Model room = Model.FromFile("room/room.glb", Shader.FromFile("room.hlsl"));
|
// Model room = Model.FromFile("room/room.glb", Shader.FromFile("room.hlsl"));
|
||||||
|
Model room = Model.FromFile("shed/shed.glb", Shader.FromFile("room.hlsl"));
|
||||||
|
|
||||||
|
|
||||||
Solid floor;
|
Solid floor;
|
||||||
|
@ -71,7 +72,7 @@ public class Scene {
|
||||||
// room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(mono.oriel.matrix);
|
// room.RootNode.Material["_matrix"] = (Matrix)System.Numerics.Matrix4x4.Transpose(mono.oriel.matrix);
|
||||||
|
|
||||||
// Shader.
|
// Shader.
|
||||||
|
// World.BoundsPose.position.y
|
||||||
room.Draw(Matrix.TRS(new Vec3(0, World.BoundsPose.position.y, -1), Quat.Identity, Vec3.One));
|
room.Draw(Matrix.TRS(new Vec3(0, -1.6f, 0), Quat.Identity, Vec3.One));
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue