Skip to content

Commit 4d9ba52

Browse files
authored
Merge pull request #257 from shoekzema/uubranch3D-v2-stefan
UUbranch3D-v2-stefan: thesis 3D Octree-movement implementation
2 parents d51700f + 6300880 commit 4d9ba52

File tree

72 files changed

+497828
-432
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+497828
-432
lines changed

JvmClient/src/commonMain/kotlin/spaceEngineers/controller/ContextControllerWrapper.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@ class ContextControllerWrapper(
1313
) : SpaceEngineers by spaceEngineers {
1414

1515
private fun addToHistory(observation: Observation) {
16-
context.addToHistory(observation)
16+
//context.addToHistory(observation)
1717
}
1818

1919
private fun addToHistory(observation: CharacterObservation) {
20-
context.addToHistory(observation)
20+
//context.addToHistory(observation)
2121
}
2222

2323
override val observer: Observer = object : Observer {

JvmClient/src/jvmMain/java/uuspaceagent/AplibCopy/NavGridCopy.java

Lines changed: 548 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package uuspaceagent.AplibCopy;
2+
3+
public class ObstacleCopy<T> {
4+
public T obstacle;
5+
public Boolean isBlocking = false;
6+
7+
/**
8+
* Wrap the given o as an Obstacle, marked initially as non-blocking.
9+
*/
10+
public ObstacleCopy(T obstacle) {
11+
this.obstacle = obstacle;
12+
}
13+
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package uuspaceagent;
2+
3+
import eu.iv4xr.framework.spatial.Vec3;
4+
5+
/**
6+
* Cubical boundary class. Can be used to check if it contains or intersects with other boundaries, points or spheres.
7+
*/
8+
public class Boundary {
9+
/**
10+
* The lower boundary of the voxel boundary
11+
*/
12+
float x, y, z;
13+
float size;
14+
15+
public Boundary(Vec3 pos, float size) {
16+
x = pos.x;
17+
y = pos.y;
18+
z = pos.z;
19+
this.size = size;
20+
//upperBounds = new Vec3(pos.x + size, pos.y + size, pos.z + size);
21+
}
22+
23+
public float size() { return size; } // Because a boundary is always cubic, we can just take the width
24+
//public float size() { return upperBounds.x - position.x; } // Because a boundary is always cubic, we can just take the width
25+
26+
public Vec3 upperBounds() { return new Vec3(x + size, y + size, z + size); }
27+
28+
public Vec3 center() { return new Vec3(x + size * 0.5f, y + size * 0.5f, z + size * 0.5f); }
29+
//public Vec3 center() { return Vec3.mul(Vec3.add(position, upperBounds), 0.5f); }
30+
31+
public Vec3 pos() { return new Vec3(x, y, z); }
32+
33+
public boolean intersects(Boundary other) {
34+
Vec3 this_upperBounds = this.upperBounds();
35+
Vec3 other_upperBounds = other.upperBounds();
36+
if (other.x > this_upperBounds.x || other_upperBounds.x < this.x)
37+
return false;
38+
if (other.y > this_upperBounds.y || other_upperBounds.y < this.y)
39+
return false;
40+
if (other.z > this_upperBounds.z || other_upperBounds.z < this.z)
41+
return false;
42+
return true;
43+
}
44+
45+
public boolean contains(Boundary other) {
46+
Vec3 this_upperBounds = this.upperBounds();
47+
Vec3 other_upperBounds = other.upperBounds();
48+
if (other.x < this.x || other_upperBounds.x > this_upperBounds.x)
49+
return false;
50+
if (other.y < this.y || other_upperBounds.y > this_upperBounds.y)
51+
return false;
52+
if (other.z < this.z || other_upperBounds.z > this_upperBounds.z)
53+
return false;
54+
return true;
55+
}
56+
public boolean contains(Boundary2 other) {
57+
Vec3 this_upperBounds = this.upperBounds();
58+
Vec3 other_upperBounds = other.upperBounds;
59+
if (other.lowerBounds.x < this.x || other_upperBounds.x > this_upperBounds.x)
60+
return false;
61+
if (other.lowerBounds.y < this.y || other_upperBounds.y > this_upperBounds.y)
62+
return false;
63+
if (other.lowerBounds.z < this.z || other_upperBounds.z > this_upperBounds.z)
64+
return false;
65+
return true;
66+
}
67+
68+
public boolean contains(Vec3 point) {
69+
Vec3 upperBounds = upperBounds();
70+
return (point.x >= x && point.x <= upperBounds.x
71+
&&
72+
point.y >= y && point.y <= upperBounds.y
73+
&&
74+
point.z >= z && point.z <= upperBounds.z);
75+
}
76+
public boolean contains(DPos3 point) {
77+
Vec3 upperBounds = upperBounds();
78+
return (point.x >= x && point.x <= upperBounds.x
79+
&&
80+
point.y >= y && point.y <= upperBounds.y
81+
&&
82+
point.z >= z && point.z <= upperBounds.z);
83+
}
84+
85+
public boolean sphereIntersects(Vec3 center, float radius) {
86+
Vec3 closest = new Vec3(center.x, center.y, center.z);
87+
88+
if (center.x < x) closest.x = x;
89+
else if(center.x > x + size) closest.x = x + size;
90+
91+
if (center.y < y) closest.y = y;
92+
else if(center.y > y + size) closest.y = y + size;
93+
94+
if (center.z < z) closest.z = z;
95+
else if(center.z > z + size) closest.z = z + size;
96+
97+
return Vec3.dist(center, closest) <= radius;
98+
}
99+
100+
public boolean sphereContains(Vec3 center, float radius) {
101+
Vec3 furthest = new Vec3(center.x, center.y, center.z);
102+
103+
if (center.x < x) furthest.x = x + size;
104+
else if(center.x > x + size) furthest.x = x;
105+
106+
if (center.y < y) furthest.y = y + size;
107+
else if(center.y > y + size) furthest.y = y;
108+
109+
if (center.z < z) furthest.z = z + size;
110+
else if(center.z > z + size) furthest.z = z;
111+
112+
return Vec3.dist(center, furthest) <= radius;
113+
}
114+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package uuspaceagent;
2+
3+
import eu.iv4xr.framework.spatial.Vec3;
4+
5+
/**
6+
* Cuboid boundary class. Can be used to check if it contains or intersects with other boundaries, points or spheres.
7+
*/
8+
public class Boundary2 {
9+
Vec3 lowerBounds, upperBounds;
10+
11+
public Boundary2(Vec3 lowerBounds, Vec3 upperBounds) {
12+
this.lowerBounds = lowerBounds;
13+
this.upperBounds = upperBounds;
14+
}
15+
16+
public boolean intersects(Boundary other) {
17+
Vec3 other_upperBounds = other.upperBounds();
18+
if (other.x > this.upperBounds.x || other_upperBounds.x < this.lowerBounds.x)
19+
return false;
20+
if (other.y > this.upperBounds.y || other_upperBounds.y < this.lowerBounds.y)
21+
return false;
22+
if (other.z > this.upperBounds.z || other_upperBounds.z < this.lowerBounds.z)
23+
return false;
24+
return true;
25+
}
26+
27+
public boolean contains(Boundary other) {
28+
Vec3 other_upperBounds = other.upperBounds();
29+
if (other.x < this.lowerBounds.x || other_upperBounds.x > this.upperBounds.x)
30+
return false;
31+
if (other.y < this.lowerBounds.y || other_upperBounds.y > this.upperBounds.y)
32+
return false;
33+
if (other.z < this.lowerBounds.z || other_upperBounds.z > this.upperBounds.z)
34+
return false;
35+
return true;
36+
}
37+
38+
public boolean contains(Vec3 point) {
39+
return (point.x >= lowerBounds.x && point.x <= upperBounds.x
40+
&&
41+
point.y >= lowerBounds.y && point.y <= upperBounds.y
42+
&&
43+
point.z >= lowerBounds.z && point.z <= upperBounds.z);
44+
}
45+
public boolean contains(DPos3 point) {
46+
return (point.x >= lowerBounds.x && point.x <= upperBounds.x
47+
&&
48+
point.y >= lowerBounds.y && point.y <= upperBounds.y
49+
&&
50+
point.z >= lowerBounds.z && point.z <= upperBounds.z);
51+
}
52+
}

JvmClient/src/jvmMain/java/uuspaceagent/DPos3.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@ public DPos3(Vec3 v) {
2828
y = (int) Math.floor(v.y) ;
2929
z = (int) Math.floor(v.z) ;
3030
}
31+
/**
32+
* @return A + B
33+
*/
34+
public static DPos3 add(DPos3 a, DPos3 b) {
35+
return new DPos3(a.x + b.x, a.y + b.y, a.z + b.z);
36+
}
37+
38+
/**
39+
* @return A - B
40+
*/
41+
public static DPos3 sub(DPos3 a, DPos3 b) {
42+
return new DPos3(a.x - b.x, a.y - b.y, a.z - b.z);
43+
}
3144

3245
@Override
3346
public boolean equals(Object o) {
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package uuspaceagent;
2+
3+
/** Constants for octree labels (not enum for less memory usage)
4+
*/
5+
public class Label {
6+
public static final byte OPEN = 0;
7+
public static final byte BLOCKED = 1;
8+
public static final byte MIXED = 2;
9+
public static final byte UNKNOWN = 3;
10+
}

JvmClient/src/jvmMain/java/uuspaceagent/NavGrid.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import eu.iv4xr.framework.mainConcepts.WorldEntity;
55
import eu.iv4xr.framework.spatial.Obstacle;
66
import eu.iv4xr.framework.spatial.Vec3;
7-
import nl.uu.cs.aplib.utils.Pair;
7+
import uuspaceagent.exploration.Explorable;
88

99
import java.util.*;
1010

@@ -58,7 +58,7 @@
5858
* could be a gaping hole in space). We can do this by maintaining a list of squares
5959
* with solid floor.
6060
*/
61-
public class NavGrid implements Navigatable<DPos3>{
61+
public class NavGrid implements Explorable<DPos3> {
6262

6363
/**
6464
* The assumed height of the player characters. It is 1.8, we conservatively
@@ -378,10 +378,23 @@ public Iterable<DPos3> neighbours(DPos3 p) {
378378
return candidates ;
379379
}
380380

381+
@Override
382+
public Iterable<DPos3> neighbours_explore(DPos3 p) {
383+
return null;
384+
}
385+
381386
@Override
382387
public float heuristic(DPos3 from, DPos3 to) {
383388
// using Manhattan distance...
384389
return CUBE_SIZE * (float) (Math.abs(to.x - from.x) + Math.abs(to.y - from.y) + Math.abs(to.z - from.z)) ;
390+
391+
// using Euclidean distance...
392+
// return CUBE_SIZE * (float) Math.sqrt((to.x - from.x) * (to.x - from.x) + (to.y - from.y) * (to.y - from.y) + (to.z - from.z) * (to.z - from.z)) ;
393+
}
394+
395+
@Override
396+
public float heuristic(DPos3 from, Vec3 to) {
397+
return CUBE_SIZE * (float) (Math.abs(to.x - from.x) + Math.abs(to.y - from.y) + Math.abs(to.z - from.z)) ;
385398
}
386399

387400
@Override
@@ -407,4 +420,17 @@ public float distance(DPos3 from, DPos3 to) {
407420
}
408421
return squareDiagonalLength ;
409422
}
423+
424+
@Override
425+
public DPos3 phantom_neighbour(DPos3 node, DPos3 real_neighbour) {
426+
return real_neighbour;
427+
}
428+
429+
@Override
430+
public boolean isUnknown(DPos3 node) {
431+
return false;
432+
}
433+
434+
@Override
435+
public void updateUnknown(Vec3 pos, float observation_radius) { }
410436
}

0 commit comments

Comments
 (0)