Formatting
This commit is contained in:
@@ -12,34 +12,29 @@
|
|||||||
// CREDITS TO LUCASC190 FOR MAKING THE MOUSE CAMERA
|
// CREDITS TO LUCASC190 FOR MAKING THE MOUSE CAMERA
|
||||||
// WALKING CODE ADDED BY VORTREX
|
// WALKING CODE ADDED BY VORTREX
|
||||||
|
|
||||||
function SetStandardControlsEnabled(bEnabled)
|
function SetStandardControlsEnabled(bEnabled) {
|
||||||
{
|
|
||||||
if (typeof gta == "undefined") {
|
if (typeof gta == "undefined") {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (game.standardControls === undefined)
|
if (game.standardControls === undefined) {
|
||||||
{
|
|
||||||
logToConsole(LOG_WARN, "game.standardControls not implemented");
|
logToConsole(LOG_WARN, "game.standardControls not implemented");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
game.standardControls = bEnabled;
|
game.standardControls = bEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetCurrentPlayerIndex()
|
function GetCurrentPlayerIndex() {
|
||||||
{
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetPlayerPed(uiIndex)
|
function GetPlayerPed(uiIndex) {
|
||||||
{
|
|
||||||
if (uiIndex >= 1)
|
if (uiIndex >= 1)
|
||||||
throw new Error("player index out of range");
|
throw new Error("player index out of range");
|
||||||
return localPlayer;
|
return localPlayer;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetPedVehicle(pPed)
|
function GetPedVehicle(pPed) {
|
||||||
{
|
|
||||||
return pPed.vehicle;
|
return pPed.vehicle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +44,7 @@ let ENTITYTYPE_PED = 3;
|
|||||||
let ENTITYTYPE_OBJECT = 4;
|
let ENTITYTYPE_OBJECT = 4;
|
||||||
let ENTITYTYPE_DUMMY = 5;
|
let ENTITYTYPE_DUMMY = 5;
|
||||||
|
|
||||||
function GetEntityType(Entity)
|
function GetEntityType(Entity) {
|
||||||
{
|
|
||||||
if (Entity.isType(ELEMENT_BUILDING))
|
if (Entity.isType(ELEMENT_BUILDING))
|
||||||
return ENTITYTYPE_BUILDING;
|
return ENTITYTYPE_BUILDING;
|
||||||
if (Entity.isType(ELEMENT_VEHICLE))
|
if (Entity.isType(ELEMENT_VEHICLE))
|
||||||
@@ -64,35 +58,29 @@ function GetEntityType(Entity)
|
|||||||
return undefined;
|
return undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetPlaceableMatrix(pPlaceable)
|
function GetPlaceableMatrix(pPlaceable) {
|
||||||
{
|
|
||||||
if (pPlaceable == GetCamera())
|
if (pPlaceable == GetCamera())
|
||||||
return game.cameraMatrix;
|
return game.cameraMatrix;
|
||||||
return pPlaceable.matrix;
|
return pPlaceable.matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetEntityModel(pEntity)
|
function GetEntityModel(pEntity) {
|
||||||
{
|
|
||||||
return pEntity;
|
return pEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetModelBoundingSphere(usModel)
|
function GetModelBoundingSphere(usModel) {
|
||||||
{
|
|
||||||
return [usModel.boundingRadius, usModel.boundingCentre.x, usModel.boundingCentre.y, usModel.boundingCentre.z];
|
return [usModel.boundingRadius, usModel.boundingCentre.x, usModel.boundingCentre.y, usModel.boundingCentre.z];
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetMouseSpeed()
|
function GetMouseSpeed() {
|
||||||
{
|
|
||||||
if (gui.cursorEnabled)
|
if (gui.cursorEnabled)
|
||||||
return [0, 0];
|
return [0, 0];
|
||||||
let MouseSpeed = game.getMouseSpeed();
|
let MouseSpeed = game.getMouseSpeed();
|
||||||
return [MouseSpeed.x, -MouseSpeed.y];
|
return [MouseSpeed.x, -MouseSpeed.y];
|
||||||
}
|
}
|
||||||
|
|
||||||
function GetMouseSensitivity()
|
function GetMouseSensitivity() {
|
||||||
{
|
if (game.getMouseSensitivity === undefined) {
|
||||||
if (game.getMouseSensitivity === undefined)
|
|
||||||
{
|
|
||||||
//logToConsole(LOG_ERROR, "game.getMouseSensitivity not implemented");
|
//logToConsole(LOG_ERROR, "game.getMouseSensitivity not implemented");
|
||||||
return [0.0025, 0.003];
|
return [0.0025, 0.003];
|
||||||
}
|
}
|
||||||
@@ -104,26 +92,21 @@ let GetCamera;
|
|||||||
{
|
{
|
||||||
const Camera = Symbol();
|
const Camera = Symbol();
|
||||||
|
|
||||||
GetCamera = function()
|
GetCamera = function () {
|
||||||
{
|
|
||||||
return Camera;
|
return Camera;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function AreEntityCollisionsEnabled(pEntity)
|
function AreEntityCollisionsEnabled(pEntity) {
|
||||||
{
|
|
||||||
return pEntity.collisionsEnabled;
|
return pEntity.collisionsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetEntityCollisionsEnabled(pEntity, bCollisionsEnabled)
|
function SetEntityCollisionsEnabled(pEntity, bCollisionsEnabled) {
|
||||||
{
|
|
||||||
pEntity.collisionsEnabled = bCollisionsEnabled;
|
pEntity.collisionsEnabled = bCollisionsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
function ProcessLineOfSight(vecStartX, vecStartY, vecStartZ, vecEndX, vecEndY, vecEndZ, bCheckBuildings, bCheckVehicles, bCheckPeds, bCheckObjects, bCheckDummies, bCheckSeeThroughStuff, bIgnoreSomeObjectsForCamera)
|
function ProcessLineOfSight(vecStartX, vecStartY, vecStartZ, vecEndX, vecEndY, vecEndZ, bCheckBuildings, bCheckVehicles, bCheckPeds, bCheckObjects, bCheckDummies, bCheckSeeThroughStuff, bIgnoreSomeObjectsForCamera) {
|
||||||
{
|
if (game.processLineOfSight === undefined) {
|
||||||
if (game.processLineOfSight === undefined)
|
|
||||||
{
|
|
||||||
logToConsole(LOG_WARN, "game.processLineOfSight not implemented");
|
logToConsole(LOG_WARN, "game.processLineOfSight not implemented");
|
||||||
return [null];
|
return [null];
|
||||||
}
|
}
|
||||||
@@ -133,10 +116,8 @@ function ProcessLineOfSight(vecStartX, vecStartY, vecStartZ, vecEndX, vecEndY, v
|
|||||||
return [Result.position.x, Result.position.y, Result.position.z, Result.normal.x, Result.normal.y, Result.normal.z, Result.entity];
|
return [Result.position.x, Result.position.y, Result.position.z, Result.normal.x, Result.normal.y, Result.normal.z, Result.entity];
|
||||||
}
|
}
|
||||||
|
|
||||||
function SetPlaceableMatrix(pPlaceable, mat)
|
function SetPlaceableMatrix(pPlaceable, mat) {
|
||||||
{
|
if (pPlaceable == GetCamera()) {
|
||||||
if (pPlaceable == GetCamera())
|
|
||||||
{
|
|
||||||
game.setCameraMatrix(mat);
|
game.setCameraMatrix(mat);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -149,20 +130,17 @@ let GetTickCount;
|
|||||||
{
|
{
|
||||||
let FrameCount = 0;
|
let FrameCount = 0;
|
||||||
|
|
||||||
setInterval(() =>
|
setInterval(() => {
|
||||||
{
|
|
||||||
++FrameCount;
|
++FrameCount;
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
let GTAFrameCount = 0;
|
let GTAFrameCount = 0;
|
||||||
|
|
||||||
addEventHandler("OnProcess", (event, deltaTime) =>
|
addEventHandler("OnProcess", (event, deltaTime) => {
|
||||||
{
|
|
||||||
++GTAFrameCount;
|
++GTAFrameCount;
|
||||||
});
|
});
|
||||||
|
|
||||||
GetTickCount = function(bGTA, bFrames)
|
GetTickCount = function (bGTA, bFrames) {
|
||||||
{
|
|
||||||
if (bFrames)
|
if (bFrames)
|
||||||
return bGTA ? GTAFrameCount : FrameCount;
|
return bGTA ? GTAFrameCount : FrameCount;
|
||||||
else
|
else
|
||||||
@@ -192,8 +170,7 @@ function applyMultiplierTimeStep(m,t)//TODO: Move this to MathUtil.js
|
|||||||
//TODO: confirm
|
//TODO: confirm
|
||||||
|
|
||||||
const identityMatrix = new Matrix4x4();
|
const identityMatrix = new Matrix4x4();
|
||||||
if (identityMatrix.setIdentity === undefined)
|
if (identityMatrix.setIdentity === undefined) {
|
||||||
{
|
|
||||||
identityMatrix.m11 = 1;
|
identityMatrix.m11 = 1;
|
||||||
identityMatrix.m12 = 0;
|
identityMatrix.m12 = 0;
|
||||||
identityMatrix.m13 = 0;
|
identityMatrix.m13 = 0;
|
||||||
@@ -230,36 +207,31 @@ cameraIdentityMatrix.m42 = 0;
|
|||||||
cameraIdentityMatrix.m43 = 0;
|
cameraIdentityMatrix.m43 = 0;
|
||||||
cameraIdentityMatrix.m44 = 1;
|
cameraIdentityMatrix.m44 = 1;
|
||||||
|
|
||||||
function createMultipliedMatrix()
|
function createMultipliedMatrix() {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
matrix.setMultiply.apply(matrix, arguments);
|
matrix.setMultiply.apply(matrix, arguments);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createXRotationMatrix(x)
|
function createXRotationMatrix(x) {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
matrix.setRotateX(x);
|
matrix.setRotateX(x);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createYRotationMatrix(x)
|
function createYRotationMatrix(x) {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
matrix.setRotateY(x);
|
matrix.setRotateY(x);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createZRotationMatrix(z)
|
function createZRotationMatrix(z) {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
matrix.setRotateZ(z);
|
matrix.setRotateZ(z);
|
||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function createTranslationMatrix(x,y,z)
|
function createTranslationMatrix(x, y, z) {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
matrix.setTranslate([x, y, z]);
|
matrix.setTranslate([x, y, z]);
|
||||||
return matrix;
|
return matrix;
|
||||||
@@ -267,31 +239,26 @@ function createTranslationMatrix(x,y,z)
|
|||||||
|
|
||||||
//TODO: createScaleMatrix
|
//TODO: createScaleMatrix
|
||||||
|
|
||||||
function getDotProduct(x,y,z,x2,y2,z2)
|
function getDotProduct(x, y, z, x2, y2, z2) {
|
||||||
{
|
|
||||||
return x * x2 + y * y2 + z * z2;
|
return x * x2 + y * y2 + z * z2;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCrossProduct(x,y,z,x2,y2,z2)
|
function getCrossProduct(x, y, z, x2, y2, z2) {
|
||||||
{
|
|
||||||
return [y * z2 - z * y2, z * x2 - x * z2, x * y2 - y * x2];
|
return [y * z2 - z * y2, z * x2 - x * z2, x * y2 - y * x2];
|
||||||
}
|
}
|
||||||
|
|
||||||
function getLength(x,y,z)
|
function getLength(x, y, z) {
|
||||||
{
|
|
||||||
return Math.sqrt(getDotProduct(x, y, z, x, y, z));
|
return Math.sqrt(getDotProduct(x, y, z, x, y, z));
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalise(x,y,z)
|
function normalise(x, y, z) {
|
||||||
{
|
|
||||||
let length = getLength(x, y, z);
|
let length = getLength(x, y, z);
|
||||||
if (length == 0)
|
if (length == 0)
|
||||||
throw new Error("an attempt was made to normalise a three dimensional vector with a length of zero");
|
throw new Error("an attempt was made to normalise a three dimensional vector with a length of zero");
|
||||||
return [x / length, y / length, z / length];
|
return [x / length, y / length, z / length];
|
||||||
}
|
}
|
||||||
|
|
||||||
function createLookAtLHMatrix(eyeX, eyeY, eyeZ, atX, atY, atZ, upX,upY,upZ)
|
function createLookAtLHMatrix(eyeX, eyeY, eyeZ, atX, atY, atZ, upX, upY, upZ) {
|
||||||
{
|
|
||||||
let matrix = new Matrix4x4();
|
let matrix = new Matrix4x4();
|
||||||
let [lookX, lookY, lookZ] = normalise(atX - eyeX, atY - eyeY, atZ - eyeZ);
|
let [lookX, lookY, lookZ] = normalise(atX - eyeX, atY - eyeY, atZ - eyeZ);
|
||||||
let [rightX, rightY, rightZ] = normalise.apply(null, getCrossProduct(upX, upY, upZ, lookX, lookY, lookZ));
|
let [rightX, rightY, rightZ] = normalise.apply(null, getCrossProduct(upX, upY, upZ, lookX, lookY, lookZ));
|
||||||
@@ -323,8 +290,7 @@ function createLookAtLHMatrix(eyeX, eyeY, eyeZ, atX, atY, atZ, upX,upY,upZ)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getDifferenceBetweenAngles(current,target)
|
function getDifferenceBetweenAngles(current, target) {
|
||||||
{
|
|
||||||
let f = (((target - current) + Math.PI) / (Math.PI * 2));
|
let f = (((target - current) + Math.PI) / (Math.PI * 2));
|
||||||
return ((f - Math.floor(f)) * (Math.PI * 2)) - Math.PI;
|
return ((f - Math.floor(f)) * (Math.PI * 2)) - Math.PI;
|
||||||
}
|
}
|
||||||
@@ -336,13 +302,11 @@ let easeStartPosX, easeStartPosY, easeStartPosZ;
|
|||||||
let easeStartLookX, easeStartLookY, easeStartLookZ;
|
let easeStartLookX, easeStartLookY, easeStartLookZ;
|
||||||
let easeStartUpX, easeStartUpY, easeStartUpZ;
|
let easeStartUpX, easeStartUpY, easeStartUpZ;
|
||||||
|
|
||||||
function getCameraPositionInfo(matrix)
|
function getCameraPositionInfo(matrix) {
|
||||||
{
|
|
||||||
return [matrix.m41, matrix.m42, matrix.m43, matrix.m21, matrix.m22, matrix.m23, matrix.m31, matrix.m32, matrix.m33];
|
return [matrix.m41, matrix.m42, matrix.m43, matrix.m21, matrix.m22, matrix.m23, matrix.m31, matrix.m32, matrix.m33];
|
||||||
}
|
}
|
||||||
|
|
||||||
function startCameraEase()
|
function startCameraEase() {
|
||||||
{
|
|
||||||
easeCamera = true;
|
easeCamera = true;
|
||||||
easeStartTicks = GetTickCount(true, false);
|
easeStartTicks = GetTickCount(true, false);
|
||||||
easeDuration = 1000;
|
easeDuration = 1000;
|
||||||
@@ -350,13 +314,11 @@ function startCameraEase()
|
|||||||
[easeStartPosX, easeStartPosY, easeStartPosZ, easeStartLookX, easeStartLookY, easeStartLookZ, easeStartUpX, easeStartUpY, easeStartUpZ] = getCameraPositionInfo(matrix);
|
[easeStartPosX, easeStartPosY, easeStartPosZ, easeStartLookX, easeStartLookY, easeStartLookZ, easeStartUpX, easeStartUpY, easeStartUpZ] = getCameraPositionInfo(matrix);
|
||||||
}
|
}
|
||||||
|
|
||||||
function applyCameraEase(matrix)
|
function applyCameraEase(matrix) {
|
||||||
{
|
|
||||||
if (!easeCamera)
|
if (!easeCamera)
|
||||||
return matrix;
|
return matrix;
|
||||||
let ease = (GetTickCount(true, false) - easeStartTicks) / easeDuration;
|
let ease = (GetTickCount(true, false) - easeStartTicks) / easeDuration;
|
||||||
if (ease < 1)
|
if (ease < 1) {
|
||||||
{
|
|
||||||
ease = easingSinusoidalInOut(ease, 0, 1, 1);
|
ease = easingSinusoidalInOut(ease, 0, 1, 1);
|
||||||
let [newPosX, newPosY, newPosZ, newLookX, newLookY, newLookZ, newUpX, newUpY, newUpZ] = getCameraPositionInfo(matrix);
|
let [newPosX, newPosY, newPosZ, newLookX, newLookY, newLookZ, newUpX, newUpY, newUpZ] = getCameraPositionInfo(matrix);
|
||||||
let easePosX = easeStartPosX + (newPosX - easeStartPosX) * ease;
|
let easePosX = easeStartPosX + (newPosX - easeStartPosX) * ease;
|
||||||
@@ -373,8 +335,7 @@ function applyCameraEase(matrix)
|
|||||||
return matrix;
|
return matrix;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isCameraEasing()
|
function isCameraEasing() {
|
||||||
{
|
|
||||||
return easeCamera && GetTickCount(true, false) < (easeStartTicks + easeDuration);
|
return easeCamera && GetTickCount(true, false) < (easeStartTicks + easeDuration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,14 +344,12 @@ let OldPosition = null;//2019 Lucas was here!
|
|||||||
let cameraRotZ;
|
let cameraRotZ;
|
||||||
let cameraRotY;
|
let cameraRotY;
|
||||||
|
|
||||||
function getCameraTarget()
|
function getCameraTarget() {
|
||||||
{
|
|
||||||
let playerPed = GetPlayerPed(GetCurrentPlayerIndex());
|
let playerPed = GetPlayerPed(GetCurrentPlayerIndex());
|
||||||
let vehicle = GetPedVehicle(playerPed);
|
let vehicle = GetPedVehicle(playerPed);
|
||||||
if (vehicle != null)
|
if (vehicle != null)
|
||||||
return vehicle;
|
return vehicle;
|
||||||
if (playerPed != null)
|
if (playerPed != null) {
|
||||||
{
|
|
||||||
//if (playerPed.health <= 1)//Breaks because of fade//2019 Lucas was here!
|
//if (playerPed.health <= 1)//Breaks because of fade//2019 Lucas was here!
|
||||||
// return null;
|
// return null;
|
||||||
return playerPed;
|
return playerPed;
|
||||||
@@ -398,30 +357,26 @@ function getCameraTarget()
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function isRelativeToTarget(target)
|
function isRelativeToTarget(target) {
|
||||||
{
|
|
||||||
if (GetEntityType(target) == ENTITYTYPE_PED)
|
if (GetEntityType(target) == ENTITYTYPE_PED)
|
||||||
return false;
|
return false;
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
function isClipped(target)
|
function isClipped(target) {
|
||||||
{
|
|
||||||
if (GetEntityType(target) == ENTITYTYPE_PED)
|
if (GetEntityType(target) == ENTITYTYPE_PED)
|
||||||
return true;
|
return true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//2019 Lucas was here!
|
//2019 Lucas was here!
|
||||||
function ShouldReturnToRestRotation(Target)
|
function ShouldReturnToRestRotation(Target) {
|
||||||
{
|
|
||||||
if (GetEntityType(Target) == ENTITYTYPE_PED)
|
if (GetEntityType(Target) == ENTITYTYPE_PED)
|
||||||
return false;
|
return false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCameraRestRotation(target)
|
function getCameraRestRotation(target) {
|
||||||
{
|
|
||||||
let targetMatrix = GetPlaceableMatrix(target);
|
let targetMatrix = GetPlaceableMatrix(target);
|
||||||
let rotZ;
|
let rotZ;
|
||||||
if (isRelativeToTarget(target))
|
if (isRelativeToTarget(target))
|
||||||
@@ -432,15 +387,13 @@ function getCameraRestRotation(target)
|
|||||||
return [rotZ, rotY];
|
return [rotZ, rotY];
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetCameraRotation()
|
function resetCameraRotation() {
|
||||||
{
|
|
||||||
[cameraRotZ, cameraRotY] = getCameraRestRotation(getCameraTarget());
|
[cameraRotZ, cameraRotY] = getCameraRestRotation(getCameraTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
//2019 Lucas was here!
|
//2019 Lucas was here!
|
||||||
let DeltaTime = 0;
|
let DeltaTime = 0;
|
||||||
addEventHandler("OnProcess", (event, deltaTime) =>
|
addEventHandler("OnProcess", (event, deltaTime) => {
|
||||||
{
|
|
||||||
DeltaTime = deltaTime;
|
DeltaTime = deltaTime;
|
||||||
if (!localPlayer) {
|
if (!localPlayer) {
|
||||||
return false;
|
return false;
|
||||||
@@ -449,8 +402,7 @@ addEventHandler("OnProcess", (event, deltaTime) =>
|
|||||||
|
|
||||||
let IdleTime = 0;//2019 Lucas was here!
|
let IdleTime = 0;//2019 Lucas was here!
|
||||||
|
|
||||||
function processReturnToRestRotation()
|
function processReturnToRestRotation() {
|
||||||
{
|
|
||||||
//resetCameraRotation();//2019 Lucas was here!
|
//resetCameraRotation();//2019 Lucas was here!
|
||||||
|
|
||||||
//2019 Lucas was here!
|
//2019 Lucas was here!
|
||||||
@@ -458,15 +410,13 @@ function processReturnToRestRotation()
|
|||||||
if (!ShouldReturnToRestRotation(Target))
|
if (!ShouldReturnToRestRotation(Target))
|
||||||
return;
|
return;
|
||||||
IdleTime += DeltaTime;
|
IdleTime += DeltaTime;
|
||||||
if (IdleTime > 1.5)
|
if (IdleTime > 1.5) {
|
||||||
{
|
|
||||||
let Velocity = Target.velocity;
|
let Velocity = Target.velocity;
|
||||||
let Matrix = Target.matrix;
|
let Matrix = Target.matrix;
|
||||||
let Speed = getDotProduct(Velocity.x, Velocity.y, Velocity.z, Matrix.getElement(1 * 4 + 0), Matrix.getElement(1 * 4 + 1), Matrix.getElement(1 * 4 + 2));
|
let Speed = getDotProduct(Velocity.x, Velocity.y, Velocity.z, Matrix.getElement(1 * 4 + 0), Matrix.getElement(1 * 4 + 1), Matrix.getElement(1 * 4 + 2));
|
||||||
let AbsSpeed = Math.abs(Speed);
|
let AbsSpeed = Math.abs(Speed);
|
||||||
let Multiplier = Math.min(AbsSpeed / 0.75, 1);
|
let Multiplier = Math.min(AbsSpeed / 0.75, 1);
|
||||||
if (Multiplier != 0)
|
if (Multiplier != 0) {
|
||||||
{
|
|
||||||
let [TargetCameraRotZ2, TargetCameraRotY2] = getCameraRestRotation(Target);
|
let [TargetCameraRotZ2, TargetCameraRotY2] = getCameraRestRotation(Target);
|
||||||
if (Speed < 0)
|
if (Speed < 0)
|
||||||
TargetCameraRotZ2 += Math.PI;
|
TargetCameraRotZ2 += Math.PI;
|
||||||
@@ -477,18 +427,15 @@ function processReturnToRestRotation()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function cancelReturnToRestRotation()
|
function cancelReturnToRestRotation() {
|
||||||
{
|
|
||||||
IdleTime = 0;//2019 Lucas was here!
|
IdleTime = 0;//2019 Lucas was here!
|
||||||
}
|
}
|
||||||
|
|
||||||
let distance;
|
let distance;
|
||||||
let zIncrease;
|
let zIncrease;
|
||||||
|
|
||||||
function getCameraOffsetInfo(target)
|
function getCameraOffsetInfo(target) {
|
||||||
{
|
if (GetEntityType(target) == ENTITYTYPE_PED) {
|
||||||
if (GetEntityType(target) == ENTITYTYPE_PED)
|
|
||||||
{
|
|
||||||
let distance = 4;
|
let distance = 4;
|
||||||
let zIncrease = 0.8;
|
let zIncrease = 0.8;
|
||||||
let offsetX = 0;
|
let offsetX = 0;
|
||||||
@@ -507,8 +454,7 @@ function getCameraOffsetInfo(target)
|
|||||||
let offsetX;
|
let offsetX;
|
||||||
let offsetY;
|
let offsetY;
|
||||||
let offsetZ;
|
let offsetZ;
|
||||||
if (radius <= 3.0535011291504)
|
if (radius <= 3.0535011291504) {
|
||||||
{
|
|
||||||
minDistance = 4;
|
minDistance = 4;
|
||||||
maxDistance = 8;
|
maxDistance = 8;
|
||||||
minZIncrease = 0.5;
|
minZIncrease = 0.5;
|
||||||
@@ -516,8 +462,7 @@ function getCameraOffsetInfo(target)
|
|||||||
minRadius = 2;
|
minRadius = 2;
|
||||||
maxRadius = 3.0535011291504;
|
maxRadius = 3.0535011291504;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
minDistance = 8;
|
minDistance = 8;
|
||||||
maxDistance = 16;
|
maxDistance = 16;
|
||||||
minZIncrease = 1;
|
minZIncrease = 1;
|
||||||
@@ -533,13 +478,10 @@ function getCameraOffsetInfo(target)
|
|||||||
return [distance, zIncrease, offsetX, offsetY, offsetZ];
|
return [distance, zIncrease, offsetX, offsetY, offsetZ];
|
||||||
}
|
}
|
||||||
|
|
||||||
function update()
|
function update() {
|
||||||
{
|
|
||||||
let target = getCameraTarget();
|
let target = getCameraTarget();
|
||||||
if (target != null)
|
if (target != null) {
|
||||||
{
|
if (oldCameraTarget != target) {
|
||||||
if (oldCameraTarget != target)
|
|
||||||
{
|
|
||||||
//if (oldCameraTarget != null)//2019 Lucas was here!
|
//if (oldCameraTarget != null)//2019 Lucas was here!
|
||||||
let Position = target.position;
|
let Position = target.position;
|
||||||
if (OldPosition == null || getLength(Position.x - OldPosition.x, Position.y - OldPosition.y, Position.z - OldPosition.z) < 10)
|
if (OldPosition == null || getLength(Position.x - OldPosition.x, Position.y - OldPosition.y, Position.z - OldPosition.z) < 10)
|
||||||
@@ -550,12 +492,10 @@ function update()
|
|||||||
let [mouseSensitivityX, mouseSensitivityY] = GetMouseSensitivity();
|
let [mouseSensitivityX, mouseSensitivityY] = GetMouseSensitivity();
|
||||||
mouseSpeedX = mouseSpeedX * mouseSensitivityX * 2;
|
mouseSpeedX = mouseSpeedX * mouseSensitivityX * 2;
|
||||||
mouseSpeedY = mouseSpeedY * mouseSensitivityY * 2;
|
mouseSpeedY = mouseSpeedY * mouseSensitivityY * 2;
|
||||||
if (mouseSpeedX == 0 && mouseSpeedY == 0)
|
if (mouseSpeedX == 0 && mouseSpeedY == 0) {
|
||||||
{
|
|
||||||
processReturnToRestRotation();
|
processReturnToRestRotation();
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
cameraRotZ = cameraRotZ - mouseSpeedX;
|
cameraRotZ = cameraRotZ - mouseSpeedX;
|
||||||
cameraRotY = cameraRotY - mouseSpeedY;
|
cameraRotY = cameraRotY - mouseSpeedY;
|
||||||
cancelReturnToRestRotation();
|
cancelReturnToRestRotation();
|
||||||
@@ -581,13 +521,11 @@ function update()
|
|||||||
let offsetRotationX = createXRotationMatrix(cameraRotY);
|
let offsetRotationX = createXRotationMatrix(cameraRotY);
|
||||||
let offsetRotationZ = createZRotationMatrix(cameraRotZ);
|
let offsetRotationZ = createZRotationMatrix(cameraRotZ);
|
||||||
let cameraMatrix = createMultipliedMatrix(cameraIdentityMatrix, distanceTranslationMatrix, offsetRotationX, offsetRotationZ, targetTranslationMatrix);
|
let cameraMatrix = createMultipliedMatrix(cameraIdentityMatrix, distanceTranslationMatrix, offsetRotationX, offsetRotationZ, targetTranslationMatrix);
|
||||||
if (isRelativeToTarget(target))
|
if (isRelativeToTarget(target)) {
|
||||||
{
|
|
||||||
cameraMatrix = createMultipliedMatrix(cameraMatrix, targetMatrix);
|
cameraMatrix = createMultipliedMatrix(cameraMatrix, targetMatrix);
|
||||||
targetTranslationMatrix = createMultipliedMatrix(targetTranslationMatrix, targetMatrix);
|
targetTranslationMatrix = createMultipliedMatrix(targetTranslationMatrix, targetMatrix);
|
||||||
}
|
}
|
||||||
if (isClipped(target))
|
if (isClipped(target)) {
|
||||||
{
|
|
||||||
let startX = targetTranslationMatrix.m41;
|
let startX = targetTranslationMatrix.m41;
|
||||||
let startY = targetTranslationMatrix.m42;
|
let startY = targetTranslationMatrix.m42;
|
||||||
let startZ = targetTranslationMatrix.m43;
|
let startZ = targetTranslationMatrix.m43;
|
||||||
@@ -607,8 +545,7 @@ function update()
|
|||||||
let [positionX, positionY, positionZ, normalX, normalY, normalZ, targetEntity] = ProcessLineOfSight(startX, startY, startZ, endX, endY, endZ, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, checkSeeThroughStuff, ignoreSomeObjectsForCamera);
|
let [positionX, positionY, positionZ, normalX, normalY, normalZ, targetEntity] = ProcessLineOfSight(startX, startY, startZ, endX, endY, endZ, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, checkSeeThroughStuff, ignoreSomeObjectsForCamera);
|
||||||
if (collisionsEnabled)
|
if (collisionsEnabled)
|
||||||
SetEntityCollisionsEnabled(target, true);
|
SetEntityCollisionsEnabled(target, true);
|
||||||
if (positionX != null)
|
if (positionX != null) {
|
||||||
{
|
|
||||||
//2019 Lucas was here!
|
//2019 Lucas was here!
|
||||||
let Distance = 0.3;
|
let Distance = 0.3;
|
||||||
positionX += normalX * Distance;
|
positionX += normalX * Distance;
|
||||||
@@ -630,8 +567,7 @@ function update()
|
|||||||
return target != null;
|
return target != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
addEventHandler("OnCameraProcess", (event) =>
|
addEventHandler("OnCameraProcess", (event) => {
|
||||||
{
|
|
||||||
if (mouseCameraEnabled) {
|
if (mouseCameraEnabled) {
|
||||||
update();
|
update();
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|||||||
Reference in New Issue
Block a user