fix internal edge collision somewhat, add radio button

This commit is contained in:
RandomityGuy 2021-07-05 13:47:28 +05:30
parent 37b246e034
commit 5a2b5ae471
5 changed files with 37 additions and 9 deletions

Binary file not shown.

View file

@ -95,7 +95,7 @@ class CollisionEntity implements IOctreeObject {
var localpos = position.clone();
localpos.transform(invMatrix);
var sphereBounds = new Bounds();
sphereBounds.addSpherePos(localpos.x, localpos.y, localpos.z, radius * 1.1);
sphereBounds.addSpherePos(localpos.x, localpos.y, localpos.z, radius);
var surfaces = octree.boundingSearch(sphereBounds);
var tform = transform.clone();
@ -135,6 +135,11 @@ class CollisionEntity implements IOctreeObject {
if (position.sub(closest).dot(surfacenormal) > 0) {
normal.normalize();
var supportVec = surface.support(normal, tform);
if (!(supportVec.equals(v0) || supportVec.equals(v) || supportVec.equals(v2))) {
normal = surfacenormal;
}
// We find the normal that is closest to the surface normal, sort of fixes weird edge cases of when colliding with
var testDot = normal.dot(surfacenormal);
if (testDot > bestDot) {

View file

@ -1,5 +1,6 @@
package collision;
import h3d.Matrix;
import h3d.col.Bounds;
import octree.IOctreeObject;
import h3d.Vector;
@ -101,4 +102,22 @@ class CollisionSurface implements IOctreeObject {
}
return intersections.length > 0;
}
public function support(direction:Vector, transform:Matrix) {
var furthestDistance:Float = Math.NEGATIVE_INFINITY;
var furthestVertex:Vector = new Vector();
for (v in points) {
var v2 = v.transformed(transform);
var distance:Float = v2.dot(direction);
if (distance > furthestDistance) {
furthestDistance = distance;
furthestVertex.x = v2.x;
furthestVertex.y = v2.y;
furthestVertex.z = v2.z;
}
}
return furthestVertex;
}
}

View file

@ -10,6 +10,7 @@ import src.ResourceLoader;
enum ButtonType {
Normal;
Toggle;
Radio;
}
class GuiButton extends GuiAnim {
@ -51,7 +52,7 @@ class GuiButton extends GuiAnim {
pressed = false;
}
}
if (buttonType == Toggle) {
if (buttonType == Toggle || buttonType == Radio) {
if (this.pressed) {
this.anim.currentFrame = 2;
} else {
@ -77,6 +78,9 @@ class GuiButton extends GuiAnim {
if (buttonType == Toggle) {
pressed = !pressed;
}
if (buttonType == Radio) {
pressed = true;
}
}
public override function onMouseEnter(mouseState:MouseState) {

View file

@ -140,7 +140,7 @@ class OptionsDlg extends GuiImage {
var gfx640480 = new GuiButton(loadButtonImages("data/ui/options/graf640"));
gfx640480.position = new Vector(157, -3);
gfx640480.extent = new Vector(84, 53);
gfx640480.buttonType = Toggle;
gfx640480.buttonType = Radio;
resolutionBoxes.push(gfx640480);
gfx640480.pressedAction = (sender) -> {
updateResolutionFunc(gfx640480);
@ -152,7 +152,7 @@ class OptionsDlg extends GuiImage {
var gfx800600 = new GuiButton(loadButtonImages("data/ui/options/graf800"));
gfx800600.position = new Vector(237, 0);
gfx800600.extent = new Vector(86, 51);
gfx800600.buttonType = Toggle;
gfx800600.buttonType = Radio;
resolutionBoxes.push(gfx800600);
gfx800600.pressedAction = (sender) -> {
updateResolutionFunc(gfx800600);
@ -164,7 +164,7 @@ class OptionsDlg extends GuiImage {
var gfx1024768 = new GuiButton(loadButtonImages("data/ui/options/graf1024"));
gfx1024768.position = new Vector(320, -1);
gfx1024768.extent = new Vector(94, 51);
gfx1024768.buttonType = Toggle;
gfx1024768.buttonType = Radio;
resolutionBoxes.push(gfx1024768);
gfx1024768.pressedAction = (sender) -> {
updateResolutionFunc(gfx1024768);
@ -185,7 +185,7 @@ class OptionsDlg extends GuiImage {
var gfxopengl = new GuiButton(loadButtonImages("data/ui/options/grafopgl"));
gfxopengl.position = new Vector(165, 58);
gfxopengl.extent = new Vector(97, 54);
gfxopengl.buttonType = Toggle;
gfxopengl.buttonType = Radio;
driverBoxes.push(gfxopengl);
gfxopengl.pressedAction = (sender) -> {
updateDriverFunc(gfxopengl);
@ -198,7 +198,7 @@ class OptionsDlg extends GuiImage {
var gfxd3d = new GuiButton(loadButtonImages("data/ui/options/grafdir3d"));
gfxd3d.position = new Vector(270, 59);
gfxd3d.extent = new Vector(104, 52);
gfxd3d.buttonType = Toggle;
gfxd3d.buttonType = Radio;
driverBoxes.push(gfxd3d);
gfxd3d.pressedAction = (sender) -> {
updateDriverFunc(gfxd3d);
@ -226,7 +226,7 @@ class OptionsDlg extends GuiImage {
var gfx16 = new GuiButton(loadButtonImages("data/ui/options/graf16bt"));
gfx16.position = new Vector(179, 170);
gfx16.extent = new Vector(79, 54);
gfx16.buttonType = Toggle;
gfx16.buttonType = Radio;
bitBoxes.push(gfx16);
gfx16.pressedAction = (sender) -> {
updateBitsFunc(gfx16);
@ -239,7 +239,7 @@ class OptionsDlg extends GuiImage {
var gfx32 = new GuiButton(loadButtonImages("data/ui/options/graf32bt"));
gfx32.position = new Vector(272, 174);
gfx32.extent = new Vector(84, 51);
gfx32.buttonType = Toggle;
gfx32.buttonType = Radio;
bitBoxes.push(gfx32);
gfx32.pressedAction = (sender) -> {
updateBitsFunc(gfx32);