-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve raycasting and add NarrowPhase.PointTest (#57)
* Improve raycasting and add NarrowPhase.PointTest * Initialize to Zero/default.
- Loading branch information
1 parent
e80205d
commit 1a8f6a5
Showing
6 changed files
with
221 additions
and
10 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
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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
using Jitter2; | ||
using Jitter2.Collision; | ||
using Jitter2.Collision.Shapes; | ||
using Jitter2.LinearMath; | ||
using JitterDemo.Renderer; | ||
|
||
namespace JitterDemo; | ||
|
||
public class Demo18 : IDemo | ||
{ | ||
public void Draw() | ||
{ | ||
float time = (float)pg.Time; | ||
|
||
JMatrix ori = JMatrix.CreateRotationX(1.1f * time) * | ||
JMatrix.CreateRotationY(2.1f * time) * | ||
JMatrix.CreateRotationZ(1.7f * time); | ||
|
||
for (int i = -15; i < 16; i++) | ||
{ | ||
for (int e = -15; e < 16; e++) | ||
{ | ||
for (int k = -15; k < 16; k++) | ||
{ | ||
JVector point = new JVector(i, e, k) * 0.1f; | ||
|
||
bool result = NarrowPhase.PointTest(testShape, ori, JVector.Zero, point); | ||
|
||
if (result) | ||
{ | ||
pg.DebugRenderer.PushPoint(DebugRenderer.Color.White, | ||
Conversion.FromJitter(point), 0.01f); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
public string Name => "PointTest"; | ||
|
||
private Playground pg = null!; | ||
private World world = null!; | ||
|
||
private Shape testShape; | ||
|
||
public void Build() | ||
{ | ||
pg = (Playground)RenderWindow.Instance; | ||
world = pg.World; | ||
|
||
testShape = new ConeShape(1f); | ||
pg.ResetScene(false); | ||
} | ||
} |
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,78 @@ | ||
using Jitter2; | ||
using Jitter2.Collision.Shapes; | ||
using Jitter2.Dynamics; | ||
using Jitter2.LinearMath; | ||
using JitterDemo.Renderer; | ||
|
||
namespace JitterDemo; | ||
|
||
public class Demo19 : IDemo | ||
{ | ||
public void Draw() | ||
{ | ||
var dr = pg.DebugRenderer; | ||
|
||
var origin = new JVector(0, 20, 0); | ||
|
||
JVector rayVector = new JVector(0, -1, 0); | ||
|
||
for (int i = 0; i < 10000; i++) | ||
{ | ||
JVector dir = JVector.Transform(rayVector, JMatrix.CreateRotationX(0.1f + 0.0001f * i)); | ||
dir = 60.0f * JVector.Transform(dir, JMatrix.CreateRotationY(0.004f * i)); | ||
|
||
dr.PushLine(DebugRenderer.Color.Green, Conversion.FromJitter(origin), | ||
Conversion.FromJitter(origin + dir)); | ||
|
||
bool hit = world.Raycast(origin, dir, null, null, out Shape? shape, | ||
out JVector normal, out float frac); | ||
|
||
if (hit) | ||
{ | ||
dr.PushPoint(DebugRenderer.Color.White, Conversion.FromJitter(origin + frac * dir), 0.2f); | ||
} | ||
} | ||
|
||
JVector offset = new JVector(0.1f, 0.2f, 0.3f); | ||
|
||
Raycast(new JVector(0, 0.5f, 0) + offset, box.Position - offset); | ||
} | ||
|
||
private void Raycast(JVector from, JVector to) | ||
{ | ||
var dr = pg.DebugRenderer; | ||
bool hit = world.Raycast(from, to - from, null, null, out Shape? shape, | ||
out JVector normal, out float frac); | ||
|
||
dr.PushLine(DebugRenderer.Color.Green, Conversion.FromJitter(from), | ||
Conversion.FromJitter(to)); | ||
|
||
if (hit) | ||
{ | ||
dr.PushPoint(DebugRenderer.Color.White, Conversion.FromJitter(from + frac * (to - from)), 0.2f); | ||
} | ||
} | ||
|
||
public string Name => "RaycastTest"; | ||
|
||
private Playground pg = null!; | ||
private World world = null!; | ||
|
||
private Shape testShape; | ||
|
||
private RigidBody box = null!; | ||
|
||
public void Build() | ||
{ | ||
pg = (Playground)RenderWindow.Instance; | ||
world = pg.World; | ||
|
||
testShape = new ConeShape(1f); | ||
pg.ResetScene(); | ||
|
||
box = world.CreateRigidBody(); | ||
box.AddShape(new BoxShape(1)); | ||
box.Position = new JVector(0, 0.5f, -6); | ||
box.IsStatic = true; | ||
} | ||
} |
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