Updated missile-code

This commit is contained in:
Nikolai V. Chr
2021-12-29 12:16:05 +01:00
parent 51cb1f23cf
commit ac519b3e89
4 changed files with 1792 additions and 1482 deletions

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@ var Math = {
#
# Authors: Nikolai V. Chr, Axel Paccalin.
#
# Version 1.94
# Version 1.97
#
# When doing euler coords. to cartesian: +x = forw, +y = left, +z = up.
# FG struct. coords: +x = back, +y = right, +z = up.
@@ -57,6 +57,22 @@ var Math = {
return R2D * math.acos(me.value);
},
# Rodrigues' rotation formula. Use unitVectorAxis as axis, and rotate around it.
rotateVectorAroundVector: func (a, unitVectorAxis, angle) {
return me.plus(
me.plus(
me.product(math.cos(angle*D2R),a),
me.product(math.sin(angle*D2R), me.crossProduct(unitVectorAxis,a))
),
me.product((1-math.cos(angle*D2R))*me.dotProduct(unitVectorAxis,a), unitVectorAxis)
);
},
#Rotate a certain amound of degrees towards 'towardsMe'.
rotateVectorTowardsVector: func (a, towardsMe, angle) {
return me.rotateVectorAroundVector(a, me.normalize(me.crossProduct(a, towardsMe)), angle);
},
# length of vector
magnitudeVector: func (a) {
me.mag = 1;
@@ -95,6 +111,14 @@ var Math = {
return me.multiplyMatrixWithVector(me.rotation, vector);
},
# rotate a vector. Order: pitch, yaw
pitchYawVector: func (pitch, yaw, vector) {
me.pitchM = me.pitchMatrix(pitch);
me.yawM = me.yawMatrix(yaw);
me.rotation = me.multiplyMatrices(me.yawM, me.pitchM);
return me.multiplyMatrixWithVector(me.rotation, vector);
},
# rotate a vector. Order: pitch
pitchVector: func (pitch, vector) {
me.pitchM = me.pitchMatrix(pitch);
@@ -144,7 +168,8 @@ var Math = {
me.horz = math.sqrt(vector[0]*vector[0]+vector[1]*vector[1]);
if (me.horz != 0) {
me.pitch = math.atan2(vector[2],me.horz)*R2D;
me.hdg = math.asin(-vector[1]/me.horz)*R2D;
me.div = math.clamp(-vector[1]/me.horz, -1, 1);
me.hdg = math.asin(me.div)*R2D;
if (vector[0] < 0) {
# south
@@ -262,6 +287,11 @@ var Math = {
projVectorOnPlane: func (planeNormal, vector) {
return me.minus(vector, me.product(me.dotProduct(vector,planeNormal)/math.pow(me.magnitudeVector(planeNormal),2), planeNormal));
},
# Project a onto ontoMe.
projVectorOnVector: func (a, ontoMe) {
return me.product(me.dotProduct(a,ontoMe)/me.dotProduct(ontoMe,ontoMe), ontoMe);
},
# unary - vector
opposite: func (v){

File diff suppressed because it is too large Load Diff

View File

@@ -2,7 +2,7 @@ var Math = {
#
# Authors: Nikolai V. Chr, Axel Paccalin.
#
# Version 1.94
# Version 1.97
#
# When doing euler coords. to cartesian: +x = forw, +y = left, +z = up.
# FG struct. coords: +x = back, +y = right, +z = up.
@@ -57,6 +57,22 @@ var Math = {
return R2D * math.acos(me.value);
},
# Rodrigues' rotation formula. Use unitVectorAxis as axis, and rotate around it.
rotateVectorAroundVector: func (a, unitVectorAxis, angle) {
return me.plus(
me.plus(
me.product(math.cos(angle*D2R),a),
me.product(math.sin(angle*D2R), me.crossProduct(unitVectorAxis,a))
),
me.product((1-math.cos(angle*D2R))*me.dotProduct(unitVectorAxis,a), unitVectorAxis)
);
},
#Rotate a certain amound of degrees towards 'towardsMe'.
rotateVectorTowardsVector: func (a, towardsMe, angle) {
return me.rotateVectorAroundVector(a, me.normalize(me.crossProduct(a, towardsMe)), angle);
},
# length of vector
magnitudeVector: func (a) {
me.mag = 1;
@@ -95,6 +111,14 @@ var Math = {
return me.multiplyMatrixWithVector(me.rotation, vector);
},
# rotate a vector. Order: pitch, yaw
pitchYawVector: func (pitch, yaw, vector) {
me.pitchM = me.pitchMatrix(pitch);
me.yawM = me.yawMatrix(yaw);
me.rotation = me.multiplyMatrices(me.yawM, me.pitchM);
return me.multiplyMatrixWithVector(me.rotation, vector);
},
# rotate a vector. Order: pitch
pitchVector: func (pitch, vector) {
me.pitchM = me.pitchMatrix(pitch);
@@ -144,7 +168,8 @@ var Math = {
me.horz = math.sqrt(vector[0]*vector[0]+vector[1]*vector[1]);
if (me.horz != 0) {
me.pitch = math.atan2(vector[2],me.horz)*R2D;
me.hdg = math.asin(-vector[1]/me.horz)*R2D;
me.div = math.clamp(-vector[1]/me.horz, -1, 1);
me.hdg = math.asin(me.div)*R2D;
if (vector[0] < 0) {
# south
@@ -262,6 +287,11 @@ var Math = {
projVectorOnPlane: func (planeNormal, vector) {
return me.minus(vector, me.product(me.dotProduct(vector,planeNormal)/math.pow(me.magnitudeVector(planeNormal),2), planeNormal));
},
# Project a onto ontoMe.
projVectorOnVector: func (a, ontoMe) {
return me.product(me.dotProduct(a,ontoMe)/me.dotProduct(ontoMe,ontoMe), ontoMe);
},
# unary - vector
opposite: func (v){