Start overhaul of mousecam
This commit is contained in:
@@ -16,6 +16,47 @@
|
|||||||
|
|
||||||
let mouseCameraEnabled = false;
|
let mouseCameraEnabled = false;
|
||||||
|
|
||||||
|
let DeltaTime = 0;
|
||||||
|
|
||||||
|
let ENTITYTYPE_BUILDING = 1;
|
||||||
|
let ENTITYTYPE_VEHICLE = 2;
|
||||||
|
let ENTITYTYPE_PED = 3;
|
||||||
|
let ENTITYTYPE_OBJECT = 4;
|
||||||
|
let ENTITYTYPE_DUMMY = 5;
|
||||||
|
|
||||||
|
let UpdateCamera = gta.updateCamera;
|
||||||
|
|
||||||
|
let distance;
|
||||||
|
let zIncrease;
|
||||||
|
|
||||||
|
let identityMatrix = new Matrix4x4();
|
||||||
|
|
||||||
|
let cameraIdentityMatrix = new Matrix4x4();
|
||||||
|
cameraIdentityMatrix.m11 = -1;
|
||||||
|
cameraIdentityMatrix.m12 = 0;
|
||||||
|
cameraIdentityMatrix.m13 = 0;
|
||||||
|
cameraIdentityMatrix.m14 = 0;
|
||||||
|
cameraIdentityMatrix.m21 = 0;
|
||||||
|
cameraIdentityMatrix.m22 = 1;
|
||||||
|
cameraIdentityMatrix.m23 = 0;
|
||||||
|
cameraIdentityMatrix.m24 = 0;
|
||||||
|
cameraIdentityMatrix.m31 = 0;
|
||||||
|
cameraIdentityMatrix.m32 = 0;
|
||||||
|
cameraIdentityMatrix.m33 = 1;
|
||||||
|
cameraIdentityMatrix.m34 = 0;
|
||||||
|
cameraIdentityMatrix.m41 = 0;
|
||||||
|
cameraIdentityMatrix.m42 = 0;
|
||||||
|
cameraIdentityMatrix.m43 = 0;
|
||||||
|
cameraIdentityMatrix.m44 = 1;
|
||||||
|
|
||||||
|
let GetCamera;
|
||||||
|
|
||||||
|
const Camera = Symbol();
|
||||||
|
|
||||||
|
GetCamera = function() {
|
||||||
|
return Camera;
|
||||||
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
function initMouseCameraScript() {
|
function initMouseCameraScript() {
|
||||||
@@ -48,12 +89,6 @@ function GetPedVehicle(pPed) {
|
|||||||
return pPed.vehicle;
|
return pPed.vehicle;
|
||||||
}
|
}
|
||||||
|
|
||||||
let ENTITYTYPE_BUILDING = 1;
|
|
||||||
let ENTITYTYPE_VEHICLE = 2;
|
|
||||||
let ENTITYTYPE_PED = 3;
|
|
||||||
let ENTITYTYPE_OBJECT = 4;
|
|
||||||
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;
|
||||||
@@ -98,16 +133,6 @@ function GetMouseSensitivity() {
|
|||||||
return [MouseSensitivity.x,MouseSensitivity.y];
|
return [MouseSensitivity.x,MouseSensitivity.y];
|
||||||
}
|
}
|
||||||
|
|
||||||
let GetCamera;
|
|
||||||
{
|
|
||||||
const Camera = Symbol();
|
|
||||||
|
|
||||||
GetCamera = function()
|
|
||||||
{
|
|
||||||
return Camera;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function AreEntityCollisionsEnabled(pEntity) {
|
function AreEntityCollisionsEnabled(pEntity) {
|
||||||
return pEntity.collisionsEnabled;
|
return pEntity.collisionsEnabled;
|
||||||
}
|
}
|
||||||
@@ -135,8 +160,6 @@ function SetPlaceableMatrix(pPlaceable, mat) {
|
|||||||
pPlaceable.matrix = mat;
|
pPlaceable.matrix = mat;
|
||||||
}
|
}
|
||||||
|
|
||||||
const UpdateCamera = gta.updateCamera;
|
|
||||||
|
|
||||||
let GetTickCount;
|
let GetTickCount;
|
||||||
{
|
{
|
||||||
let FrameCount = 0;
|
let FrameCount = 0;
|
||||||
@@ -177,7 +200,6 @@ function applyMultiplierTimeStep(m,t) {
|
|||||||
//TODO: alert
|
//TODO: alert
|
||||||
//TODO: confirm
|
//TODO: confirm
|
||||||
|
|
||||||
const identityMatrix = new Matrix4x4();
|
|
||||||
if (identityMatrix.setIdentity === undefined) {
|
if (identityMatrix.setIdentity === undefined) {
|
||||||
identityMatrix.m11 = 1;
|
identityMatrix.m11 = 1;
|
||||||
identityMatrix.m12 = 0;
|
identityMatrix.m12 = 0;
|
||||||
@@ -197,54 +219,31 @@ if (identityMatrix.setIdentity === undefined) {
|
|||||||
identityMatrix.m44 = 1;
|
identityMatrix.m44 = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
const cameraIdentityMatrix = new Matrix4x4();
|
function createMultipliedMatrix() {
|
||||||
cameraIdentityMatrix.m11 = -1;
|
|
||||||
cameraIdentityMatrix.m12 = 0;
|
|
||||||
cameraIdentityMatrix.m13 = 0;
|
|
||||||
cameraIdentityMatrix.m14 = 0;
|
|
||||||
cameraIdentityMatrix.m21 = 0;
|
|
||||||
cameraIdentityMatrix.m22 = 1;
|
|
||||||
cameraIdentityMatrix.m23 = 0;
|
|
||||||
cameraIdentityMatrix.m24 = 0;
|
|
||||||
cameraIdentityMatrix.m31 = 0;
|
|
||||||
cameraIdentityMatrix.m32 = 0;
|
|
||||||
cameraIdentityMatrix.m33 = 1;
|
|
||||||
cameraIdentityMatrix.m34 = 0;
|
|
||||||
cameraIdentityMatrix.m41 = 0;
|
|
||||||
cameraIdentityMatrix.m42 = 0;
|
|
||||||
cameraIdentityMatrix.m43 = 0;
|
|
||||||
cameraIdentityMatrix.m44 = 1;
|
|
||||||
|
|
||||||
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;
|
||||||
@@ -252,31 +251,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));
|
||||||
@@ -308,8 +302,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;
|
||||||
}
|
}
|
||||||
@@ -321,13 +314,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;
|
||||||
@@ -335,8 +326,7 @@ 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;
|
||||||
@@ -368,8 +358,7 @@ let OldPosition = null;
|
|||||||
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)
|
||||||
@@ -383,30 +372,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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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))
|
||||||
@@ -417,24 +402,14 @@ function getCameraRestRotation(target)
|
|||||||
return [rotZ, rotY];
|
return [rotZ, rotY];
|
||||||
}
|
}
|
||||||
|
|
||||||
function resetCameraRotation()
|
function resetCameraRotation() {
|
||||||
{
|
|
||||||
[cameraRotZ, cameraRotY] = getCameraRestRotation(getCameraTarget());
|
[cameraRotZ, cameraRotY] = getCameraRestRotation(getCameraTarget());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let DeltaTime = 0;
|
function processMouseCamera() {
|
||||||
addEventHandler("OnProcess", (event, deltaTime) => {
|
return false;
|
||||||
DeltaTime = deltaTime;
|
}
|
||||||
if(!localPlayer) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(gta.game >= GAME_GTA_SA) {
|
|
||||||
// We don't need this for GTA SA+
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let IdleTime = 0;
|
let IdleTime = 0;
|
||||||
|
|
||||||
@@ -467,9 +442,6 @@ function cancelReturnToRestRotation() {
|
|||||||
IdleTime = 0;
|
IdleTime = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
let distance;
|
|
||||||
let zIncrease;
|
|
||||||
|
|
||||||
function getCameraOffsetInfo(target) {
|
function getCameraOffsetInfo(target) {
|
||||||
if (GetEntityType(target) == ENTITYTYPE_PED) {
|
if (GetEntityType(target) == ENTITYTYPE_PED) {
|
||||||
let distance = 4;
|
let distance = 4;
|
||||||
@@ -513,7 +485,7 @@ function getCameraOffsetInfo(target) {
|
|||||||
return [distance, zIncrease, offsetX, offsetY, offsetZ];
|
return [distance, zIncrease, offsetX, offsetY, offsetZ];
|
||||||
}
|
}
|
||||||
|
|
||||||
function update() {
|
function updateMouseCamera() {
|
||||||
let target = getCameraTarget();
|
let target = getCameraTarget();
|
||||||
if(target != null) {
|
if(target != null) {
|
||||||
if(oldCameraTarget != target) {
|
if(oldCameraTarget != target) {
|
||||||
@@ -606,50 +578,3 @@ function update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ===========================================================================
|
// ===========================================================================
|
||||||
|
|
||||||
addEventHandler("OnCameraProcess", (event) => {
|
|
||||||
if(mouseCameraEnabled) {
|
|
||||||
update();
|
|
||||||
event.preventDefault();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
|
|
||||||
function getPosInFrontOfPos(pos, angle, distance) {
|
|
||||||
let x = (pos.x+((Math.cos(angle+(Math.PI/2)))*distance));
|
|
||||||
let y = (pos.y+((Math.sin(angle+(Math.PI/2)))*distance));
|
|
||||||
let z = pos.z;
|
|
||||||
|
|
||||||
return new Vec3(x,y,z);
|
|
||||||
}
|
|
||||||
|
|
||||||
function vec3ToVec2(pos) {
|
|
||||||
return new Vec2(pos[0], pos[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
// ===========================================================================
|
|
||||||
|
|
||||||
/*
|
|
||||||
addEventHandler("OnEntityProcess", function(event, entity) {
|
|
||||||
if(entity.type == ELEMENT_PLAYER) {
|
|
||||||
if(entity != localPlayer) {
|
|
||||||
let isPlayerWalking = entity.getData("ag.walk");
|
|
||||||
if(isPlayerWalking == true) {
|
|
||||||
let position = getPosInFrontOfPos(entity.position, entity.heading, 1.0);
|
|
||||||
entity.walkTo(position);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
function getHeadingFromPosToPos(pos1, pos2) {
|
|
||||||
let x = pos2.x-pos1.x;
|
|
||||||
let y = pos2.y-pos1.y;
|
|
||||||
let rad = Math.atan2(y, x);
|
|
||||||
let deg = radToDeg(rad);
|
|
||||||
deg -= 90;
|
|
||||||
deg = deg % 360;
|
|
||||||
return degToRad(deg);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
Reference in New Issue
Block a user