Skip to content

Instantly share code, notes, and snippets.

@qoh
Created September 18, 2012 10:09
Show Gist options
  • Save qoh/3742400 to your computer and use it in GitHub Desktop.
Save qoh/3742400 to your computer and use it in GitHub Desktop.
function updateScreenOffset()
{
cancel( $updateScreenOffset );
if ( !isObject( %sc = nameToID( "serverConnection" ) ) )
{
$dofX = 0;
$dofY = 0;
return;
}
%co = %sc.getControlObject();
if ( !( %co.getType() & $TypeMasks::PlayerObjectType ) || !$firstPerson )
{
$dofX = 0;
$dofY = 0;
$updateScreenOffset = schedule( 16, 0, "updateScreenOffset" );
return;
}
%vl = %co.getVelocity();
%fv = %co.getForwardVector();
%vx = getWord( %vl, 0 );
%vy = getWord( %vl, 1 );
%fx = getWord( %fv, 0 );
%fy = getWord( %fv, 1 );
%nx = mClampF( %vx * %fy + %vy * %fx, -1, 1 );
%ny = mClampF( %vy * %fy + %vx * -%fx, -1, 1 );
%ny = 0;
%nz = %nx * 4;
%dx = mClampF( mAbs( %nx - $dofX ), 0, 2 );
%dy = mClampF( mAbs( %nx - $dofY ), 0, 2 );
%dy = mClampF( mAbs( %nx - playGUI.cameraZRot ), 0, 2 );
%sx = mClampF( %dx / 2, 0.01, 1 );
%sy = mClampF( %dy / 2, 0.01, 1 );
%sz = mClampF( %dz / 2, 0.01, 1 );
%rx = 0.2 * %sx;
%ry = 0.2 * %sy;
%rz = 0.2 * %sy;
if ( $dofX < %nx )
{
$dofX += %rx;
if ( $dofX > %nx )
{
$dofX = %nx;
}
}
else if ( $dofX > %nx )
{
$dofX -= %rx;
if ( $dofX < %nx )
{
$dofX = %nx;
}
}
if ( $dofY < %ny )
{
$dofY += %ry;
if ( $dofY > %ny )
{
$dofY = %ny;
}
}
else if ( $dofY > %ny )
{
$dofY -= %ry;
if ( $dofY < %ny )
{
$dofY = %ny;
}
}
if ( playGUI.cameraZRot < %nz )
{
playGUI.cameraZRot += %rz;
if ( $dofX > %nz )
{
playGUI.cameraZRot = %nz;
}
}
else if ( playGUI.cameraZRot > %nz )
{
playGUI.cameraZRot -= %rz;
if ( playGUI.cameraZRot < %nz )
{
playGUI.cameraZRot = %nz;
}
}
$updateScreenOffset = schedule( 16, 0, "updateScreenOffset" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment