W/S=camera pitch; wheel zoom; canvas click coords; CamSync pitch
This commit is contained in:
1 parent
e1e0d95e45
commit
b5a847d418
1 file changed
+76
-13
@@ -9,6 +9,12 @@ $RPGClient::Active = 0;
|
||||
$RPGClient::Yaw = 0;
|
||||
$RPGClient::Dist = 14;
|
||||
$RPGClient::TopDownPitch = 1.22;
|
||||
$RPGClient::Pitch = 1.22;
|
||||
$RPGClient::PitchMin = 0.55;
|
||||
$RPGClient::PitchMax = 1.38;
|
||||
$RPGClient::PitchSpeed = 0.025;
|
||||
$RPGClient::DistMin = 8;
|
||||
$RPGClient::DistMax = 30;
|
||||
$RPGClient::OrbitInit = 0;
|
||||
$RPGClient::HudPlaced = 0;
|
||||
$RPGClient::PlayBooted = 0;
|
||||
@@ -32,8 +38,55 @@ $RPGClient::CamSched = 0;
|
||||
$RPGClient::LastClickTime = 0;
|
||||
$RPGClient::ChatOpen = 0;
|
||||
|
||||
function RPGClient_NormScreenPos(%pos)
|
||||
{
|
||||
if (!isObject(Canvas))
|
||||
{
|
||||
return "0.5 0.5";
|
||||
}
|
||||
%ext = Canvas.getExtent();
|
||||
%w = getWord(%ext, 0);
|
||||
%h = getWord(%ext, 1);
|
||||
if (%w < 1)
|
||||
{
|
||||
%w = 1;
|
||||
}
|
||||
if (%h < 1)
|
||||
{
|
||||
%h = 1;
|
||||
}
|
||||
%x = getWord(%pos, 0) / %w;
|
||||
%y = 1 - getWord(%pos, 1) / %h;
|
||||
return RPGClient_ClampNorm(%x, %y);
|
||||
}
|
||||
|
||||
function RPGClient_ClampNorm(%x, %y)
|
||||
{
|
||||
if (%x < 0)
|
||||
{
|
||||
%x = 0;
|
||||
}
|
||||
if (%x > 1)
|
||||
{
|
||||
%x = 1;
|
||||
}
|
||||
if (%y < 0)
|
||||
{
|
||||
%y = 0;
|
||||
}
|
||||
if (%y > 1)
|
||||
{
|
||||
%y = 1;
|
||||
}
|
||||
return %x SPC %y;
|
||||
}
|
||||
|
||||
function RPGClient_NormPos(%ctrl, %pos)
|
||||
{
|
||||
if (isObject(Canvas))
|
||||
{
|
||||
return RPGClient_NormScreenPos(%pos);
|
||||
}
|
||||
if (!isObject(%ctrl))
|
||||
{
|
||||
return "0.5 0.5";
|
||||
@@ -94,7 +147,7 @@ function RPGClient_SendClick(%button, %pos)
|
||||
return;
|
||||
}
|
||||
$RPGClient::LastClickTime = %now;
|
||||
%norm = RPGClient_NormPos(RPGClient_Mouse, %pos);
|
||||
%norm = RPGClient_NormScreenPos(%pos);
|
||||
commandToServer('RPG_Click', %button, getWord(%norm, 0), getWord(%norm, 1), RPGClient_Aspect());
|
||||
schedule(1, 0, RPGClient_ApplyCamera, 1);
|
||||
}
|
||||
@@ -153,7 +206,7 @@ function RPGClient_ViewTransform(%body, %yaw, %dist, %panX, %panY)
|
||||
%cx = getWord(%p, 0) + %panX;
|
||||
%cy = getWord(%p, 1) + %panY;
|
||||
%cz = getWord(%p, 2) + 1.5;
|
||||
%pitch = $RPGClient::TopDownPitch;
|
||||
%pitch = $RPGClient::Pitch > 0 ? $RPGClient::Pitch : $RPGClient::TopDownPitch;
|
||||
%bx = -mCos(%yaw) * mCos(%pitch) * %dist;
|
||||
%by = -mSin(%yaw) * mCos(%pitch) * %dist;
|
||||
%bz = mSin(%pitch) * %dist;
|
||||
@@ -194,6 +247,7 @@ function RPGClient_CameraTick()
|
||||
return;
|
||||
}
|
||||
%spin = $RPGClient::YawSpeed * 2.5;
|
||||
%tilt = $RPGClient::PitchSpeed * 2.5;
|
||||
%zoom = $RPGClient::ZoomSpeed * 2.5;
|
||||
%changed = 0;
|
||||
if ($mvLeftAction > 0)
|
||||
@@ -208,12 +262,12 @@ function RPGClient_CameraTick()
|
||||
}
|
||||
if ($mvForwardAction > 0)
|
||||
{
|
||||
$RPGClient::Dist = getMax(6, $RPGClient::Dist - %zoom * $mvForwardAction);
|
||||
$RPGClient::Pitch = getMin($RPGClient::PitchMax, $RPGClient::Pitch + %tilt * $mvForwardAction);
|
||||
%changed = 1;
|
||||
}
|
||||
if ($mvBackwardAction > 0)
|
||||
{
|
||||
$RPGClient::Dist = getMin(32, $RPGClient::Dist + %zoom * $mvBackwardAction);
|
||||
$RPGClient::Pitch = getMax($RPGClient::PitchMin, $RPGClient::Pitch - %tilt * $mvBackwardAction);
|
||||
%changed = 1;
|
||||
}
|
||||
if ($RPGClient::MvL > 0)
|
||||
@@ -228,12 +282,12 @@ function RPGClient_CameraTick()
|
||||
}
|
||||
if ($RPGClient::MvF > 0)
|
||||
{
|
||||
$RPGClient::Dist = getMax(6, $RPGClient::Dist - %zoom * $RPGClient::MvF);
|
||||
$RPGClient::Pitch = getMin($RPGClient::PitchMax, $RPGClient::Pitch + %tilt * $RPGClient::MvF);
|
||||
%changed = 1;
|
||||
}
|
||||
if ($RPGClient::MvB > 0)
|
||||
{
|
||||
$RPGClient::Dist = getMin(32, $RPGClient::Dist + %zoom * $RPGClient::MvB);
|
||||
$RPGClient::Pitch = getMax($RPGClient::PitchMin, $RPGClient::Pitch - %tilt * $RPGClient::MvB);
|
||||
%changed = 1;
|
||||
}
|
||||
RPGClient_ApplyCamera(%changed || $RPGClient::MvF || $RPGClient::MvB || $RPGClient::MvL || $RPGClient::MvR);
|
||||
@@ -452,6 +506,11 @@ function RPGClient_EnsureOverlay()
|
||||
PlayGui.add(RPGClient_Mouse);
|
||||
PlayGui.pushToBack(RPGClient_Mouse);
|
||||
}
|
||||
if (isObject(RPGClient_Mouse) && isObject(Canvas))
|
||||
{
|
||||
%ext = Canvas.getExtent();
|
||||
RPGClient_Mouse.resize(0, 0, getWord(%ext, 0), getWord(%ext, 1));
|
||||
}
|
||||
if ($RPGClient::Active)
|
||||
{
|
||||
RPGClient_StockMoveMapBinds();
|
||||
@@ -540,7 +599,7 @@ function RPGClient_ApplyCamera(%forceSync)
|
||||
return;
|
||||
}
|
||||
$RPGClient::LastCamSync = %now;
|
||||
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist, 0, 0);
|
||||
commandToServer('RPG_CamSync', $RPGClient::Yaw, $RPGClient::Dist, $RPGClient::PanX, $RPGClient::PanY, $RPGClient::Pitch);
|
||||
if (RPGClient_NetCam())
|
||||
{
|
||||
return;
|
||||
@@ -567,7 +626,7 @@ function RPGClient_ApplyCamera(%forceSync)
|
||||
%conn.setControlObject(%cam);
|
||||
$mvFreeLook = 0;
|
||||
$firstPerson = 0;
|
||||
%xfm = RPGClient_ViewTransform(%body, $RPGClient::Yaw, $RPGClient::Dist, 0, 0);
|
||||
%xfm = RPGClient_ViewTransform(%body, $RPGClient::Yaw, $RPGClient::Dist, $RPGClient::PanX, $RPGClient::PanY);
|
||||
%cam.unmountImage(0);
|
||||
if (!$RPGClient::OrbitInit)
|
||||
{
|
||||
@@ -637,7 +696,7 @@ function RPGClient_ZoomIn(%val)
|
||||
}
|
||||
if (%val)
|
||||
{
|
||||
$RPGClient::Dist = getMax(6, $RPGClient::Dist - 0.8);
|
||||
$RPGClient::Dist = getMax($RPGClient::DistMin, $RPGClient::Dist - 1.2);
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
}
|
||||
@@ -654,7 +713,7 @@ function RPGClient_ZoomOut(%val)
|
||||
}
|
||||
if (%val)
|
||||
{
|
||||
$RPGClient::Dist = getMin(32, $RPGClient::Dist + 0.8);
|
||||
$RPGClient::Dist = getMin($RPGClient::DistMax, $RPGClient::Dist + 1.2);
|
||||
RPGClient_ApplyCamera(1);
|
||||
}
|
||||
}
|
||||
@@ -770,13 +829,17 @@ function RPGClient_EnsurePlayGui()
|
||||
return 1;
|
||||
}
|
||||
|
||||
function clientCmdRPG_Camera(%yaw, %dist)
|
||||
function clientCmdRPG_Camera(%yaw, %dist, %pitch)
|
||||
{
|
||||
$RPGClient::Yaw = %yaw;
|
||||
if (%dist > 0)
|
||||
{
|
||||
$RPGClient::Dist = %dist;
|
||||
}
|
||||
if (%pitch > 0)
|
||||
{
|
||||
$RPGClient::Pitch = %pitch;
|
||||
}
|
||||
}
|
||||
|
||||
function clientCmdRPG_TopDown(%on, %yaw, %dist)
|
||||
@@ -1071,11 +1134,11 @@ package RPGClient_Input
|
||||
{
|
||||
if (%val > 0)
|
||||
{
|
||||
$RPGClient::Dist = getMax(6, $RPGClient::Dist - 0.35 * %val);
|
||||
$RPGClient::Dist = getMax($RPGClient::DistMin, $RPGClient::Dist - 0.5 * %val);
|
||||
}
|
||||
else
|
||||
{
|
||||
$RPGClient::Dist = getMin(32, $RPGClient::Dist - 0.35 * %val);
|
||||
$RPGClient::Dist = getMin($RPGClient::DistMax, $RPGClient::Dist - 0.5 * %val);
|
||||
}
|
||||
RPGClient_ApplyCamera(1);
|
||||
return;
|
||||
|
||||
Reference in new issue
Block a user