mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-02-27 08:31:00 +00:00
gui scaling for js, fix camera thing again, kinda speed up collision a bit
This commit is contained in:
parent
3c14d1b029
commit
4a0e506fde
10 changed files with 46 additions and 29 deletions
BIN
marblegame.hl
BIN
marblegame.hl
Binary file not shown.
|
|
@ -212,13 +212,20 @@ class CameraController extends Object {
|
|||
var closeness = 0.1;
|
||||
var rayCastOrigin = marblePosition.add(level.currentUp.multiply(marble._radius));
|
||||
|
||||
var processedShapes = [];
|
||||
for (i in 0...3) {
|
||||
var rayCastDirection = camera.pos.sub(rayCastOrigin);
|
||||
rayCastDirection = rayCastDirection.add(rayCastDirection.normalized().multiply(2));
|
||||
|
||||
var results = level.collisionWorld.rayCast(rayCastOrigin, rayCastDirection);
|
||||
|
||||
var firstHit = results[0];
|
||||
var firstHit:octree.OctreeIntersection = null;
|
||||
for (result in results) {
|
||||
if (!processedShapes.contains(result.object) && (firstHit == null || (result.distance < firstHit.distance))) {
|
||||
firstHit = result;
|
||||
processedShapes.push(result.object);
|
||||
}
|
||||
}
|
||||
|
||||
if (firstHit != null) {
|
||||
if (firstHit.distance < CameraDistance) {
|
||||
|
|
@ -236,16 +243,18 @@ class CameraController extends Object {
|
|||
camera.pos = projected.toVector().add(normal.multiply(-closeness));
|
||||
|
||||
var forwardVec = marblePosition.sub(camera.pos).normalized();
|
||||
var rightVec = camera.up.cross(forwardVec);
|
||||
var rightVec = camera.up.cross(forwardVec).normalized();
|
||||
var upVec = forwardVec.cross(rightVec);
|
||||
|
||||
var cameraQuat = new Quat();
|
||||
cameraQuat.initDirection(camera.target.sub(camera.pos).normalized());
|
||||
|
||||
camera.target = marblePosition.add(upVec.multiply(0.3));
|
||||
camera.up = upVec;
|
||||
|
||||
continue;
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if (oob) {
|
||||
|
|
|
|||
|
|
@ -737,8 +737,7 @@ class Marble extends GameObject {
|
|||
for (obj in foundObjs) {
|
||||
var radius = _radius;
|
||||
|
||||
var invMatrix = obj.transform.clone();
|
||||
invMatrix.invert();
|
||||
var invMatrix = @:privateAccess obj.invTransform;
|
||||
var localpos = position.clone();
|
||||
localpos.transform(invMatrix);
|
||||
|
||||
|
|
@ -809,16 +808,6 @@ class Marble extends GameObject {
|
|||
// }
|
||||
// }
|
||||
|
||||
if (this.controllable) {
|
||||
for (interior in pathedInteriors) {
|
||||
// interior.popTickState();
|
||||
// interior.pushTickState();
|
||||
interior.setStopped(false);
|
||||
// interior.recomputeVelocity(piTime + 0.032, 0.032);
|
||||
// interior.update(piTime, timeStep);
|
||||
}
|
||||
}
|
||||
|
||||
_bounceYet = false;
|
||||
|
||||
var contactTime = 0.0;
|
||||
|
|
|
|||
|
|
@ -83,9 +83,8 @@ class MarbleGame {
|
|||
}
|
||||
}
|
||||
if (canvas != null) {
|
||||
var wnd = Window.getInstance();
|
||||
var mouseState:MouseState = {
|
||||
position: new Vector(wnd.mouseX, wnd.mouseY)
|
||||
position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY)
|
||||
}
|
||||
canvas.update(dt, mouseState);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package src;
|
||||
|
||||
import gui.Canvas;
|
||||
import src.AudioManager;
|
||||
import hxd.Key;
|
||||
import src.MarbleGame;
|
||||
|
|
@ -195,8 +196,15 @@ class Settings {
|
|||
// @:privateAccess Window.getInstance().window.center();
|
||||
Window.getInstance().addResizeEvent(() -> {
|
||||
var wnd = Window.getInstance();
|
||||
Settings.optionsSettings.screenWidth = wnd.width;
|
||||
Settings.optionsSettings.screenHeight = wnd.height;
|
||||
var zoomRatio = 1.0;
|
||||
#if js
|
||||
zoomRatio = js.Browser.window.devicePixelRatio;
|
||||
#end
|
||||
Settings.optionsSettings.screenWidth = cast wnd.width / zoomRatio;
|
||||
Settings.optionsSettings.screenHeight = cast wnd.height / zoomRatio;
|
||||
|
||||
MarbleGame.canvas.scene2d.scaleMode = Zoom(zoomRatio);
|
||||
|
||||
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,6 +24,9 @@ class CollisionEntity implements IOctreeObject {
|
|||
public var velocity:Vector = new Vector();
|
||||
|
||||
public var transform:Matrix;
|
||||
|
||||
var invTransform:Matrix;
|
||||
|
||||
public var go:GameObject;
|
||||
|
||||
public var userData:Int;
|
||||
|
|
@ -33,6 +36,7 @@ class CollisionEntity implements IOctreeObject {
|
|||
this.octree = new Octree();
|
||||
this.surfaces = [];
|
||||
this.transform = Matrix.I();
|
||||
this.invTransform = Matrix.I();
|
||||
}
|
||||
|
||||
public function addSurface(surface:CollisionSurface) {
|
||||
|
|
@ -46,6 +50,7 @@ class CollisionEntity implements IOctreeObject {
|
|||
if (this.transform == transform)
|
||||
return;
|
||||
this.transform = transform;
|
||||
this.invTransform = transform.getInverse();
|
||||
generateBoundingBox();
|
||||
}
|
||||
|
||||
|
|
@ -60,8 +65,7 @@ class CollisionEntity implements IOctreeObject {
|
|||
}
|
||||
|
||||
public function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData> {
|
||||
var invMatrix = transform.clone();
|
||||
invMatrix.invert();
|
||||
var invMatrix = invTransform;
|
||||
var rStart = rayOrigin.clone();
|
||||
rStart.transform(invMatrix);
|
||||
var rDir = rayDirection.transformed3x3(invMatrix);
|
||||
|
|
@ -71,7 +75,7 @@ class CollisionEntity implements IOctreeObject {
|
|||
i.point.transform(transform);
|
||||
i.normal.transform3x3(transform);
|
||||
i.normal.normalize();
|
||||
iData.push({point: i.point, normal: i.normal});
|
||||
iData.push({point: i.point, normal: i.normal, object: i.object});
|
||||
}
|
||||
return iData;
|
||||
}
|
||||
|
|
@ -89,8 +93,9 @@ class CollisionEntity implements IOctreeObject {
|
|||
var velocity = collisionEntity.velocity;
|
||||
var radius = collisionEntity.radius;
|
||||
|
||||
var invMatrix = transform.clone();
|
||||
invMatrix.invert();
|
||||
var invMatrix = invTransform;
|
||||
if (this.velocity.lengthSq() != 0)
|
||||
invMatrix = transform.getInverse();
|
||||
var sphereBounds = new Bounds();
|
||||
var localPos = position.clone();
|
||||
localPos.transform(invMatrix);
|
||||
|
|
|
|||
|
|
@ -90,7 +90,7 @@ class CollisionSurface implements IOctreeObject {
|
|||
var ip = rayOrigin.add(rayDirection.multiply(t));
|
||||
ip.w = 1;
|
||||
if (t >= 0 && Collision.PointInTriangle(ip, p1, p2, p3)) {
|
||||
intersections.push({point: ip, normal: n});
|
||||
intersections.push({point: ip, normal: n, object: cast this});
|
||||
}
|
||||
i += 3;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,17 +106,23 @@ class GuiControl {
|
|||
parentRect = this.parent.getRenderRectangle();
|
||||
rect.position = parentRect.position.add(this.position);
|
||||
}
|
||||
|
||||
var scaleFactor = 1.0;
|
||||
#if js
|
||||
scaleFactor = 1 / js.Browser.window.devicePixelRatio;
|
||||
#end
|
||||
|
||||
if (this.horizSizing == HorizSizing.Width) {
|
||||
if (this.parent != null)
|
||||
rect.extent.x = parentRect.extent.x * (this.extent.x / parent.extent.x);
|
||||
else
|
||||
rect.extent.x = Window.getInstance().width;
|
||||
rect.extent.x = Window.getInstance().width * scaleFactor;
|
||||
}
|
||||
if (this.vertSizing == VertSizing.Height) {
|
||||
if (this.parent != null)
|
||||
rect.extent.y = parentRect.extent.y * (this.extent.y / parent.extent.y);
|
||||
else
|
||||
rect.extent.y = Window.getInstance().height;
|
||||
rect.extent.y = Window.getInstance().height * scaleFactor;
|
||||
}
|
||||
|
||||
if (this.horizSizing == HorizSizing.Center) {
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import h3d.col.Bounds;
|
|||
typedef RayIntersectionData = {
|
||||
var point:Vector;
|
||||
var normal:Vector;
|
||||
var object:IOctreeObject;
|
||||
}
|
||||
|
||||
interface IOctreeObject extends IOctreeElement {
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ class OctreeNode implements IOctreeElement {
|
|||
for (intersection in iSecs) {
|
||||
var intersectionData = new OctreeIntersection();
|
||||
intersectionData.distance = rayOrigin.distance(intersection.point);
|
||||
intersectionData.object = obj;
|
||||
intersectionData.object = intersection.object;
|
||||
intersectionData.point = intersection.point;
|
||||
intersectionData.normal = intersection.normal;
|
||||
intersections.push(intersectionData);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue