attempted to fix mouse look being agonizing, fixed doors not rotating because at some point physics state completely overridden local transforms (to-do: expose some interface that will magically handle this mess)
This commit is contained in:
parent
3aa9a084ae
commit
a566e07756
@ -395,8 +395,8 @@
|
||||
"mouse" : {
|
||||
"visible" : true,
|
||||
"center" : false,
|
||||
"sensitivity": [ 2, 2 ],
|
||||
"smoothing": [ 0, 0 ]
|
||||
"sensitivity": [ 50, 50 ],
|
||||
"smoothing": [ 0.75, 0.75 ]
|
||||
},
|
||||
"mode" : "windowed", // fullscreen, borderless, windowed
|
||||
"icon" : "./data/textures/icon.png",
|
||||
|
||||
@ -9,11 +9,13 @@ end
|
||||
|
||||
local polarity = 1
|
||||
local state = 0
|
||||
local targetAlpha = 1
|
||||
local targetAlpha = 1.57
|
||||
local alpha = 0
|
||||
local target = Vector3f(0,0,0)
|
||||
local transform = ent:getComponent("Transform")
|
||||
local metadata = ent:getComponent("Metadata")
|
||||
local collider = ent:getComponent("PhysicsState")
|
||||
|
||||
local speed = metadata["speed"] or 1.0
|
||||
local normal = Vector3f(0,0,-1)
|
||||
if metadata["normal"] ~= nil then
|
||||
@ -62,9 +64,10 @@ local stopSoundscape = function( key )
|
||||
end
|
||||
-- on tick
|
||||
ent:bind( "tick", function(self)
|
||||
-- transform.orientation = starting:slerp( ending, math.cos(time.current() * speed) * 0.5 + 0.5 )
|
||||
rot = nil
|
||||
if state == 1 then
|
||||
alpha = alpha + time.delta() * speed
|
||||
rot = Quaternion.axisAngle( Vector3f(0, 1, 0), time.delta() * speed * polarity )
|
||||
|
||||
if alpha > targetAlpha then
|
||||
state = 2
|
||||
@ -75,6 +78,7 @@ ent:bind( "tick", function(self)
|
||||
end
|
||||
if state == 3 then
|
||||
alpha = alpha - time.delta() * speed
|
||||
rot = Quaternion.axisAngle( Vector3f(0, 1, 0), time.delta() * speed * -polarity )
|
||||
|
||||
if alpha < 0 then
|
||||
state = 0
|
||||
@ -83,8 +87,12 @@ ent:bind( "tick", function(self)
|
||||
end
|
||||
end
|
||||
|
||||
if state > 0 then
|
||||
transform.orientation = starting:slerp( ending, alpha * polarity )
|
||||
if state > 0 and rot ~= nil then
|
||||
if collider:hasBody() then
|
||||
collider:applyRotation( rot )
|
||||
else
|
||||
transform:rotate( rot )
|
||||
end
|
||||
end
|
||||
end )
|
||||
-- on use
|
||||
|
||||
@ -145,16 +145,17 @@ void client::tick() {
|
||||
auto size = client::window.getSize();
|
||||
auto current = client::window.getMousePosition();
|
||||
pod::Vector2i center = {
|
||||
client::window.getSize().x * 0.5f,
|
||||
client::window.getSize().y * 0.5f,
|
||||
size.x * 0.5f,
|
||||
size.y * 0.5f,
|
||||
};
|
||||
client::window.setMousePosition( center );
|
||||
client::window.setCursorVisible(false);
|
||||
|
||||
|
||||
#if UF_INPUT_USE_ENUM_MOUSE
|
||||
uf::inputs::kbm::states::Mouse = {
|
||||
(current.x - center.x) / (float) size.x,
|
||||
(current.y - center.y) / (float) size.y,
|
||||
(float) (current.x - center.x) / (float) size.x,
|
||||
(float) (current.y - center.y) / (float) size.y,
|
||||
};
|
||||
#else
|
||||
uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
#include <uf/utils/string/string.h>
|
||||
#include <uf/utils/math/vector.h>
|
||||
|
||||
#define UF_INPUT_USE_ENUM_MOUSE 1
|
||||
//#define UF_INPUT_USE_ENUM_MOUSE 1
|
||||
|
||||
namespace uf {
|
||||
namespace console {
|
||||
|
||||
@ -303,7 +303,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
this->addHook( "window:Mouse.Click", [&](pod::payloads::windowMouseClick& payload){
|
||||
if ( metadata.world ) return;
|
||||
if ( !metadata.box.min && !metadata.box.max ) return;
|
||||
//if ( !metadata.box.min && !metadata.box.max ) return;
|
||||
if ((metadata.box.min.x > metadata.box.max.x)||(metadata.box.min.y > metadata.box.max.y)) return;
|
||||
|
||||
// uf::Object* manager = (uf::Object*) this->globalFindByName("Gui Manager");
|
||||
// pod::Vector2ui guiSize = manager ? manager->getComponent<ext::GuiManagerBehavior::Metadata>().size : pod::Vector2ui{ uf::renderer::settings::width, uf::renderer::settings::height };
|
||||
@ -381,7 +382,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
|
||||
|
||||
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){
|
||||
if ( metadata.world ) return;
|
||||
if ( !metadata.box.min && !metadata.box.max ) return;
|
||||
//if ( !metadata.box.min && !metadata.box.max ) return;
|
||||
if ((metadata.box.min.x > metadata.box.max.x)||(metadata.box.min.y > metadata.box.max.y)) return;
|
||||
|
||||
// uf::Object* manager = (uf::Object*) this->globalFindByName("Gui Manager");
|
||||
// pod::Vector2ui guiSize = manager ? manager->getComponent<ext::GuiManagerBehavior::Metadata>().size : pod::Vector2ui{ uf::renderer::settings::width, uf::renderer::settings::height };
|
||||
|
||||
@ -97,11 +97,8 @@ void ext::PlayerBehavior::initialize( uf::Object& self ) {
|
||||
const pod::Vector2ui deadZone{0, 0};
|
||||
if ( (payload.mouse.delta.x == 0 && payload.mouse.delta.y == 0) || !metadata.system.control ) return;
|
||||
|
||||
pod::Vector2f delta = {
|
||||
(float) metadata.mouse.sensitivity.x * (abs(payload.mouse.delta.x) < deadZone.x ? 0 : payload.mouse.delta.x) / payload.window.size.x,
|
||||
(float) metadata.mouse.sensitivity.y * (abs(payload.mouse.delta.y) < deadZone.y ? 0 : payload.mouse.delta.y) / payload.window.size.y
|
||||
};
|
||||
metadata.camera.queued += delta;
|
||||
if (abs(payload.mouse.delta.x) > deadZone.x) metadata.mouse.accum.x += payload.mouse.delta.x * uf::physics::time::delta / payload.window.size.x;
|
||||
if (abs(payload.mouse.delta.y) > deadZone.y) metadata.mouse.accum.y += payload.mouse.delta.y * uf::physics::time::delta / payload.window.size.y;
|
||||
});
|
||||
#endif
|
||||
#endif
|
||||
@ -479,21 +476,25 @@ void ext::PlayerBehavior::tick( uf::Object& self ) {
|
||||
const auto& mouseDelta = uf::inputs::kbm::states::Mouse;
|
||||
bool shouldnt = (mouseDelta.x == 0 && mouseDelta.y == 0) || !metadata.system.control || metadata.camera.fixed;
|
||||
if ( !shouldnt ) {
|
||||
pod::Vector2f delta = {
|
||||
(float) metadata.mouse.sensitivity.x * (abs(mouseDelta.x) < deadZone.x ? 0 : mouseDelta.x),
|
||||
(float) metadata.mouse.sensitivity.y * (abs(mouseDelta.y) < deadZone.y ? 0 : mouseDelta.y)
|
||||
};
|
||||
metadata.camera.queued += delta;
|
||||
if (abs(mouseDelta.x) > deadZone.x) metadata.mouse.accum.x += mouseDelta.x * uf::physics::time::delta;
|
||||
if (abs(mouseDelta.y) > deadZone.y) metadata.mouse.accum.y += mouseDelta.y * uf::physics::time::delta;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if ( !metadata.camera.fixed ) {
|
||||
if ( metadata.mouse.accum.x != 0 && metadata.mouse.accum.y != 0 ) {
|
||||
metadata.camera.queued.x += metadata.mouse.accum.x * metadata.mouse.sensitivity.x;
|
||||
metadata.camera.queued.y += metadata.mouse.accum.y * metadata.mouse.sensitivity.y;
|
||||
|
||||
metadata.mouse.accum = {};
|
||||
}
|
||||
|
||||
|
||||
if ( metadata.camera.queued.x != 0 || metadata.camera.queued.y != 0 ) {
|
||||
auto lookDelta = metadata.camera.queued;
|
||||
if ( abs(lookDelta.x) > uf::physics::time::delta / metadata.mouse.smoothing.x ) lookDelta.x *= uf::physics::time::delta * metadata.mouse.smoothing.x;
|
||||
if ( abs(lookDelta.y) > uf::physics::time::delta / metadata.mouse.smoothing.y ) lookDelta.y *= uf::physics::time::delta * metadata.mouse.smoothing.y;
|
||||
metadata.camera.queued -= lookDelta;
|
||||
metadata.camera.queued -= lookDelta * metadata.mouse.smoothing;
|
||||
//metadata.camera.queued = {};
|
||||
|
||||
if ( lookDelta.x != 0 ) {
|
||||
if ( metadata.camera.invert.x ) lookDelta.x *= -1;
|
||||
metadata.camera.limit.current.x += lookDelta.x;
|
||||
|
||||
@ -50,7 +50,9 @@ namespace ext {
|
||||
} camera;
|
||||
struct {
|
||||
pod::Vector2f sensitivity = {1,1};
|
||||
pod::Vector2f smoothing = {10,10};
|
||||
pod::Vector2f smoothing = {0,0};
|
||||
|
||||
pod::Vector2f accum = {};
|
||||
} mouse;
|
||||
struct {
|
||||
struct {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user