diff --git a/src/CameraController.hx b/src/CameraController.hx index 6236682e..f529b48b 100644 --- a/src/CameraController.hx +++ b/src/CameraController.hx @@ -27,6 +27,7 @@ import h3d.Vector; import hxsl.Types.Matrix; import h3d.scene.Scene; import src.Gamepad; +import src.MarbleGame; enum CameraMode { FreeOrbit; @@ -63,6 +64,10 @@ class CameraController extends Object { var _ignoreCursor:Bool = false; + var hasXInput:Bool = false; + var hasYInput:Bool = false; + var dt:Float; + public function new(marble:Marble) { super(); this.marble = marble; @@ -127,8 +132,8 @@ class CameraController extends Object { } } - var factor = isTouch ? Util.lerp(1 / 250, 1 / 25, - Settings.controlsSettings.cameraSensitivity) : Util.lerp(1 / 2500, 1 / 100, Settings.controlsSettings.cameraSensitivity); + var factor = isTouch ? Util.lerp(1 / 25, 1 / 15, + Settings.controlsSettings.cameraSensitivity) : Util.lerp(1 / 750, 1 / 50, Settings.controlsSettings.cameraSensitivity); // CameraPitch += deltaposY * factor; // CameraYaw += deltaposX * factor; @@ -136,6 +141,20 @@ class CameraController extends Object { nextCameraPitch = CameraPitch + deltaposY * factor; nextCameraYaw = CameraYaw + deltaposX * factor; + if (Math.abs(deltaposX) > 0.001) + hasXInput = true; + else + hasXInput = false; + if (Math.abs(deltaposY) > 0.001) + hasYInput = true; + else + hasYInput = false; + + if (MarbleGame.instance.touchInput.cameraInput.pressed) { + hasXInput = true; + hasYInput = true; + } + // var rotX = deltaposX * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2; // var rotY = deltaposY * 0.001 * Settings.controlsSettings.cameraSensitivity * Math.PI * 2; // CameraYaw -= rotX; @@ -191,8 +210,9 @@ class CameraController extends Object { // this.level.scene.camera.target = marblePosition.add(cameraVerticalTranslation); // camera.position.add(cameraVerticalTranslation); var camera = level.scene.camera; + this.dt = dt; - var lerpt = Math.pow(0.5, dt / 0.032); // Math.min(1, 1 - Math.pow(0.6, dt / 0.032)); // hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600)); + var lerpt = 1 - Math.pow(0.5, dt / 0.016); // Math.min(1, 1 - Math.pow(0.6, dt / 0.032)); // hxd.Math.min(1, 1 - Math.pow(0.6, dt * 600)); var cameraPitchDelta = (Key.isDown(Settings.controlsSettings.camBackward) ? 1 : 0) - (Key.isDown(Settings.controlsSettings.camForward) ? 1 : 0) @@ -232,7 +252,7 @@ class CameraController extends Object { deltaX = deltaNew; // Center the pitch - if (!Settings.controlsSettings.alwaysFreeLook && !Key.isDown(Settings.controlsSettings.freelook)) { + if (!Settings.controlsSettings.alwaysFreeLook && !Key.isDown(Settings.controlsSettings.freelook) && !(hasXInput || hasYInput)) { var rescaledY = deltaY; if (rescaledY <= 0.0) rescaledY = 0.4 - rescaledY * -0.75; @@ -252,6 +272,11 @@ class CameraController extends Object { deltaY = movePitchSpeed; } + if (!MarbleGame.instance.touchInput.cameraInput.pressed) { + hasXInput = false; + hasYInput = false; + } + nextCameraYaw += deltaX; nextCameraPitch += deltaY; nextCameraPitch = Math.max(-Math.PI / 2 + Math.PI / 4, Math.min(Math.PI / 2 - 0.0001, nextCameraPitch)); diff --git a/src/Renderer.hx b/src/Renderer.hx index 0522c855..3c9d6eb0 100644 --- a/src/Renderer.hx +++ b/src/Renderer.hx @@ -1,5 +1,6 @@ package src; +import h3d.pass.PassList; import hxd.Window; import src.ResourceLoader; import shaders.GammaRamp; @@ -147,17 +148,28 @@ class Renderer extends h3d.scene.Renderer { if (!cubemapPass || Settings.optionsSettings.reflectionDetail >= 4) { var glowObjects = get("glow"); if (!glowObjects.isEmpty()) { - if (dirtyBuffers) { - ctx.engine.pushTarget(glowBuffer); - ctx.engine.clear(0); - renderPass(defaultPass, glowObjects); - bloomPass(ctx); - ctx.engine.popTarget(); + var frustum = ctx.camera.frustum; + var hasOne = false; + for (obj in glowObjects) { + var bounds = obj.obj.getBounds(); + if (frustum.hasBounds(bounds)) { + hasOne = true; + break; + } + } + if (hasOne) { + if (dirtyBuffers) { + ctx.engine.pushTarget(glowBuffer); + ctx.engine.clear(0); + renderPass(defaultPass, glowObjects); + bloomPass(ctx); + ctx.engine.popTarget(); + } + copyPass.shader.texture = growBufferTemps[0]; + copyPass.pass.blend(One, One); + copyPass.pass.depth(false, Always); + copyPass.render(); } - copyPass.shader.texture = growBufferTemps[0]; - copyPass.pass.blend(One, One); - copyPass.pass.depth(false, Always); - copyPass.render(); } } if (!cubemapPass) diff --git a/src/Settings.hx b/src/Settings.hx index 6c41da5a..b2756292 100644 --- a/src/Settings.hx +++ b/src/Settings.hx @@ -126,7 +126,7 @@ class Settings { marbleCategoryIndex: 0, marbleSkin: "base", marbleModel: "data/shapes/balls/marble01.dts", - marbleShader: "Default", + marbleShader: "ClassicGlassPureSphere", rewindEnabled: false, rewindTimescale: 1, reflectionDetail: 3, @@ -412,7 +412,7 @@ class Settings { optionsSettings.marbleCategoryIndex = 0; } if (optionsSettings.marbleShader == null) { - optionsSettings.marbleShader = "Default"; + optionsSettings.marbleShader = "ClassicGlassPureSphere"; } if (controlsSettings.blast == null) { controlsSettings.blast = Key.E; diff --git a/src/gui/AboutMenuOptionsGui.hx b/src/gui/AboutMenuOptionsGui.hx index 35990406..78c743e8 100644 --- a/src/gui/AboutMenuOptionsGui.hx +++ b/src/gui/AboutMenuOptionsGui.hx @@ -24,7 +24,12 @@ class AboutMenuOptionsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/AchievementsGui.hx b/src/gui/AchievementsGui.hx index a12c9729..85e6d9bc 100644 --- a/src/gui/AchievementsGui.hx +++ b/src/gui/AchievementsGui.hx @@ -25,7 +25,12 @@ class AchievementsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/DifficultySelectGui.hx b/src/gui/DifficultySelectGui.hx index e72d57b0..d20aa96e 100644 --- a/src/gui/DifficultySelectGui.hx +++ b/src/gui/DifficultySelectGui.hx @@ -25,7 +25,12 @@ class DifficultySelectGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/EndGameGui.hx b/src/gui/EndGameGui.hx index 609b5ea6..e297e829 100644 --- a/src/gui/EndGameGui.hx +++ b/src/gui/EndGameGui.hx @@ -39,7 +39,12 @@ class EndGameGui extends GuiImage { return [normal, hover, pressed]; } + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/ExitGameDlg.hx b/src/gui/ExitGameDlg.hx index 5ec53654..4a165e55 100644 --- a/src/gui/ExitGameDlg.hx +++ b/src/gui/ExitGameDlg.hx @@ -32,7 +32,12 @@ class ExitGameDlg extends GuiImage { return [normal, hover, pressed]; } + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/HelpCreditsGui.hx b/src/gui/HelpCreditsGui.hx index e49dc7c8..b567f92b 100644 --- a/src/gui/HelpCreditsGui.hx +++ b/src/gui/HelpCreditsGui.hx @@ -33,7 +33,12 @@ class HelpCreditsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/InputOptionsGui.hx b/src/gui/InputOptionsGui.hx index 2b2012c0..19c2ca8e 100644 --- a/src/gui/InputOptionsGui.hx +++ b/src/gui/InputOptionsGui.hx @@ -24,7 +24,12 @@ class InputOptionsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/KeyBindingsGui.hx b/src/gui/KeyBindingsGui.hx index cd791ff5..41411473 100644 --- a/src/gui/KeyBindingsGui.hx +++ b/src/gui/KeyBindingsGui.hx @@ -84,7 +84,12 @@ class KeyBindingsGui extends GuiImage { } } + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/LevelSelectGui.hx b/src/gui/LevelSelectGui.hx index 17ed2e08..10502183 100644 --- a/src/gui/LevelSelectGui.hx +++ b/src/gui/LevelSelectGui.hx @@ -99,7 +99,12 @@ class LevelSelectGui extends GuiImage { this.vertSizing = Height; this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/MainMenuGui.hx b/src/gui/MainMenuGui.hx index 711f400b..fbef0040 100644 --- a/src/gui/MainMenuGui.hx +++ b/src/gui/MainMenuGui.hx @@ -29,7 +29,12 @@ class MainMenuGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/MarblePickerGui.hx b/src/gui/MarblePickerGui.hx index 565b3624..9cbafda6 100644 --- a/src/gui/MarblePickerGui.hx +++ b/src/gui/MarblePickerGui.hx @@ -245,7 +245,12 @@ class MarblePickerGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/MiscOptionsGui.hx b/src/gui/MiscOptionsGui.hx index b24db32d..e366dfda 100644 --- a/src/gui/MiscOptionsGui.hx +++ b/src/gui/MiscOptionsGui.hx @@ -23,7 +23,12 @@ class MiscOptionsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/OptionsListGui.hx b/src/gui/OptionsListGui.hx index a5ea3352..7bc1a7a6 100644 --- a/src/gui/OptionsListGui.hx +++ b/src/gui/OptionsListGui.hx @@ -23,7 +23,12 @@ class OptionsListGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/PlayGui.hx b/src/gui/PlayGui.hx index d70ded2f..eceac881 100644 --- a/src/gui/PlayGui.hx +++ b/src/gui/PlayGui.hx @@ -111,7 +111,12 @@ class PlayGui { playGuiCtrlOuter.horizSizing = Width; playGuiCtrlOuter.vertSizing = Height; + #if hl var wnd = hxd.Window.getInstance(); + #end + #if js + var wnd = MarbleGame.instance.scene2d; + #end var safeVerMargin = 1 + (wnd.height * 0.15) / 2; var safeHorMargin = 1 + (wnd.width * 0.15) / 2; @@ -181,7 +186,12 @@ class PlayGui { } public function initTimer() { + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var safeVerMargin = 1 + (scene2d.height * 0.15) / 2; var timerCtrl = new GuiImage(ResourceLoader.getResource('data/ui/game/timebackdrop0.png', ResourceLoader.getImage, this.imageResources).toTile()); @@ -287,7 +297,12 @@ class PlayGui { } public function initGemCounter() { + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var safeVerMargin = 1 + (scene2d.height * 0.15) / 2; var gemBox = new GuiControl(); @@ -374,7 +389,12 @@ class PlayGui { } function initPowerupBox() { + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var safeVerMargin = 1 + (scene2d.height * 0.15) / 2; var powerupImgs = [ @@ -526,7 +546,12 @@ class PlayGui { } function initBlastBar() { + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var safeVerMargin = 1 + (scene2d.height * 0.15) / 2; blastBar = new GuiControl(); diff --git a/src/gui/ReplayCenterGui.hx b/src/gui/ReplayCenterGui.hx index 206153a5..17e3dc85 100644 --- a/src/gui/ReplayCenterGui.hx +++ b/src/gui/ReplayCenterGui.hx @@ -29,7 +29,12 @@ class ReplayCenterGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/TouchCtrlsEditGui.hx b/src/gui/TouchCtrlsEditGui.hx index 6e758523..5502119a 100644 --- a/src/gui/TouchCtrlsEditGui.hx +++ b/src/gui/TouchCtrlsEditGui.hx @@ -21,7 +21,12 @@ class TouchCtrlsEditGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/VersionGui.hx b/src/gui/VersionGui.hx index 789db995..5cfc6da4 100644 --- a/src/gui/VersionGui.hx +++ b/src/gui/VersionGui.hx @@ -19,7 +19,12 @@ class VersionGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/gui/VideoOptionsGui.hx b/src/gui/VideoOptionsGui.hx index 3695374a..e78f72c7 100644 --- a/src/gui/VideoOptionsGui.hx +++ b/src/gui/VideoOptionsGui.hx @@ -23,7 +23,12 @@ class VideoOptionsGui extends GuiImage { this.position = new Vector(); this.extent = new Vector(640, 480); + #if hl var scene2d = hxd.Window.getInstance(); + #end + #if js + var scene2d = MarbleGame.instance.scene2d; + #end var offsetX = (scene2d.width - 1280) / 2; var offsetY = (scene2d.height - 720) / 2; diff --git a/src/touch/CameraInput.hx b/src/touch/CameraInput.hx index 149bb2b0..75925edd 100644 --- a/src/touch/CameraInput.hx +++ b/src/touch/CameraInput.hx @@ -13,6 +13,7 @@ class CameraInput { var identifier:Int = -1; public var enabled = false; + public var pressed = false; var added = false; @@ -35,7 +36,7 @@ class CameraInput { this.collider.horizSizing = Width; this.collider.vertSizing = Height; - var pressed = false; + pressed = false; var prevMouse = new Vector(0, 0); interactive.onPush = (e) -> { diff --git a/src/touch/TouchInput.hx b/src/touch/TouchInput.hx index 3fc0e430..f5085884 100644 --- a/src/touch/TouchInput.hx +++ b/src/touch/TouchInput.hx @@ -34,7 +34,7 @@ class TouchEventState { } class TouchInput { - var cameraInput:CameraInput; + public var cameraInput:CameraInput; public var movementInput:MovementInput;