Skip to content

Commit

Permalink
Fixed some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jvbsl committed Nov 2, 2016
1 parent a3e867b commit 17b2c1c
Show file tree
Hide file tree
Showing 16 changed files with 254 additions and 299 deletions.
3 changes: 0 additions & 3 deletions OctoAwesome/OctoAwesome.Basics/OctoAwesome.Basics.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -186,9 +186,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\engenious.0.0.1.22\build\engenious.targets" Condition="Exists('..\packages\engenious.0.0.1.22\build\engenious.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
31 changes: 11 additions & 20 deletions OctoAwesome/OctoAwesome.Client/OctoAwesome.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
Expand Down Expand Up @@ -97,26 +97,23 @@
<Compile Include="Screens\PauseScreen.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="engenious, Version=1.0.6075.22909, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\engenious.0.0.1.22\lib\net40\engenious.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="MonoGameUi">
<HintPath>..\libs\MonoGameUi.dll</HintPath>
</Reference>
<Reference Include="NVorbis, Version=0.8.4.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\engenious.0.0.1.22\lib\net40\NVorbis.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="OpenTK, Version=1.1.0.0, Culture=neutral, PublicKeyToken=bad199fe84eb3df4, processorArchitecture=MSIL">
<HintPath>..\packages\engenious.0.0.1.22\lib\net40\OpenTK.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="System" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="System.Configuration" />
<Reference Include="NVorbis">
<HintPath>..\packages\engenious.0.1.0\lib\net40\NVorbis.dll</HintPath>
</Reference>
<Reference Include="OpenTK">
<HintPath>..\packages\engenious.0.1.0\lib\net40\OpenTK.dll</HintPath>
</Reference>
<Reference Include="engenious">
<HintPath>..\packages\engenious.0.1.0\lib\net40\engenious.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Assets\Components\background.png" />
Expand Down Expand Up @@ -199,13 +196,7 @@
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\engenious.0.0.1.22\build\engenious.targets" Condition="Exists('..\packages\engenious.0.0.1.22\build\engenious.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>Dieses Projekt verweist auf mindestens ein NuGet-Paket, das auf diesem Computer fehlt. Verwenden Sie die Wiederherstellung von NuGet-Paketen, um die fehlenden Dateien herunterzuladen. Weitere Informationen finden Sie unter "http://go.microsoft.com/fwlink/?LinkID=322105". Die fehlende Datei ist "{0}".</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('..\packages\engenious.0.0.1.22\build\engenious.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\engenious.0.0.1.22\build\engenious.targets'))" />
</Target>
<Import Project="..\packages\engenious.0.1.0\build\engenious.targets" Condition="Exists('..\packages\engenious.0.1.0\build\engenious.targets')" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
Expand Down
2 changes: 1 addition & 1 deletion OctoAwesome/OctoAwesome.Client/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="engenious" version="0.0.1.22" targetFramework="net40" />
<package id="engenious" version="0.1.0" targetFramework="net452" />
</packages>
219 changes: 121 additions & 98 deletions OctoAwesome/OctoAwesome.Tests/CollisionTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,29 +4,26 @@
using System.Linq;

namespace OctoAwesome.Tests
{
{
using System;
using Xunit;

public class CollisionTests
{
private float gap = 0.00001f;
private Coordinate player;
private float playerRadius = 0.5f;
private float playerHeight = 2f;
private Vector3 move;
private BlockDefinition blockDefinition = new TestBlockDefinition();
private float gap = 0.0000f;
private Player Player;
private List<Index3> blocks = new List<Index3>();

public CollisionTests()
{
Player = new Player();
blocks.Clear();
}

[Fact]
public void CollisionFromEastToWestTest()
{
player = new Coordinate();
player.GlobalPosition = new Vector3(10.6f, 10.5f, 10f);
Player.Position = new Coordinate(){GlobalPosition=new Vector3(10.6f, 10.5f, 10f)};

// Wand
blocks.Add(new Index3(7, 9, 10));
Expand Down Expand Up @@ -56,34 +53,33 @@ public void CollisionFromEastToWestTest()



move = new Vector3(-1, 0, -0.1f);
Player.Velocity = new Vector3(-1, 0, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(9.6f, 10.5f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(9.6f, 10.5f, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-1, 0.1f, -0.1f);
Player.Velocity = new Vector3(-1, 0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(8.6f, 10.6f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(8.6f, 10.6f, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-1, 0.1f, -0.1f);
Player.Velocity = new Vector3(-1, 0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(8.5f + gap, 10.7f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(8.5f + gap, 10.7f, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-0.4f, -0.1f, -0.1f);
Player.Velocity = new Vector3(-0.4f, -0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(8.5f + gap, 10.6f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(8.5f + gap, 10.6f, 10f + gap), Player.Position.GlobalPosition);
}

[Fact]
public void CollisionFromEastToWestIntMaxTest()
{
int max = int.MaxValue - 1000;

player = new Coordinate();
player.GlobalPosition = new Vector3(max + 10.5f, max + 10.5f, max + 10f);
Player.Position = new Coordinate(){GlobalPosition=new Vector3(max + 10.5f, max + 10.5f, max + 10f)};

// Wand
blocks.Add(new Index3(max + 7, max + 9, max + 10));
Expand Down Expand Up @@ -113,33 +109,31 @@ public void CollisionFromEastToWestIntMaxTest()



move = new Vector3(-1, 0, -0.1f);
Player.Velocity = new Vector3(-1, 0, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(max + 9.6f, max + 10.5f, max + 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(max + 9.6f, max + 10.5f, max + 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-1, 0.1f, -0.1f);
Player.Velocity = new Vector3(-1, 0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(max + 8.6f, max + 10.6f, max + 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(max + 8.6f, max + 10.6f, max + 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-1, 0.1f, -0.1f);
Player.Velocity = new Vector3(-1, 0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(max + 8.5f + gap, max + 10.7f, max + 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(max + 8.5f + gap, max + 10.7f, max + 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(-0.4f, -0.1f, -0.1f);
Player.Velocity = new Vector3(-0.4f, -0.1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(max + 8.5f + gap, max + 10.6f, max + 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(max + 8.5f + gap, max + 10.6f, max + 10f + gap), Player.Position.GlobalPosition);
}

[Fact]
public void CollisionFrameSouthToNorthTest()
{
player = new Coordinate();
player.GlobalPosition = new Vector3(10.5f, 10.5f, 10f);

Player.Position = new Coordinate(){GlobalPosition=new Vector3(10.5f, 10.5f, 10f)};
// Wand
blocks.Add(new Index3(9, 7, 10));
blocks.Add(new Index3(10, 7, 10));
Expand All @@ -166,85 +160,114 @@ public void CollisionFrameSouthToNorthTest()
blocks.Add(new Index3(11, 10, 9));
blocks.Add(new Index3(11, 11, 9));

move = new Vector3(0f, -1, -0.1f);
Player.Velocity = new Vector3(0f, -1, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(10.5f, 9.5f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(10.5f, 9.5f, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(0f, -1f, -0.1f);
Player.Velocity = new Vector3(0f, -1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(10.5f, 8.5f, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(10.5f, 8.5f, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(0f, -1f, -0.1f);
Player.Velocity = new Vector3(0f, -1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(10.5f, 8.5f + gap, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(10.5f, 8.5f + gap, 10f + gap), Player.Position.GlobalPosition);

move = new Vector3(0f, -1f, -0.1f);
Player.Velocity = new Vector3(0f, -1f, -0.1f);
Move();
AssertEx.Equal(Vector3.Zero, move);
AssertEx.Equal(new Vector3(10.5f, 8.5f + gap, 10f + gap), player.GlobalPosition);
AssertEx.Equal(Vector3.Zero, Player.Velocity);
AssertEx.Equal(new Vector3(10.5f, 8.5f + gap, 10f + gap), Player.Position.GlobalPosition);
}

private void Move()
{
bool collision = false;
int loop = 0;

do
//Blocks finden die eine Kollision verursachen könnten
int minx = (int)Math.Floor(Math.Min(
Player.Position.BlockPosition.X - Player.Radius,
Player.Position.BlockPosition.X - Player.Radius + Player.Velocity.X));
int maxx = (int)Math.Ceiling(Math.Max(
Player.Position.BlockPosition.X + Player.Radius,
Player.Position.BlockPosition.X + Player.Radius + Player.Velocity.X));
int miny = (int)Math.Floor(Math.Min(
Player.Position.BlockPosition.Y - Player.Radius,
Player.Position.BlockPosition.Y - Player.Radius + Player.Velocity.Y));
int maxy = (int)Math.Ceiling(Math.Max(
Player.Position.BlockPosition.Y + Player.Radius,
Player.Position.BlockPosition.Y + Player.Radius + Player.Velocity.Y));
int minz = (int)Math.Floor(Math.Min(
Player.Position.BlockPosition.Z,
Player.Position.BlockPosition.Z + Player.Velocity.Z));
int maxz = (int)Math.Ceiling(Math.Max(
Player.Position.BlockPosition.Z + Player.Height,
Player.Position.BlockPosition.Z + Player.Height + Player.Velocity.Z));

var playerplanes = CollisionPlane.GetPlayerCollisionPlanes(Player).ToList();

bool abort = false;
var move = Player.Velocity;
for (int z = minz; z <= maxz && !abort; z++)
{
BoundingBox playerBox = new BoundingBox(
new Vector3(
player.GlobalPosition.X - playerRadius,
player.GlobalPosition.Y - playerRadius,
player.GlobalPosition.Z),
new Vector3(
player.GlobalPosition.X + playerRadius,
player.GlobalPosition.Y + playerRadius,
player.GlobalPosition.Z + playerHeight));

collision = false;
float min = 1f;
Axis minAxis = Axis.None;

foreach (var pos in blocks)
for (int y = miny; y <= maxy && !abort; y++)
{
Axis? localAxis;
float? moveFactor = Block.Intersect(blockDefinition.GetCollisionBoxes(null, pos.X, pos.Y, pos.Z), pos, playerBox, move, out localAxis);

if (moveFactor.HasValue && moveFactor.Value < min)
for (int x = minx; x <= maxx && !abort; x++)
{
collision = true;
min = moveFactor.Value;
minAxis = localAxis.Value;
}
}
move = Player.Velocity;

player += (move * min);
move *= (1f - min);
switch (minAxis)
{
case Axis.X:
player += new Vector3(move.X > 0 ? -gap : gap, 0, 0);
move.X = 0f;
break;
case Axis.Y:
player += new Vector3(0, move.Y > 0 ? -gap : gap, 0);
move.Y = 0f;
break;
case Axis.Z:
player += new Vector3(0, 0, move.Z > 0 ? -gap : gap);
move.Z = 0f;
break;
}
Index3 pos = new Index3(x, y, z);
Index3 blockPos = pos + Player.Position.GlobalBlockIndex;
if (!blocks.Contains(blockPos))
continue;



var blockplane = CollisionPlane.GetBlockCollisionPlanes(pos, Player.Velocity).ToList();

// Koordinate normalisieren (Rundwelt)
// player.NormalizeChunkIndexXY(planet.Size);
var planes = from pp in playerplanes
from bp in blockplane
where CollisionPlane.Intersect(bp, pp)
let distance = CollisionPlane.GetDistance(bp, pp)
where CollisionPlane.CheckDistance(distance, move)
select new { BlockPlane = bp, PlayerPlane = pp, Distance = distance };

loop++;
foreach (var plane in planes)
{

var subvelocity = (plane.Distance );
var diff = Player.Velocity - subvelocity;

float vx;
float vy;
float vz;

if (plane.BlockPlane.normal.X != 0 && (Player.Velocity.X > 0 && diff.X >= 0 && subvelocity.X >= 0 || Player.Velocity.X < 0 && diff.X <= 0 && subvelocity.X <= 0))
vx = subvelocity.X;
else
vx = Player.Velocity.X;

if (plane.BlockPlane.normal.Y != 0 && (Player.Velocity.Y > 0 && diff.Y >= 0 && subvelocity.Y >= 0 || Player.Velocity.Y < 0 && diff.Y <= 0 && subvelocity.Y <= 0))
vy = subvelocity.Y;
else
vy = Player.Velocity.Y;

if (plane.BlockPlane.normal.Z != 0 && (Player.Velocity.Z > 0 && diff.Z >= 0 && subvelocity.Z >= 0 || Player.Velocity.Z < 0 && diff.Z <= 0 && subvelocity.Z <= 0))
vz = subvelocity.Z;
else
vz = Player.Velocity.Z;

Player.Velocity = new Vector3(vx, vy, vz);

if (vx == 0 && vy == 0 && vz == 0)
{
abort = true;
break;
}
}
}
}
}
while (collision && loop < 3);
}
}
}
Loading

0 comments on commit 17b2c1c

Please sign in to comment.