mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-12 13:56:28 +00:00
fix bad collision normals
This commit is contained in:
parent
506cb50960
commit
266a29afc4
7 changed files with 69 additions and 28 deletions
|
|
@ -1 +1 @@
|
|||
by16:font%2Farial.fntaoy3:veri1y4:timei1659272757y4:hashy40:dc7f069d72e0d1b6b7edfd5b9e6af9c22f9c641cy3:outy23:tmp%2Ffont%2Farial.bfntghy21:font%2FMarkerFelt.fntaoR1i1R2i1672239219R3y40:eb239790210478413cc111da54400b3d38aba041R5y28:tmp%2Ffont%2FMarkerFelt.bfntghy27:font%2FLucida%20Console.fntaoR1i1R2i1672239804R3y40:b56483df1b8f3d8472856b51459d5ce8f3cdfa09R5y34:tmp%2Ffont%2FLucida%20Console.bfntghy16:font%2FEXPON.fntaoR1i1R2i1659272757R3y40:ba8ecd55d9475ee0f9d20c9a5189fe6a9c9ff727R5y23:tmp%2Ffont%2FEXPON.bfntghy21:font%2FDomCasualD.fntaoR1i1R2i1659272757R3y40:ea40ffbf969a51d3e653a3d09b450143a814c7eeR5y28:tmp%2Ffont%2FDomCasualD.bfntghy23:font%2FArial%20Bold.fntaoR1i1R2i1659272757R3y40:dce4a5edf92262f9ea5540d55271f8423683d064R5y30:tmp%2Ffont%2FArial%20Bold.bfntghy23:data%2Ffont%2Farial.fntaoR1i1R2i1659272757R3R4R5y37:data%2Ftmp%2Fdata%2Ffont%2Farial.bfntghy28:data%2Ffont%2FMarkerFelt.fntaoR1i1R2i1672239219R3R8R5y42:data%2Ftmp%2Fdata%2Ffont%2FMarkerFelt.bfntghy34:data%2Ffont%2FLucida%20Console.fntaoR1i1R2i1672239804R3R11R5y48:data%2Ftmp%2Fdata%2Ffont%2FLucida%20Console.bfntghy23:data%2Ffont%2FEXPON.fntaoR1i1R2i1659272757R3R14R5y37:data%2Ftmp%2Fdata%2Ffont%2FEXPON.bfntghy28:data%2Ffont%2FDomCasualD.fntaoR1i1R2i1659272757R3R17R5y42:data%2Ftmp%2Fdata%2Ffont%2FDomCasualD.bfntghy30:data%2Ffont%2FArial%20Bold.fntaoR1i1R2i1659272757R3R20R5y44:data%2Ftmp%2Fdata%2Ffont%2FArial%20Bold.bfntghh
|
||||
by30:data%2Ffont%2FArial%20Bold.fntaoy3:outy44:data%2Ftmp%2Fdata%2Ffont%2FArial%20Bold.bfnty3:veri1y4:hashy40:dce4a5edf92262f9ea5540d55271f8423683d064y4:timei1659272757ghy21:font%2FDomCasualD.fntaoR1y28:tmp%2Ffont%2FDomCasualD.bfntR3i1R4y40:ea40ffbf969a51d3e653a3d09b450143a814c7eeR6i1659272757ghy16:font%2FEXPON.fntaoR1y23:tmp%2Ffont%2FEXPON.bfntR3i1R4y40:ba8ecd55d9475ee0f9d20c9a5189fe6a9c9ff727R6i1659272757ghy27:font%2FLucida%20Console.fntaoR1y34:tmp%2Ffont%2FLucida%20Console.bfntR3i1R4y40:b56483df1b8f3d8472856b51459d5ce8f3cdfa09R6i1675969447ghy23:font%2FArial%20Bold.fntaoR1y30:tmp%2Ffont%2FArial%20Bold.bfntR3i1R4R5R6i1659272757ghy28:data%2Ffont%2FMarkerFelt.fntaoR1y42:data%2Ftmp%2Fdata%2Ffont%2FMarkerFelt.bfntR3i1R4y40:eb239790210478413cc111da54400b3d38aba041R6i1675969447ghy16:font%2Farial.fntaoR1y23:tmp%2Ffont%2Farial.bfntR3i1R4y40:dc7f069d72e0d1b6b7edfd5b9e6af9c22f9c641cR6i1659272757ghy28:data%2Ffont%2FDomCasualD.fntaoR1y42:data%2Ftmp%2Fdata%2Ffont%2FDomCasualD.bfntR3i1R4R9R6i1659272757ghy34:data%2Ffont%2FLucida%20Console.fntaoR1y48:data%2Ftmp%2Fdata%2Ffont%2FLucida%20Console.bfntR3i1R4R15R6i1675969447ghy21:font%2FMarkerFelt.fntaoR1y28:tmp%2Ffont%2FMarkerFelt.bfntR3i1R4R20R6i1675969447ghy23:data%2Ffont%2FEXPON.fntaoR1y37:data%2Ftmp%2Fdata%2Ffont%2FEXPON.bfntR3i1R4R12R6i1659272757ghy23:data%2Ffont%2Farial.fntaoR1y37:data%2Ftmp%2Fdata%2Ffont%2Farial.bfntR3i1R4R23R6i1659272757ghh
|
||||
32
src/Debug.hx
32
src/Debug.hx
|
|
@ -1,8 +1,40 @@
|
|||
package src;
|
||||
|
||||
import src.MarbleGame;
|
||||
import h3d.Vector;
|
||||
|
||||
@:publicFields
|
||||
class Debug {
|
||||
static var timeScale:Float = 1.0;
|
||||
static var wireFrame:Bool = false;
|
||||
static var drawBounds:Bool = false;
|
||||
|
||||
static var _triangles:Array<h3d.col.Point> = [];
|
||||
|
||||
static var debugTriangles:h3d.scene.Mesh;
|
||||
|
||||
public static function update() {
|
||||
if (_triangles.length != 0 && drawBounds) {
|
||||
var prim = new h3d.prim.Polygon(_triangles.copy());
|
||||
if (debugTriangles != null) {
|
||||
debugTriangles.remove();
|
||||
}
|
||||
debugTriangles = new h3d.scene.Mesh(prim, h3d.mat.Material.create());
|
||||
prim.addUVs();
|
||||
prim.addNormals();
|
||||
MarbleGame.instance.scene.addChild(debugTriangles);
|
||||
_triangles = [];
|
||||
} else {
|
||||
if (debugTriangles != null) {
|
||||
debugTriangles.remove();
|
||||
debugTriangles = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static function drawTriangle(p1:Vector, p2:Vector, p3:Vector) {
|
||||
_triangles.push(p3.toPoint());
|
||||
_triangles.push(p2.toPoint());
|
||||
_triangles.push(p1.toPoint());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1006,6 +1006,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);
|
||||
|
||||
|
|
@ -1032,7 +1034,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);
|
||||
|
|
|
|||
|
|
@ -176,6 +176,7 @@ class MarbleGame {
|
|||
world = null;
|
||||
return;
|
||||
}
|
||||
Debug.update();
|
||||
if (Util.isTouchDevice()) {
|
||||
touchInput.update();
|
||||
}
|
||||
|
|
@ -224,7 +225,9 @@ class MarbleGame {
|
|||
exitGameDlg = new ExitGameDlg((sender) -> {
|
||||
canvas.popDialog(exitGameDlg);
|
||||
if (world.isRecording) {
|
||||
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {quitMission();}));
|
||||
MarbleGame.canvas.pushDialog(new ReplayNameDlg(() -> {
|
||||
quitMission();
|
||||
}));
|
||||
} else {
|
||||
quitMission();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -684,7 +684,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);
|
||||
interior.isCollideable = hasCollision;
|
||||
|
|
@ -809,7 +810,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)));
|
||||
|
|
@ -183,7 +185,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