custom fly camera: WASD pan, ESC keeps cursor
This commit is contained in:
1 parent
036466aa88
commit
59c9fe33cc
1 file changed
+222
-26
@@ -7,6 +7,16 @@ $RPGClient::Active = 0;
|
||||
$RPGClient::Yaw = 0;
|
||||
$RPGClient::Dist = 14;
|
||||
$RPGClient::TopDownPitch = 0.95;
|
||||
$RPGClient::PanX = 0;
|
||||
$RPGClient::PanY = 0;
|
||||
$RPGClient::PanMax = 48;
|
||||
$RPGClient::PanSpeed = 0.42;
|
||||
$RPGClient::CamTickSched = 0;
|
||||
$RPGClient::LastCamSync = 0;
|
||||
$RPGClient::MvF = 0;
|
||||
$RPGClient::MvB = 0;
|
||||
$RPGClient::MvL = 0;
|
||||
$RPGClient::MvR = 0;
|
||||
$RPGClient::HelloPending = 0;
|
||||
$RPGClient::HelloLast = "";
|
||||
$RPGClient::TopDownWatchSched = 0;
|
||||
@@ -77,7 +87,7 @@ function RPGClient_SendClick(%button, %pos)
|
||||
$RPGClient::LastClickTime = %now;
|
||||
%norm = RPGClient_NormPos(RPGClient_Mouse, %pos);
|
||||
commandToServer('RPG_Click', %button, getWord(%norm, 0), getWord(%norm, 1), RPGClient_Aspect());
|
||||
schedule(1, 0, RPGClient_ApplyCamera);
|
||||
schedule(1, 0, RPGClient_ApplyCamera, 1);
|
||||
}
|
||||
|
||||
function RPGClient_Mouse::onMouseDown(%this, %mod, %pos, %clicks)
|
||||
@@ -107,11 +117,32 @@ function RPGClient_Mouse::onWake(%this)
|
||||
}
|
||||
}
|
||||
|
||||
function RPGClient_OrbitTransform(%body, %yaw, %dist)
|
||||
function RPGClient_ClampPan()
|
||||
{
|
||||
%max = $RPGClient::PanMax;
|
||||
if ($RPGClient::PanX > %max)
|
||||
{
|
||||
$RPGClient::PanX = %max;
|
||||
}
|
||||
if ($RPGClient::PanX < -%max)
|
||||
{
|
||||
$RPGClient::PanX = -%max;
|
||||
}
|
||||
if ($RPGClient::PanY > %max)
|
||||
{
|
||||
$RPGClient::PanY = %max;
|
||||
}
|
||||
if ($RPGClient::PanY < -%max)
|
||||
{
|
||||
$RPGClient::PanY = -%max;
|
||||
}
|
||||
}
|
||||
|
||||
function RPGClient_ViewTransform(%body, %yaw, %dist, %panX, %panY)
|
||||
{
|
||||
%p = %body.getPosition();
|
||||
%cx = getWord(%p, 0);
|
||||
%cy = getWord(%p, 1);
|
||||
%cx = getWord(%p, 0) + %panX;
|
||||
%cy = getWord(%p, 1) + %panY;
|
||||
%cz = getWord(%p, 2) + 1.5;
|
||||
%pitch = $RPGClient::TopDownPitch;
|
||||
%bx = -mCos(%yaw) * mCos(%pitch) * %dist;
|
||||
@@ -126,6 +157,60 @@ function RPGClient_OrbitTransform(%body, %yaw, %dist)
|
||||
return %eye @ " " @ %rot;
|
||||
}
|
||||
|
||||
function RPGClient_EnsureCursor()
|
||||
{
|
||||
if (!$RPGClient::Active || !isObject(Canvas))
|
||||
{
|
||||
return;
|
||||
}
|
||||
lockMouse(0);
|
||||
cursorOn();
|
||||
}
|
||||
|
||||
function RPGClient_CameraTick()
|
||||
{
|
||||
$RPGClient::CamTickSched = 0;
|
||||
if (!$RPGClient::Active)
|
||||
{
|
||||
return;
|
||||
}
|
||||
%speed = $RPGClient::PanSpeed;
|
||||
%yaw = $RPGClient::Yaw;
|
||||
%fwdX = -mCos(%yaw);
|
||||
%fwdY = -mSin(%yaw);
|
||||
%rightX = mSin(%yaw);
|
||||
%rightY = -mCos(%yaw);
|
||||
if ($RPGClient::MvF)
|
||||
{
|
||||
$RPGClient::PanX = $RPGClient::PanX + %fwdX * %speed * $RPGClient::MvF;
|
||||
$RPGClient::PanY = $RPGClient::PanY + %fwdY * %speed * $RPGClient::MvF;
|
||||
}
|
||||
if ($RPGClient::MvB)
|
||||
{
|
||||
$RPGClient::PanX = $RPGClient::PanX - %fwdX * %speed * $RPGClient::MvB;
|
||||
$RPGClient::PanY = $RPGClient::PanY - %fwdY * %speed * $RPGClient::MvB;
|
||||
}
|
||||
if ($RPGClient::MvL)
|
||||
{
|
||||
$RPGClient::PanX = $RPGClient::PanX - %rightX * %speed * $RPGClient::MvL;
|
||||
$RPGClient::PanY = $RPGClient::PanY - %rightY * %speed * $RPGClient::MvL;
|
||||
}
|
||||
if ($RPGClient::MvR)
|
||||
{
|
||||
$RPGClient::PanX = $RPGClient::PanX + %rightX * %speed * $RPGClient::MvR;
|
||||
$RPGClient::PanY = $RPGClient::PanY + %rightY * %speed * $RPGClient::MvR;
|
||||
}
|
||||
RPGClient_ClampPan();
|
||||
RPGClient_ApplyCamera(0);
|
||||
$RPGClient::CamTickSched = schedule(32, 0, RPGClient_CameraTick);
|
||||
}
|
||||
|
||||
function RPGClient_StartCameraTick()
|
||||
{
|
||||
cancel($RPGClient::CamTickSched);
|
||||
$RPGClient::CamTickSched = schedule(32, 0, RPGClient_CameraTick);
|
||||
}
|
||||
|
||||
function RPGClient_SendClickFromCursor(%button)
|
||||
{
|
||||
if (!$RPGClient::Active || !isObject(Canvas))
|
||||
@@ -159,16 +244,10 @@ function RPGClient_EnableOverlay()
|
||||
RPGClient_KeyMap.delete();
|
||||
}
|
||||
new ActionMap(RPGClient_KeyMap);
|
||||
RPGClient_KeyMap.bind(keyboard0, a, RPGClient_YawLeft);
|
||||
RPGClient_KeyMap.bind(keyboard0, d, RPGClient_YawRight);
|
||||
RPGClient_KeyMap.bind(keyboard0, left, RPGClient_YawLeft);
|
||||
RPGClient_KeyMap.bind(keyboard0, right, RPGClient_YawRight);
|
||||
RPGClient_KeyMap.bind(keyboard0, "pageup", RPGClient_ZoomIn);
|
||||
RPGClient_KeyMap.bind(keyboard0, "pagedown", RPGClient_ZoomOut);
|
||||
RPGClient_KeyMap.bind(keyboard0, equals, RPGClient_ZoomIn);
|
||||
RPGClient_KeyMap.bind(keyboard0, minus, RPGClient_ZoomOut);
|
||||
RPGClient_KeyMap.bind(keyboard0, w, RPGClient_ZoomIn);
|
||||
RPGClient_KeyMap.bind(keyboard0, s, RPGClient_ZoomOut);
|
||||
RPGClient_KeyMap.bind(keyboard0, m, RPGClient_ToggleCursor);
|
||||
RPGClient_KeyMap.push();
|
||||
$mvFreeLook = 0;
|
||||
@@ -196,6 +275,12 @@ function RPGClient_DisableOverlay()
|
||||
{
|
||||
cancel($RPGClient::CamSched);
|
||||
$RPGClient::CamSched = 0;
|
||||
cancel($RPGClient::CamTickSched);
|
||||
$RPGClient::CamTickSched = 0;
|
||||
$RPGClient::MvF = 0;
|
||||
$RPGClient::MvB = 0;
|
||||
$RPGClient::MvL = 0;
|
||||
$RPGClient::MvR = 0;
|
||||
if (isObject(RPGClient_KeyMap))
|
||||
{
|
||||
RPGClient_KeyMap.pop();
|
||||
@@ -207,7 +292,7 @@ function RPGClient_DisableOverlay()
|
||||
$RPGClient::Active = 0;
|
||||
}
|
||||
|
||||
function RPGClient_ApplyCamera()
|
||||
function RPGClient_ApplyCamera(%forceSync)
|
||||
{
|
||||
%conn = RPGClient_GetConn();
|
||||
if (!isObject(%conn))
|
||||
@@ -239,24 +324,31 @@ function RPGClient_ApplyCamera()
|
||||
%conn.setControlObject(%cam);
|
||||
$mvFreeLook = 0;
|
||||
$firstPerson = 0;
|
||||
$mvForwardAction = 0;
|
||||
$mvBackwardAction = 0;
|
||||
$mvLeftAction = 0;
|
||||
$mvRightAction = 0;
|
||||
%cam.unmountImage(0);
|
||||
%xfm = RPGClient_OrbitTransform(%body, $RPGClient::Yaw, $RPGClient::Dist);
|
||||
%xfm = RPGClient_ViewTransform(%body, $RPGClient::Yaw, $RPGClient::Dist, $RPGClient::PanX, $RPGClient::PanY);
|
||||
%cam.setFlyMode();
|
||||
%cam.setTransform(%xfm);
|
||||
%cam.setMode("Corpse", %body);
|
||||
%cam.setOrbitMode(%body, %xfm, 0, 32, $RPGClient::Dist);
|
||||
%cam.mode = "Corpse";
|
||||
%cam.thirdPersonOnly = 1;
|
||||
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist);
|
||||
%cam.mode = "Fly";
|
||||
%now = getSimTime();
|
||||
if (%forceSync || %now - $RPGClient::LastCamSync > 120)
|
||||
{
|
||||
$RPGClient::LastCamSync = %now;
|
||||
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist, $RPGClient::PanX, $RPGClient::PanY);
|
||||
}
|
||||
}
|
||||
|
||||
function RPGClient_ScheduleCamera()
|
||||
{
|
||||
cancel($RPGClient::CamSched);
|
||||
$RPGClient::CamSched = schedule(50, 0, RPGClient_ApplyCamera);
|
||||
schedule(200, 0, RPGClient_ApplyCamera);
|
||||
schedule(500, 0, RPGClient_ApplyCamera);
|
||||
schedule(1200, 0, RPGClient_ApplyCamera);
|
||||
schedule(2500, 0, RPGClient_ApplyCamera);
|
||||
$RPGClient::CamSched = schedule(50, 0, RPGClient_ApplyCamera, 0);
|
||||
schedule(200, 0, RPGClient_ApplyCamera, 0);
|
||||
schedule(500, 0, RPGClient_ApplyCamera, 0);
|
||||
schedule(1200, 0, RPGClient_ApplyCamera, 0);
|
||||
schedule(2500, 0, RPGClient_ApplyCamera, 0);
|
||||
}
|
||||
|
||||
function RPGClient_YawLeft(%val)
|
||||
@@ -266,7 +358,7 @@ function RPGClient_YawLeft(%val)
|
||||
return;
|
||||
}
|
||||
$RPGClient::Yaw = $RPGClient::Yaw - 0.06;
|
||||
RPGClient_ApplyCamera();
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
|
||||
function RPGClient_YawRight(%val)
|
||||
@@ -276,7 +368,7 @@ function RPGClient_YawRight(%val)
|
||||
return;
|
||||
}
|
||||
$RPGClient::Yaw = $RPGClient::Yaw + 0.06;
|
||||
RPGClient_ApplyCamera();
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
|
||||
function RPGClient_ZoomIn(%val)
|
||||
@@ -286,7 +378,7 @@ function RPGClient_ZoomIn(%val)
|
||||
return;
|
||||
}
|
||||
$RPGClient::Dist = getMax(6, $RPGClient::Dist - 0.6);
|
||||
RPGClient_ApplyCamera();
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
|
||||
function RPGClient_ZoomOut(%val)
|
||||
@@ -296,7 +388,7 @@ function RPGClient_ZoomOut(%val)
|
||||
return;
|
||||
}
|
||||
$RPGClient::Dist = getMin(32, $RPGClient::Dist + 0.6);
|
||||
RPGClient_ApplyCamera();
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
|
||||
function RPGClient_CanSendCmd()
|
||||
@@ -397,9 +489,13 @@ function clientCmdRPG_TopDown(%on, %yaw, %dist)
|
||||
$RPGClient::Active = 1;
|
||||
$RPGClient::Yaw = %yaw;
|
||||
$RPGClient::Dist = %dist > 0 ? %dist : 14;
|
||||
$RPGClient::PanX = 0;
|
||||
$RPGClient::PanY = 0;
|
||||
RPGClient_EnableOverlay();
|
||||
RPGClient_BindKeys();
|
||||
RPGClient_StartCameraTick();
|
||||
RPGClient_ScheduleCamera();
|
||||
RPGClient_EnsureCursor();
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -552,6 +648,106 @@ package RPGClient_BlockMouseFire
|
||||
};
|
||||
activatePackage(RPGClient_BlockMouseFire);
|
||||
|
||||
package RPGClient_MoveMap
|
||||
{
|
||||
function moveforward(%val)
|
||||
{
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
$RPGClient::MvF = %val * $RunMultiplier;
|
||||
$mvForwardAction = 0;
|
||||
return;
|
||||
}
|
||||
Parent::moveforward(%val);
|
||||
}
|
||||
|
||||
function movebackward(%val)
|
||||
{
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
$RPGClient::MvB = %val * $RunMultiplier;
|
||||
$mvBackwardAction = 0;
|
||||
return;
|
||||
}
|
||||
Parent::movebackward(%val);
|
||||
}
|
||||
|
||||
function moveleft(%val)
|
||||
{
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
$RPGClient::MvL = %val * $RunMultiplier;
|
||||
$mvLeftAction = 0;
|
||||
return;
|
||||
}
|
||||
Parent::moveleft(%val);
|
||||
}
|
||||
|
||||
function moveright(%val)
|
||||
{
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
$RPGClient::MvR = %val * $RunMultiplier;
|
||||
$mvRightAction = 0;
|
||||
return;
|
||||
}
|
||||
Parent::moveright(%val);
|
||||
}
|
||||
|
||||
function PageUpNewChatHud(%val)
|
||||
{
|
||||
if ($RPGClient::Active && %val)
|
||||
{
|
||||
RPGClient_ZoomIn(1);
|
||||
return;
|
||||
}
|
||||
Parent::PageUpNewChatHud(%val);
|
||||
}
|
||||
|
||||
function PageDownNewChatHud(%val)
|
||||
{
|
||||
if ($RPGClient::Active && %val)
|
||||
{
|
||||
RPGClient_ZoomOut(1);
|
||||
return;
|
||||
}
|
||||
Parent::PageDownNewChatHud(%val);
|
||||
}
|
||||
};
|
||||
activatePackage(RPGClient_MoveMap);
|
||||
|
||||
package RPGClient_Cursor
|
||||
{
|
||||
function GuiCanvas::checkCursor(%this)
|
||||
{
|
||||
Parent::checkCursor(%this);
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
RPGClient_EnsureCursor();
|
||||
}
|
||||
}
|
||||
|
||||
function escapeMenu::toggle(%this)
|
||||
{
|
||||
if (%this.isAwake())
|
||||
{
|
||||
Canvas.popDialog(%this);
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
schedule(0, 0, RPGClient_EnsureCursor);
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (Canvas.getContent().getName() $= "LoadingGui")
|
||||
{
|
||||
disconnect();
|
||||
return;
|
||||
}
|
||||
Canvas.pushDialog(%this);
|
||||
}
|
||||
};
|
||||
activatePackage(RPGClient_Cursor);
|
||||
|
||||
package RPGClient_Cleanup
|
||||
{
|
||||
function disconnectedCleanup(%doReconnect)
|
||||
|
||||
Reference in new issue
Block a user