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" : {
|
"mouse" : {
|
||||||
"visible" : true,
|
"visible" : true,
|
||||||
"center" : false,
|
"center" : false,
|
||||||
"sensitivity": [ 2, 2 ],
|
"sensitivity": [ 50, 50 ],
|
||||||
"smoothing": [ 0, 0 ]
|
"smoothing": [ 0.75, 0.75 ]
|
||||||
},
|
},
|
||||||
"mode" : "windowed", // fullscreen, borderless, windowed
|
"mode" : "windowed", // fullscreen, borderless, windowed
|
||||||
"icon" : "./data/textures/icon.png",
|
"icon" : "./data/textures/icon.png",
|
||||||
|
|||||||
@ -9,11 +9,13 @@ end
|
|||||||
|
|
||||||
local polarity = 1
|
local polarity = 1
|
||||||
local state = 0
|
local state = 0
|
||||||
local targetAlpha = 1
|
local targetAlpha = 1.57
|
||||||
local alpha = 0
|
local alpha = 0
|
||||||
local target = Vector3f(0,0,0)
|
local target = Vector3f(0,0,0)
|
||||||
local transform = ent:getComponent("Transform")
|
local transform = ent:getComponent("Transform")
|
||||||
local metadata = ent:getComponent("Metadata")
|
local metadata = ent:getComponent("Metadata")
|
||||||
|
local collider = ent:getComponent("PhysicsState")
|
||||||
|
|
||||||
local speed = metadata["speed"] or 1.0
|
local speed = metadata["speed"] or 1.0
|
||||||
local normal = Vector3f(0,0,-1)
|
local normal = Vector3f(0,0,-1)
|
||||||
if metadata["normal"] ~= nil then
|
if metadata["normal"] ~= nil then
|
||||||
@ -62,9 +64,10 @@ local stopSoundscape = function( key )
|
|||||||
end
|
end
|
||||||
-- on tick
|
-- on tick
|
||||||
ent:bind( "tick", function(self)
|
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
|
if state == 1 then
|
||||||
alpha = alpha + time.delta() * speed
|
alpha = alpha + time.delta() * speed
|
||||||
|
rot = Quaternion.axisAngle( Vector3f(0, 1, 0), time.delta() * speed * polarity )
|
||||||
|
|
||||||
if alpha > targetAlpha then
|
if alpha > targetAlpha then
|
||||||
state = 2
|
state = 2
|
||||||
@ -75,6 +78,7 @@ ent:bind( "tick", function(self)
|
|||||||
end
|
end
|
||||||
if state == 3 then
|
if state == 3 then
|
||||||
alpha = alpha - time.delta() * speed
|
alpha = alpha - time.delta() * speed
|
||||||
|
rot = Quaternion.axisAngle( Vector3f(0, 1, 0), time.delta() * speed * -polarity )
|
||||||
|
|
||||||
if alpha < 0 then
|
if alpha < 0 then
|
||||||
state = 0
|
state = 0
|
||||||
@ -83,8 +87,12 @@ ent:bind( "tick", function(self)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if state > 0 then
|
if state > 0 and rot ~= nil then
|
||||||
transform.orientation = starting:slerp( ending, alpha * polarity )
|
if collider:hasBody() then
|
||||||
|
collider:applyRotation( rot )
|
||||||
|
else
|
||||||
|
transform:rotate( rot )
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end )
|
end )
|
||||||
-- on use
|
-- on use
|
||||||
|
|||||||
@ -145,16 +145,17 @@ void client::tick() {
|
|||||||
auto size = client::window.getSize();
|
auto size = client::window.getSize();
|
||||||
auto current = client::window.getMousePosition();
|
auto current = client::window.getMousePosition();
|
||||||
pod::Vector2i center = {
|
pod::Vector2i center = {
|
||||||
client::window.getSize().x * 0.5f,
|
size.x * 0.5f,
|
||||||
client::window.getSize().y * 0.5f,
|
size.y * 0.5f,
|
||||||
};
|
};
|
||||||
client::window.setMousePosition( center );
|
client::window.setMousePosition( center );
|
||||||
client::window.setCursorVisible(false);
|
client::window.setCursorVisible(false);
|
||||||
|
|
||||||
|
|
||||||
#if UF_INPUT_USE_ENUM_MOUSE
|
#if UF_INPUT_USE_ENUM_MOUSE
|
||||||
uf::inputs::kbm::states::Mouse = {
|
uf::inputs::kbm::states::Mouse = {
|
||||||
(current.x - center.x) / (float) size.x,
|
(float) (current.x - center.x) / (float) size.x,
|
||||||
(current.y - center.y) / (float) size.y,
|
(float) (current.y - center.y) / (float) size.y,
|
||||||
};
|
};
|
||||||
#else
|
#else
|
||||||
uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{
|
uf::hooks.call("window:Mouse.Moved", pod::payloads::windowMouseMoved{
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
#include <uf/utils/string/string.h>
|
#include <uf/utils/string/string.h>
|
||||||
#include <uf/utils/math/vector.h>
|
#include <uf/utils/math/vector.h>
|
||||||
|
|
||||||
#define UF_INPUT_USE_ENUM_MOUSE 1
|
//#define UF_INPUT_USE_ENUM_MOUSE 1
|
||||||
|
|
||||||
namespace uf {
|
namespace uf {
|
||||||
namespace console {
|
namespace console {
|
||||||
|
|||||||
@ -303,7 +303,8 @@ void ext::GuiBehavior::initialize( uf::Object& self ) {
|
|||||||
|
|
||||||
this->addHook( "window:Mouse.Click", [&](pod::payloads::windowMouseClick& payload){
|
this->addHook( "window:Mouse.Click", [&](pod::payloads::windowMouseClick& payload){
|
||||||
if ( metadata.world ) return;
|
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");
|
// 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 };
|
// 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){
|
this->addHook( "window:Mouse.Moved", [&](pod::payloads::windowMouseMoved& payload){
|
||||||
if ( metadata.world ) return;
|
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");
|
// 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 };
|
// 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};
|
const pod::Vector2ui deadZone{0, 0};
|
||||||
if ( (payload.mouse.delta.x == 0 && payload.mouse.delta.y == 0) || !metadata.system.control ) return;
|
if ( (payload.mouse.delta.x == 0 && payload.mouse.delta.y == 0) || !metadata.system.control ) return;
|
||||||
|
|
||||||
pod::Vector2f 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;
|
||||||
(float) metadata.mouse.sensitivity.x * (abs(payload.mouse.delta.x) < deadZone.x ? 0 : payload.mouse.delta.x) / 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;
|
||||||
(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;
|
|
||||||
});
|
});
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
@ -479,21 +476,25 @@ void ext::PlayerBehavior::tick( uf::Object& self ) {
|
|||||||
const auto& mouseDelta = uf::inputs::kbm::states::Mouse;
|
const auto& mouseDelta = uf::inputs::kbm::states::Mouse;
|
||||||
bool shouldnt = (mouseDelta.x == 0 && mouseDelta.y == 0) || !metadata.system.control || metadata.camera.fixed;
|
bool shouldnt = (mouseDelta.x == 0 && mouseDelta.y == 0) || !metadata.system.control || metadata.camera.fixed;
|
||||||
if ( !shouldnt ) {
|
if ( !shouldnt ) {
|
||||||
pod::Vector2f delta = {
|
if (abs(mouseDelta.x) > deadZone.x) metadata.mouse.accum.x += mouseDelta.x * uf::physics::time::delta;
|
||||||
(float) metadata.mouse.sensitivity.x * (abs(mouseDelta.x) < deadZone.x ? 0 : mouseDelta.x),
|
if (abs(mouseDelta.y) > deadZone.y) metadata.mouse.accum.y += mouseDelta.y * uf::physics::time::delta;
|
||||||
(float) metadata.mouse.sensitivity.y * (abs(mouseDelta.y) < deadZone.y ? 0 : mouseDelta.y)
|
|
||||||
};
|
|
||||||
metadata.camera.queued += delta;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( !metadata.camera.fixed ) {
|
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 ) {
|
if ( metadata.camera.queued.x != 0 || metadata.camera.queued.y != 0 ) {
|
||||||
auto lookDelta = metadata.camera.queued;
|
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;
|
metadata.camera.queued -= lookDelta * metadata.mouse.smoothing;
|
||||||
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 = {};
|
||||||
metadata.camera.queued -= lookDelta;
|
|
||||||
if ( lookDelta.x != 0 ) {
|
if ( lookDelta.x != 0 ) {
|
||||||
if ( metadata.camera.invert.x ) lookDelta.x *= -1;
|
if ( metadata.camera.invert.x ) lookDelta.x *= -1;
|
||||||
metadata.camera.limit.current.x += lookDelta.x;
|
metadata.camera.limit.current.x += lookDelta.x;
|
||||||
|
|||||||
@ -50,7 +50,9 @@ namespace ext {
|
|||||||
} camera;
|
} camera;
|
||||||
struct {
|
struct {
|
||||||
pod::Vector2f sensitivity = {1,1};
|
pod::Vector2f sensitivity = {1,1};
|
||||||
pod::Vector2f smoothing = {10,10};
|
pod::Vector2f smoothing = {0,0};
|
||||||
|
|
||||||
|
pod::Vector2f accum = {};
|
||||||
} mouse;
|
} mouse;
|
||||||
struct {
|
struct {
|
||||||
struct {
|
struct {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user