mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
parent
2f81f5e137
commit
2ee42a2291
1 changed files with 15 additions and 9 deletions
|
|
@ -11,11 +11,13 @@ class CollisionWorld {
|
||||||
public var octree:Octree;
|
public var octree:Octree;
|
||||||
public var entities:Array<CollisionEntity> = [];
|
public var entities:Array<CollisionEntity> = [];
|
||||||
public var dynamicEntities:Array<CollisionEntity> = [];
|
public var dynamicEntities:Array<CollisionEntity> = [];
|
||||||
public var dynamicBVH:BVHTree<CollisionEntity>;
|
public var dynamicOctree:Octree;
|
||||||
|
|
||||||
|
var dynamicEntitySet:Map<CollisionEntity, Bool> = [];
|
||||||
|
|
||||||
public function new() {
|
public function new() {
|
||||||
this.octree = new Octree();
|
this.octree = new Octree();
|
||||||
this.dynamicBVH = new BVHTree();
|
this.dynamicOctree = new Octree();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function sphereIntersection(spherecollision:SphereCollisionEntity, timeState:TimeState) {
|
public function sphereIntersection(spherecollision:SphereCollisionEntity, timeState:TimeState) {
|
||||||
|
|
@ -46,7 +48,7 @@ class CollisionWorld {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var dynSearch = dynamicBVH.boundingSearch(box);
|
var dynSearch = dynamicOctree.boundingSearch(box).map(x -> cast(x, CollisionEntity));
|
||||||
for (obj in dynSearch) {
|
for (obj in dynSearch) {
|
||||||
if (obj != spherecollision) {
|
if (obj != spherecollision) {
|
||||||
if (obj.boundingBox.collide(box) && obj.go.isCollideable)
|
if (obj.boundingBox.collide(box) && obj.go.isCollideable)
|
||||||
|
|
@ -75,14 +77,14 @@ class CollisionWorld {
|
||||||
contacts.push(entity);
|
contacts.push(entity);
|
||||||
}
|
}
|
||||||
|
|
||||||
contacts = contacts.concat(dynamicBVH.boundingSearch(box));
|
contacts = contacts.concat(dynamicOctree.boundingSearch(box, false).map(x -> cast(x, CollisionEntity)));
|
||||||
|
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function boundingSearch(bounds:Bounds, useCache:Bool = true) {
|
public function boundingSearch(bounds:Bounds, useCache:Bool = true) {
|
||||||
var contacts = this.octree.boundingSearch(bounds, useCache).map(x -> cast(x, CollisionEntity));
|
var contacts = this.octree.boundingSearch(bounds, useCache).map(x -> cast(x, CollisionEntity));
|
||||||
contacts = contacts.concat(dynamicBVH.boundingSearch(bounds));
|
contacts = contacts.concat(dynamicOctree.boundingSearch(bounds, useCache).map(x -> cast(x, CollisionEntity)));
|
||||||
return contacts;
|
return contacts;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -96,7 +98,7 @@ class CollisionWorld {
|
||||||
+ rayDirection.x * rayLength, rayStart.y
|
+ rayDirection.x * rayLength, rayStart.y
|
||||||
+ rayDirection.y * rayLength, rayStart.z
|
+ rayDirection.y * rayLength, rayStart.z
|
||||||
+ rayDirection.z * rayLength);
|
+ rayDirection.z * rayLength);
|
||||||
var objs = this.octree.boundingSearch(bounds).map(x -> cast(x, CollisionEntity));
|
var objs = this.octree.boundingSearch(bounds).concat(dynamicOctree.boundingSearch(bounds)).map(x -> cast(x, CollisionEntity));
|
||||||
var results = [];
|
var results = [];
|
||||||
for (obj in objs) {
|
for (obj in objs) {
|
||||||
results = results.concat(obj.rayCast(rayStart, rayDirection));
|
results = results.concat(obj.rayCast(rayStart, rayDirection));
|
||||||
|
|
@ -114,7 +116,8 @@ class CollisionWorld {
|
||||||
|
|
||||||
public function addMovingEntity(entity:CollisionEntity) {
|
public function addMovingEntity(entity:CollisionEntity) {
|
||||||
this.dynamicEntities.push(entity);
|
this.dynamicEntities.push(entity);
|
||||||
this.dynamicBVH.add(entity);
|
this.dynamicOctree.insert(entity);
|
||||||
|
this.dynamicEntitySet.set(entity, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeMovingEntity(entity:CollisionEntity) {
|
public function removeMovingEntity(entity:CollisionEntity) {
|
||||||
|
|
@ -122,7 +125,10 @@ class CollisionWorld {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function updateTransform(entity:CollisionEntity) {
|
public function updateTransform(entity:CollisionEntity) {
|
||||||
this.octree.update(entity);
|
if (!dynamicEntitySet.exists(entity)) {
|
||||||
this.dynamicBVH.update();
|
this.octree.update(entity);
|
||||||
|
} else {
|
||||||
|
this.dynamicOctree.update(entity);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue