mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-05-10 19:41:39 +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;
|
var invMatrix = @:privateAccess obj.invTransform;
|
||||||
if (obj.go is PathedInterior)
|
if (obj.go is PathedInterior)
|
||||||
invMatrix = obj.transform.getInverse();
|
invMatrix = obj.transform.getInverse();
|
||||||
|
var invTform = invMatrix.clone();
|
||||||
|
invTform.transpose();
|
||||||
var localpos = position.clone();
|
var localpos = position.clone();
|
||||||
localpos.transform(invMatrix);
|
localpos.transform(invMatrix);
|
||||||
|
|
||||||
|
|
@ -824,7 +826,7 @@ class Marble extends GameObject {
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < surface.indices.length) {
|
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 v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||||
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
||||||
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
||||||
|
|
|
||||||
|
|
@ -163,6 +163,7 @@ class MarbleGame {
|
||||||
world = null;
|
world = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Debug.update();
|
||||||
if (Util.isTouchDevice()) {
|
if (Util.isTouchDevice()) {
|
||||||
touchInput.update();
|
touchInput.update();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -559,7 +559,8 @@ class MarbleWorld extends Scheduler {
|
||||||
var tmp = new Matrix();
|
var tmp = new Matrix();
|
||||||
interiorRotation.toMatrix(tmp);
|
interiorRotation.toMatrix(tmp);
|
||||||
mat.multiply3x4(mat, 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);
|
interior.setTransform(mat);
|
||||||
onFinish();
|
onFinish();
|
||||||
|
|
@ -647,7 +648,8 @@ class MarbleWorld extends Scheduler {
|
||||||
var tmp = new Matrix();
|
var tmp = new Matrix();
|
||||||
shapeRotation.toMatrix(tmp);
|
shapeRotation.toMatrix(tmp);
|
||||||
mat.multiply3x4(mat, 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, () -> {
|
this.addDtsObject(shape, () -> {
|
||||||
shape.setTransform(mat);
|
shape.setTransform(mat);
|
||||||
|
|
|
||||||
|
|
@ -73,26 +73,26 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
if (this.transform.equal(transform))
|
if (this.transform.equal(transform))
|
||||||
return;
|
return;
|
||||||
// Speedup
|
// Speedup
|
||||||
if (Util.mat3x3equal(this.transform, transform)) {
|
// if (Util.mat3x3equal(this.transform, transform)) {
|
||||||
var oldPos = this.transform.getPosition();
|
// var oldPos = this.transform.getPosition();
|
||||||
var newPos = transform.getPosition();
|
// var newPos = transform.getPosition();
|
||||||
this.transform.setPosition(newPos);
|
// this.transform.setPosition(newPos);
|
||||||
this.invTransform.setPosition(newPos.multiply(-1));
|
// this.invTransform.setPosition(newPos.multiply(-1));
|
||||||
if (this.boundingBox == null)
|
// if (this.boundingBox == null)
|
||||||
generateBoundingBox();
|
// generateBoundingBox();
|
||||||
else {
|
// else {
|
||||||
this.boundingBox.xMin += newPos.x - oldPos.x;
|
// this.boundingBox.xMin += newPos.x - oldPos.x;
|
||||||
this.boundingBox.xMax += newPos.x - oldPos.x;
|
// this.boundingBox.xMax += newPos.x - oldPos.x;
|
||||||
this.boundingBox.yMin += newPos.y - oldPos.y;
|
// this.boundingBox.yMin += newPos.y - oldPos.y;
|
||||||
this.boundingBox.yMax += newPos.y - oldPos.y;
|
// this.boundingBox.yMax += newPos.y - oldPos.y;
|
||||||
this.boundingBox.zMin += newPos.z - oldPos.z;
|
// this.boundingBox.zMin += newPos.z - oldPos.z;
|
||||||
this.boundingBox.zMax += newPos.z - oldPos.z;
|
// this.boundingBox.zMax += newPos.z - oldPos.z;
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
this.transform.load(transform);
|
this.transform.load(transform);
|
||||||
this.invTransform = transform.getInverse();
|
this.invTransform = transform.getInverse();
|
||||||
generateBoundingBox();
|
generateBoundingBox();
|
||||||
}
|
// }
|
||||||
_transformKey++;
|
_transformKey++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -169,6 +169,8 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
var sphereRadius = new Vector(radius * invScale.x, radius * invScale.y, radius * invScale.z);
|
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);
|
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 surfaces = bvh == null ? octree.boundingSearch(sphereBounds).map(x -> cast x) : bvh.boundingSearch(sphereBounds);
|
||||||
|
var invtform = invMatrix.clone();
|
||||||
|
invtform.transpose();
|
||||||
|
|
||||||
var tform = transform.clone();
|
var tform = transform.clone();
|
||||||
// tform.setPosition(tform.getPosition().add(this.velocity.multiply(timeState.dt)));
|
// tform.setPosition(tform.getPosition().add(this.velocity.multiply(timeState.dt)));
|
||||||
|
|
@ -195,7 +197,7 @@ class CollisionEntity implements IOctreeObject implements IBVHObject {
|
||||||
|
|
||||||
var i = 0;
|
var i = 0;
|
||||||
while (i < surface.indices.length) {
|
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 v0 = surface.points[surface.indices[i]].transformed(tform);
|
||||||
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
// var v = surface.points[surface.indices[i + 1]].transformed(tform);
|
||||||
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
// var v2 = surface.points[surface.indices[i + 2]].transformed(tform);
|
||||||
|
|
|
||||||
|
|
@ -121,7 +121,7 @@ class CollisionSurface implements IOctreeObject implements IBVHObject {
|
||||||
return furthestVertex;
|
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) {
|
if (_transformedPoints == null) {
|
||||||
_transformedPoints = points.copy();
|
_transformedPoints = points.copy();
|
||||||
}
|
}
|
||||||
|
|
@ -133,7 +133,7 @@ class CollisionSurface implements IOctreeObject implements IBVHObject {
|
||||||
var p3 = indices[idx + 2];
|
var p3 = indices[idx + 2];
|
||||||
if (transformKeys[p1] != key) {
|
if (transformKeys[p1] != key) {
|
||||||
_transformedPoints[p1] = points[p1].transformed(tform);
|
_transformedPoints[p1] = points[p1].transformed(tform);
|
||||||
_transformedNormals[p1] = normals[p1].transformed3x3(tform).normalized();
|
_transformedNormals[p1] = normals[p1].transformed3x3(invtform).normalized();
|
||||||
transformKeys[p1] = key;
|
transformKeys[p1] = key;
|
||||||
}
|
}
|
||||||
if (transformKeys[p2] != key) {
|
if (transformKeys[p2] != key) {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue