mirror of
https://github.com/RandomityGuy/MBHaxe.git
synced 2026-04-27 13:11:42 +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 closeness = 0.1;
|
||||||
var rayCastOrigin = marblePosition.add(level.currentUp.multiply(marble._radius));
|
var rayCastOrigin = marblePosition.add(level.currentUp.multiply(marble._radius));
|
||||||
|
|
||||||
|
var processedShapes = [];
|
||||||
for (i in 0...3) {
|
for (i in 0...3) {
|
||||||
var rayCastDirection = camera.pos.sub(rayCastOrigin);
|
var rayCastDirection = camera.pos.sub(rayCastOrigin);
|
||||||
rayCastDirection = rayCastDirection.add(rayCastDirection.normalized().multiply(2));
|
rayCastDirection = rayCastDirection.add(rayCastDirection.normalized().multiply(2));
|
||||||
|
|
||||||
var results = level.collisionWorld.rayCast(rayCastOrigin, rayCastDirection);
|
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 != null) {
|
||||||
if (firstHit.distance < CameraDistance) {
|
if (firstHit.distance < CameraDistance) {
|
||||||
|
|
@ -236,16 +243,18 @@ class CameraController extends Object {
|
||||||
camera.pos = projected.toVector().add(normal.multiply(-closeness));
|
camera.pos = projected.toVector().add(normal.multiply(-closeness));
|
||||||
|
|
||||||
var forwardVec = marblePosition.sub(camera.pos).normalized();
|
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 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.target = marblePosition.add(upVec.multiply(0.3));
|
||||||
camera.up = upVec;
|
camera.up = upVec;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oob) {
|
if (oob) {
|
||||||
|
|
|
||||||
|
|
@ -737,8 +737,7 @@ class Marble extends GameObject {
|
||||||
for (obj in foundObjs) {
|
for (obj in foundObjs) {
|
||||||
var radius = _radius;
|
var radius = _radius;
|
||||||
|
|
||||||
var invMatrix = obj.transform.clone();
|
var invMatrix = @:privateAccess obj.invTransform;
|
||||||
invMatrix.invert();
|
|
||||||
var localpos = position.clone();
|
var localpos = position.clone();
|
||||||
localpos.transform(invMatrix);
|
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;
|
_bounceYet = false;
|
||||||
|
|
||||||
var contactTime = 0.0;
|
var contactTime = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,8 @@ class MarbleGame {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (canvas != null) {
|
if (canvas != null) {
|
||||||
var wnd = Window.getInstance();
|
|
||||||
var mouseState:MouseState = {
|
var mouseState:MouseState = {
|
||||||
position: new Vector(wnd.mouseX, wnd.mouseY)
|
position: new Vector(canvas.scene2d.mouseX, canvas.scene2d.mouseY)
|
||||||
}
|
}
|
||||||
canvas.update(dt, mouseState);
|
canvas.update(dt, mouseState);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package src;
|
package src;
|
||||||
|
|
||||||
|
import gui.Canvas;
|
||||||
import src.AudioManager;
|
import src.AudioManager;
|
||||||
import hxd.Key;
|
import hxd.Key;
|
||||||
import src.MarbleGame;
|
import src.MarbleGame;
|
||||||
|
|
@ -195,8 +196,15 @@ class Settings {
|
||||||
// @:privateAccess Window.getInstance().window.center();
|
// @:privateAccess Window.getInstance().window.center();
|
||||||
Window.getInstance().addResizeEvent(() -> {
|
Window.getInstance().addResizeEvent(() -> {
|
||||||
var wnd = Window.getInstance();
|
var wnd = Window.getInstance();
|
||||||
Settings.optionsSettings.screenWidth = wnd.width;
|
var zoomRatio = 1.0;
|
||||||
Settings.optionsSettings.screenHeight = wnd.height;
|
#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);
|
MarbleGame.canvas.render(MarbleGame.canvas.scene2d);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,9 @@ class CollisionEntity implements IOctreeObject {
|
||||||
public var velocity:Vector = new Vector();
|
public var velocity:Vector = new Vector();
|
||||||
|
|
||||||
public var transform:Matrix;
|
public var transform:Matrix;
|
||||||
|
|
||||||
|
var invTransform:Matrix;
|
||||||
|
|
||||||
public var go:GameObject;
|
public var go:GameObject;
|
||||||
|
|
||||||
public var userData:Int;
|
public var userData:Int;
|
||||||
|
|
@ -33,6 +36,7 @@ class CollisionEntity implements IOctreeObject {
|
||||||
this.octree = new Octree();
|
this.octree = new Octree();
|
||||||
this.surfaces = [];
|
this.surfaces = [];
|
||||||
this.transform = Matrix.I();
|
this.transform = Matrix.I();
|
||||||
|
this.invTransform = Matrix.I();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addSurface(surface:CollisionSurface) {
|
public function addSurface(surface:CollisionSurface) {
|
||||||
|
|
@ -46,6 +50,7 @@ class CollisionEntity implements IOctreeObject {
|
||||||
if (this.transform == transform)
|
if (this.transform == transform)
|
||||||
return;
|
return;
|
||||||
this.transform = transform;
|
this.transform = transform;
|
||||||
|
this.invTransform = transform.getInverse();
|
||||||
generateBoundingBox();
|
generateBoundingBox();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -60,8 +65,7 @@ class CollisionEntity implements IOctreeObject {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData> {
|
public function rayCast(rayOrigin:Vector, rayDirection:Vector):Array<RayIntersectionData> {
|
||||||
var invMatrix = transform.clone();
|
var invMatrix = invTransform;
|
||||||
invMatrix.invert();
|
|
||||||
var rStart = rayOrigin.clone();
|
var rStart = rayOrigin.clone();
|
||||||
rStart.transform(invMatrix);
|
rStart.transform(invMatrix);
|
||||||
var rDir = rayDirection.transformed3x3(invMatrix);
|
var rDir = rayDirection.transformed3x3(invMatrix);
|
||||||
|
|
@ -71,7 +75,7 @@ class CollisionEntity implements IOctreeObject {
|
||||||
i.point.transform(transform);
|
i.point.transform(transform);
|
||||||
i.normal.transform3x3(transform);
|
i.normal.transform3x3(transform);
|
||||||
i.normal.normalize();
|
i.normal.normalize();
|
||||||
iData.push({point: i.point, normal: i.normal});
|
iData.push({point: i.point, normal: i.normal, object: i.object});
|
||||||
}
|
}
|
||||||
return iData;
|
return iData;
|
||||||
}
|
}
|
||||||
|
|
@ -89,8 +93,9 @@ class CollisionEntity implements IOctreeObject {
|
||||||
var velocity = collisionEntity.velocity;
|
var velocity = collisionEntity.velocity;
|
||||||
var radius = collisionEntity.radius;
|
var radius = collisionEntity.radius;
|
||||||
|
|
||||||
var invMatrix = transform.clone();
|
var invMatrix = invTransform;
|
||||||
invMatrix.invert();
|
if (this.velocity.lengthSq() != 0)
|
||||||
|
invMatrix = transform.getInverse();
|
||||||
var sphereBounds = new Bounds();
|
var sphereBounds = new Bounds();
|
||||||
var localPos = position.clone();
|
var localPos = position.clone();
|
||||||
localPos.transform(invMatrix);
|
localPos.transform(invMatrix);
|
||||||
|
|
|
||||||
|
|
@ -90,7 +90,7 @@ class CollisionSurface implements IOctreeObject {
|
||||||
var ip = rayOrigin.add(rayDirection.multiply(t));
|
var ip = rayOrigin.add(rayDirection.multiply(t));
|
||||||
ip.w = 1;
|
ip.w = 1;
|
||||||
if (t >= 0 && Collision.PointInTriangle(ip, p1, p2, p3)) {
|
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;
|
i += 3;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -106,17 +106,23 @@ class GuiControl {
|
||||||
parentRect = this.parent.getRenderRectangle();
|
parentRect = this.parent.getRenderRectangle();
|
||||||
rect.position = parentRect.position.add(this.position);
|
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.horizSizing == HorizSizing.Width) {
|
||||||
if (this.parent != null)
|
if (this.parent != null)
|
||||||
rect.extent.x = parentRect.extent.x * (this.extent.x / parent.extent.x);
|
rect.extent.x = parentRect.extent.x * (this.extent.x / parent.extent.x);
|
||||||
else
|
else
|
||||||
rect.extent.x = Window.getInstance().width;
|
rect.extent.x = Window.getInstance().width * scaleFactor;
|
||||||
}
|
}
|
||||||
if (this.vertSizing == VertSizing.Height) {
|
if (this.vertSizing == VertSizing.Height) {
|
||||||
if (this.parent != null)
|
if (this.parent != null)
|
||||||
rect.extent.y = parentRect.extent.y * (this.extent.y / parent.extent.y);
|
rect.extent.y = parentRect.extent.y * (this.extent.y / parent.extent.y);
|
||||||
else
|
else
|
||||||
rect.extent.y = Window.getInstance().height;
|
rect.extent.y = Window.getInstance().height * scaleFactor;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.horizSizing == HorizSizing.Center) {
|
if (this.horizSizing == HorizSizing.Center) {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import h3d.col.Bounds;
|
||||||
typedef RayIntersectionData = {
|
typedef RayIntersectionData = {
|
||||||
var point:Vector;
|
var point:Vector;
|
||||||
var normal:Vector;
|
var normal:Vector;
|
||||||
|
var object:IOctreeObject;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IOctreeObject extends IOctreeElement {
|
interface IOctreeObject extends IOctreeElement {
|
||||||
|
|
|
||||||
|
|
@ -143,7 +143,7 @@ class OctreeNode implements IOctreeElement {
|
||||||
for (intersection in iSecs) {
|
for (intersection in iSecs) {
|
||||||
var intersectionData = new OctreeIntersection();
|
var intersectionData = new OctreeIntersection();
|
||||||
intersectionData.distance = rayOrigin.distance(intersection.point);
|
intersectionData.distance = rayOrigin.distance(intersection.point);
|
||||||
intersectionData.object = obj;
|
intersectionData.object = intersection.object;
|
||||||
intersectionData.point = intersection.point;
|
intersectionData.point = intersection.point;
|
||||||
intersectionData.normal = intersection.normal;
|
intersectionData.normal = intersection.normal;
|
||||||
intersections.push(intersectionData);
|
intersections.push(intersectionData);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue