From c4234c3c636d6f6d1f567e3df1d440c662105c1d Mon Sep 17 00:00:00 2001 From: RandomityGuy <31925790+RandomityGuy@users.noreply.github.com> Date: Sat, 17 Dec 2022 20:19:56 +0530 Subject: [PATCH] use the hitbox of the rotated marble hitbox --- src/Marble.hx | 10 ++++++---- src/MarbleWorld.hx | 3 --- src/collision/BoxCollisionEntity.hx | 21 +++++++++++++++++++++ src/collision/SphereCollisionEntity.hx | 23 +++++++++++++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) diff --git a/src/Marble.hx b/src/Marble.hx index 97a6331b..5001071e 100644 --- a/src/Marble.hx +++ b/src/Marble.hx @@ -1517,11 +1517,12 @@ class Marble extends GameObject { quat.multiply(quat, rot); this.setRotationQuat(quat); + var totMatrix = quat.toMatrix(); + totMatrix.setPosition(newPos); + this.setPosition(newPos.x, newPos.y, newPos.z); - var tform = this.collider.transform; - tform.setPosition(new Vector(newPos.x, newPos.y, newPos.z)); - this.collider.setTransform(tform); + this.collider.setTransform(totMatrix); this.collider.velocity = this.velocity; if (this.heldPowerup != null && m.powerup && !this.level.outOfBounds) { @@ -1606,7 +1607,8 @@ class Marble extends GameObject { var expectedOmega = this.level.replay.currentPlaybackFrame.marbleAngularVelocity.clone(); this.setPosition(expectedPos.x, expectedPos.y, expectedPos.z); - var tform = this.collider.transform; + var tform = this.level.replay.currentPlaybackFrame.marbleOrientation.toMatrix(); + tform.setPosition(new Vector(expectedPos.x, expectedPos.y, expectedPos.z)); this.collider.setTransform(tform); this.velocity = expectedVel; diff --git a/src/MarbleWorld.hx b/src/MarbleWorld.hx index 3670ecd6..1f25d60f 100644 --- a/src/MarbleWorld.hx +++ b/src/MarbleWorld.hx @@ -1481,9 +1481,6 @@ class MarbleWorld extends Scheduler { var contacts = marble.contactEntities; var inside = []; - var contactsphere = new SphereCollisionEntity(marble); - contactsphere.velocity = new Vector(); - for (contact in contacts) { if (contact.go != marble) { if (contact.go is DtsObject) { diff --git a/src/collision/BoxCollisionEntity.hx b/src/collision/BoxCollisionEntity.hx index d90d67d3..cfa4861c 100644 --- a/src/collision/BoxCollisionEntity.hx +++ b/src/collision/BoxCollisionEntity.hx @@ -1,5 +1,6 @@ package collision; +import src.MarbleGame; import src.TimeState; import h3d.Matrix; import src.GameObject; @@ -12,6 +13,8 @@ import h3d.col.Bounds; class BoxCollisionEntity extends CollisionEntity { var bounds:Bounds; + var _dbgEntity:h3d.scene.Mesh; + public function new(bounds:Bounds, go:GameObject) { super(go); this.bounds = bounds; @@ -21,6 +24,24 @@ class BoxCollisionEntity extends CollisionEntity { public override function generateBoundingBox() { this.boundingBox = bounds.clone(); this.boundingBox.transform(this.transform); + // if (_dbgEntity == null) { + // var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true); + // cube.addNormals(); + // cube.addUVs(); + // _dbgEntity = new h3d.scene.Mesh(cube); + // _dbgEntity.material.mainPass.wireframe = true; + // _dbgEntity.setTransform(transform); + // MarbleGame.instance.scene.addChild(_dbgEntity); + // } else { + // _dbgEntity.setTransform(transform); + // } + } + + public override function setTransform(transform:Matrix) { + super.setTransform(transform); + // if (_dbgEntity != null) { + // _dbgEntity.setTransform(transform); + // } } public override function rayCast(rayOrigin:Vector, rayDirection:Vector) { diff --git a/src/collision/SphereCollisionEntity.hx b/src/collision/SphereCollisionEntity.hx index 585bd569..49b0fbf2 100644 --- a/src/collision/SphereCollisionEntity.hx +++ b/src/collision/SphereCollisionEntity.hx @@ -1,16 +1,20 @@ package collision; +import h3d.Matrix; import src.TimeState; import src.Marble; import h3d.col.Ray; import h3d.Vector; import h3d.col.Sphere; import h3d.col.Bounds; +import src.MarbleGame; class SphereCollisionEntity extends CollisionEntity { public var radius:Float; public var marble:Marble; + var _dbgEntity:h3d.scene.Mesh; + public function new(marble:Marble) { super(cast marble); this.marble = marble; @@ -24,6 +28,25 @@ class SphereCollisionEntity extends CollisionEntity { var pos = transform.getPosition(); boundingBox.addSpherePos(pos.x, pos.y, pos.z, radius); this.boundingBox = boundingBox; + + // if (_dbgEntity == null) { + // var cube = new h3d.prim.Cube(this.boundingBox.xSize, this.boundingBox.ySize, this.boundingBox.zSize, true); + // cube.addNormals(); + // cube.addUVs(); + // _dbgEntity = new h3d.scene.Mesh(cube); + // _dbgEntity.material.mainPass.wireframe = true; + // _dbgEntity.setTransform(transform); + // MarbleGame.instance.scene.addChild(_dbgEntity); + // } else { + // _dbgEntity.setTransform(transform); + // } + } + + public override function setTransform(transform:Matrix) { + super.setTransform(transform); + // if (_dbgEntity != null) { + // _dbgEntity.setTransform(transform); + // } } public override function rayCast(rayOrigin:Vector, rayDirection:Vector) {