mirror of
https://github.com/Ragora/T2-DXAI.git
synced 2026-07-16 02:44:35 +00:00
Mathematical optimizations.
This commit is contained in:
parent
3058d538f8
commit
274d858679
1 changed files with 55 additions and 79 deletions
|
|
@ -37,6 +37,12 @@ function pointInTriangle(%point, %a, %b, %c)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Player::getXFacing(%this)
|
||||||
|
{
|
||||||
|
%forward = %this.getForwardVector();
|
||||||
|
return mAtan(getWord(%forward, 1), getWord(%forward, 0));
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
// Description: Calculates all the points of the given client's view cone given a maximum
|
// Description: Calculates all the points of the given client's view cone given a maximum
|
||||||
// view distance and returns them in a long string.
|
// view distance and returns them in a long string.
|
||||||
|
|
@ -48,60 +54,30 @@ function pointInTriangle(%point, %a, %b, %c)
|
||||||
// TODO: Return in a faster-to-read format: Could try as static GVar names
|
// TODO: Return in a faster-to-read format: Could try as static GVar names
|
||||||
// as the game's scripting environment for the gameplay is single threaded
|
// as the game's scripting environment for the gameplay is single threaded
|
||||||
// and it probably does a hash to store the values.
|
// and it probably does a hash to store the values.
|
||||||
// FIXME: Mathematical optimizations, right now it's a hack because of no
|
// FIXME: The horizontal view cones may be all that's necessary. A player
|
||||||
// reliable way of getting a player's X facing? Also, the horizontal view cones may
|
// height check could be used to help alleviate computational complexity.
|
||||||
// be all that's necessary. A player height check could be used to help alleviate
|
|
||||||
// computational complexity.
|
|
||||||
//------------------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------------------
|
||||||
function GameConnection::calculateViewCone(%this, %distance)
|
function GameConnection::calculateViewCone(%this, %distance)
|
||||||
{
|
{
|
||||||
if (!isObject(%this.player) || %this.player.getState() !$= "Move")
|
if (!isObject(%this.player) || %this.player.getState() !$= "Move")
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
//%xFacing = %this.player.getXFacing();
|
%xFacing = %this.player.getXFacing();
|
||||||
%halfView = %this.fieldOfView / 2;
|
|
||||||
%coneOrigin = %this.player.getMuzzlePoint($WeaponSlot);
|
%coneOrigin = %this.player.getMuzzlePoint($WeaponSlot);
|
||||||
|
|
||||||
%forwardVector = %this.player.getForwardVector();
|
%halfView = %this.fieldOfView / 2;
|
||||||
%sideVector = vectorCross("0 0 1", %forwardVector);
|
%cos = mCos(%halfView);
|
||||||
|
%sin = mSin(%halfView);
|
||||||
|
|
||||||
// Clockwise
|
// Translate the horizontal points
|
||||||
//%viewConeClockwise = %xFacing - %halfView;
|
%viewConeClockwisePoint = vectorAdd(%coneOrigin, vectorScale(%cos SPC -%sin SPC "0", %this.viewDistance));
|
||||||
|
%viewConeCounterClockwisePoint = vectorAdd(%coneOrigin, vectorScale(%cos SPC -%sin SPC "0", %this.viewDistance));
|
||||||
// %viewConeClockwisePoint = mCos(%viewConeClockwise) SPC mSin(%viewConeClockwise) SPC "0";
|
|
||||||
%viewConeClockwisePoint = mCos(-%halfView) SPC mSin(-%halfView) SPC "0";
|
|
||||||
%viewConeClockwisePoint = vectorScale(%viewConeClockwisePoint, %this.viewDistance);
|
|
||||||
//%viewConeClockwisePoint = vectorAdd(%viewConeClockwisePoint, %coneOrigin);
|
|
||||||
|
|
||||||
// Counter Clockwise
|
|
||||||
//%viewConeCounterClockwise = %xFacing + %halfView;
|
|
||||||
|
|
||||||
//%viewConeCounterClockwisePoint = mCos(%viewConeCounterClockwise) SPC mSin(%viewConeCounterClockwise) SPC "0";
|
|
||||||
%viewConeCounterClockwisePoint = mCos(%halfView) SPC mSin(%halfView) SPC "0";
|
|
||||||
%viewConeCounterClockwisePoint = vectorScale(%viewConeCounterClockwisePoint, %this.viewDistance);
|
|
||||||
//%viewConeCounterClockwisePoint = vectorAdd(%viewConeCounterClockwisePoint, %coneOrigin);
|
|
||||||
|
|
||||||
// Offsets
|
|
||||||
%halfDistance = vectorDist(%viewConeCounterClockwisePoint, %viewConeClockwisePoint) / 2;
|
|
||||||
|
|
||||||
%viewConeCounterClockwisePoint = vectorScale(%sideVector, %halfDistance);
|
|
||||||
%viewConeCounterClockwisePoint = vectorAdd(%coneOrigin, %viewConeCounterClockwisePoint);
|
|
||||||
|
|
||||||
%viewConeClockwisePoint = vectorScale(vectorScale(%sideVector, -1), %halfDistance);
|
|
||||||
%viewConeClockwisePoint = vectorAdd(%coneOrigin, %viewConeClockwisePoint);
|
|
||||||
|
|
||||||
// Translate the upper and lower points
|
// Translate the upper and lower points
|
||||||
%viewForwardPoint = vectorScale(%forwardVector, %this.viewDistance);
|
%halfDistance = vectorDist(%viewConeCounterClockwisePoint, %viewConeClockwisePoint) / 2;
|
||||||
|
|
||||||
%viewConeUpperPoint = vectorAdd(vectorScale("0 0 1", %halfDistance), %viewForwardPoint);
|
%viewConeUpperPoint = vectorAdd(%coneOrigin, "0 0" SPC %halfDistance);
|
||||||
%viewConeUpperPoint = vectorAdd(%coneOrigin, %viewConeUpperPoint);
|
%viewConeLowerPoint = vectorAdd(%coneOrigin, "0 0" SPC -%halfDistance);
|
||||||
|
|
||||||
%viewConeLowerPoint = vectorAdd(vectorScale("0 0 -1", %halfDistance), %viewForwardPoint);
|
|
||||||
%viewConeLowerPoint = vectorAdd(%coneOrigin, %viewConeLowerPoint);
|
|
||||||
|
|
||||||
// Now cast them forward
|
|
||||||
%viewConeClockwisePoint = vectorAdd(%viewConeClockwisePoint, vectorScale(%this.player.getForwardVector(), %this.viewDistance));
|
|
||||||
%viewConeCounterClockwisePoint = vectorAdd(%viewConeCounterClockwisePoint, vectorScale(%this.player.getForwardVector(), %this.viewDistance));
|
|
||||||
|
|
||||||
return %coneOrigin SPC %viewConeClockwisePoint SPC %viewConeCounterClockwisePoint SPC %viewConeUpperPoint SPC %viewConeLowerPoint;
|
return %coneOrigin SPC %viewConeClockwisePoint SPC %viewConeCounterClockwisePoint SPC %viewConeUpperPoint SPC %viewConeLowerPoint;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue