mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2025-10-30 08:11:25 +00:00
fix bad collision normals
This commit is contained in:
parent
c4ae0a4933
commit
26b1aad189
5 changed files with 33 additions and 26 deletions
|
|
@ -773,6 +773,8 @@ class Marble extends GameObject {
|
|||
var invMatrix = @:privateAccess obj.invTransform;
|
||||
if (obj.go is PathedInterior)
|
||||
invMatrix = obj.transform.getInverse();
|
||||
var invTform = invMatrix.clone();
|
||||
invTform.transpose();
|
||||
var localpos = position.clone();
|
||||
localpos.transform(invMatrix);
|
||||
|
||||
|
|
@ -824,7 +826,7 @@ class Marble extends GameObject {
|
|||
|
||||
var i = 0;
|
||||
while (i < surface.indices.length) {
|
||||
var verts = surface.transformTriangle(i, obj.transform, @:privateAccess obj._transformKey);
|
||||
var verts = surface.transformTriangle(i, obj.transform, invTform, @:privateAccess obj._transformKey);
|
||||
// var v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
||||
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ class MarbleGame {
|
|||
world = null;
|
||||
return;
|
||||
}
|
||||
Debug.update();
|
||||
if (Util.isTouchDevice()) {
|
||||
touchInput.update();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -559,7 +559,8 @@ class MarbleWorld extends Scheduler {
|
|||
var tmp = new Matrix();
|
||||
interiorRotation.toMatrix(tmp);
|
||||
mat.multiply3x4(mat, tmp);
|
||||
mat.setPosition(interiorPosition);
|
||||
var tmat = Matrix.T(interiorPosition.x, interiorPosition.y, interiorPosition.z);
|
||||
mat.multiply(mat, tmat);
|
||||
|
||||
interior.setTransform(mat);
|
||||
onFinish();
|
||||
|
|
@ -647,7 +648,8 @@ class MarbleWorld extends Scheduler {
|
|||
var tmp = new Matrix();
|
||||
shapeRotation.toMatrix(tmp);
|
||||
mat.multiply3x4(mat, tmp);
|
||||
mat.setPosition(shapePosition);
|
||||
var tmat = Matrix.T(shapePosition.x, shapePosition.y, shapePosition.z);
|
||||
mat.multiply(mat, tmat);
|
||||
|
||||
this.addDtsObject(shape, () -> {
|
||||
shape.setTransform(mat);
|
||||
|
|
|
|||
|
|
@ -73,26 +73,26 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
|||
if (this.transform.equal(transform))
|
||||
return;
|
||||
// Speedup
|
||||
if (Util.mat3x3equal(this.transform, transform)) {
|
||||
var oldPos = this.transform.getPosition();
|
||||
var newPos = transform.getPosition();
|
||||
this.transform.setPosition(newPos);
|
||||
this.invTransform.setPosition(newPos.multiply(-1));
|
||||
if (this.boundingBox == null)
|
||||
generateBoundingBox();
|
||||
else {
|
||||
this.boundingBox.xMin += newPos.x - oldPos.x;
|
||||
this.boundingBox.xMax += newPos.x - oldPos.x;
|
||||
this.boundingBox.yMin += newPos.y - oldPos.y;
|
||||
this.boundingBox.yMax += newPos.y - oldPos.y;
|
||||
this.boundingBox.zMin += newPos.z - oldPos.z;
|
||||
this.boundingBox.zMax += newPos.z - oldPos.z;
|
||||
}
|
||||
} else {
|
||||
this.transform.load(transform);
|
||||
this.invTransform = transform.getInverse();
|
||||
generateBoundingBox();
|
||||
}
|
||||
// if (Util.mat3x3equal(this.transform, transform)) {
|
||||
// var oldPos = this.transform.getPosition();
|
||||
// var newPos = transform.getPosition();
|
||||
// this.transform.setPosition(newPos);
|
||||
// this.invTransform.setPosition(newPos.multiply(-1));
|
||||
// if (this.boundingBox == null)
|
||||
// generateBoundingBox();
|
||||
// else {
|
||||
// this.boundingBox.xMin += newPos.x - oldPos.x;
|
||||
// this.boundingBox.xMax += newPos.x - oldPos.x;
|
||||
// this.boundingBox.yMin += newPos.y - oldPos.y;
|
||||
// this.boundingBox.yMax += newPos.y - oldPos.y;
|
||||
// this.boundingBox.zMin += newPos.z - oldPos.z;
|
||||
// this.boundingBox.zMax += newPos.z - oldPos.z;
|
||||
// }
|
||||
// } else {
|
||||
this.transform.load(transform);
|
||||
this.invTransform = transform.getInverse();
|
||||
generateBoundingBox();
|
||||
// }
|
||||
_transformKey++;
|
||||
}
|
||||
|
||||
|
|
@ -169,6 +169,8 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
|||
var sphereRadius = new Vector(radius * invScale.x, radius * invScale.y, radius * invScale.z);
|
||||
sphereBounds.addSpherePos(localPos.x, localPos.y, localPos.z, Math.max(Math.max(sphereRadius.x, sphereRadius.y), sphereRadius.z) * 1.1);
|
||||
var surfaces = bvh == null ? octree.boundingSearch(sphereBounds).map(x -> cast x) : bvh.boundingSearch(sphereBounds);
|
||||
var invtform = invMatrix.clone();
|
||||
invtform.transpose();
|
||||
|
||||
var tform = transform.clone();
|
||||
// tform.setPosition(tform.getPosition().add(this.velocity.multiply(timeState.dt)));
|
||||
|
|
@ -195,7 +197,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
|||
|
||||
var i = 0;
|
||||
while (i < surface.indices.length) {
|
||||
var verts = surface.transformTriangle(i, tform, this._transformKey);
|
||||
var verts = surface.transformTriangle(i, tform, invtform, this._transformKey);
|
||||
// var v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
||||
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ class CollisionSurface implements IOctreeObject implements IBVHObject {
|
|||
return furthestVertex;
|
||||
}
|
||||
|
||||
public function transformTriangle(idx:Int, tform:Matrix, key:Int) {
|
||||
public function transformTriangle(idx:Int, tform:Matrix, invtform:Matrix, key:Int) {
|
||||
if (_transformedPoints == null) {
|
||||
_transformedPoints = points.copy();
|
||||
}
|
||||
|
|
@ -133,7 +133,7 @@ class CollisionSurface implements IOctreeObject implements IBVHObject {
|
|||
var p3 = indices[idx + 2];
|
||||
if (transformKeys[p1] != key) {
|
||||
_transformedPoints[p1] = points[p1].transformed(tform);
|
||||
_transformedNormals[p1] = normals[p1].transformed3x3(tform).normalized();
|
||||
_transformedNormals[p1] = normals[p1].transformed3x3(invtform).normalized();
|
||||
transformKeys[p1] = key;
|
||||
}
|
||||
if (transformKeys[p2] != key) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue