/// <summary> /// Creates a matrix for rotating points around the Y-axis. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the Y-axis.</param> /// <returns>The rotation matrix.</returns> public static FPMatrix4x4 RotateY(FP radians) { FPMatrix4x4 result; FP c = FPMath.Cos(radians); FP s = FPMath.Sin(radians); // [ c 0 -s 0 ] // [ 0 1 0 0 ] // [ s 0 c 0 ] // [ 0 0 0 1 ] result.M11 = c; result.M12 = FP.Zero; result.M13 = -s; result.M14 = FP.Zero; result.M21 = FP.Zero; result.M22 = FP.One; result.M23 = FP.Zero; result.M24 = FP.Zero; result.M31 = s; result.M32 = FP.Zero; result.M33 = c; result.M34 = FP.Zero; result.M41 = FP.Zero; result.M42 = FP.Zero; result.M43 = FP.Zero; result.M44 = FP.One; return(result); }
public static FPQuaternion Slerp(FPQuaternion quaternion1, FPQuaternion quaternion2, pfloat amount) { pfloat num2; pfloat num3; FPQuaternion quaternion; pfloat num = amount; pfloat num4 = (((quaternion1.x * quaternion2.x) + (quaternion1.y * quaternion2.y)) + (quaternion1.z * quaternion2.z)) + (quaternion1.w * quaternion2.w); bool flag = false; if (num4 < 0f) { flag = true; num4 = -num4; } if (num4 > 0.999999f) { num3 = 1f - num; num2 = flag ? -num : num; } else { pfloat num5 = FPMath.ACos(num4); pfloat num6 = (1.0f / FPMath.Sin(num5)); num3 = (FPMath.Sin(((1f - num) * num5))) * num6; num2 = flag ? ((-FPMath.Sin((num * num5))) * num6) : ((FPMath.Sin((num * num5))) * num6); } quaternion.x = (num3 * quaternion1.x) + (num2 * quaternion2.x); quaternion.y = (num3 * quaternion1.y) + (num2 * quaternion2.y); quaternion.z = (num3 * quaternion1.z) + (num2 * quaternion2.z); quaternion.w = (num3 * quaternion1.w) + (num2 * quaternion2.w); return(quaternion); }
/// <summary> /// Creates a matrix for rotating points around the Z-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the Z-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FPMatrix4x4 RotateZ(FP radians, FPVector centerPoint) { FPMatrix4x4 result; FP c = FPMath.Cos(radians); FP s = FPMath.Sin(radians); FP x = centerPoint.x * (1 - c) + centerPoint.y * s; FP y = centerPoint.y * (1 - c) - centerPoint.x * s; // [ c s 0 0 ] // [ -s c 0 0 ] // [ 0 0 1 0 ] // [ x y 0 1 ] result.M11 = c; result.M12 = s; result.M13 = FP.Zero; result.M14 = FP.Zero; result.M21 = -s; result.M22 = c; result.M23 = FP.Zero; result.M24 = FP.Zero; result.M31 = FP.Zero; result.M32 = FP.Zero; result.M33 = FP.One; result.M34 = FP.Zero; result.M41 = FP.Zero; result.M42 = FP.Zero; result.M43 = FP.Zero; result.M44 = FP.One; return(result); }
/// <summary> /// Creates a matrix for rotating points around the X-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the X-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FPMatrix4x4 RotateX(FP radians, FPVector centerPoint) { FPMatrix4x4 result; FP c = FPMath.Cos(radians); FP s = FPMath.Sin(radians); FP y = centerPoint.y * (FP.One - c) + centerPoint.z * s; FP z = centerPoint.z * (FP.One - c) - centerPoint.y * s; // [ 1 0 0 0 ] // [ 0 c s 0 ] // [ 0 -s c 0 ] // [ 0 y z 1 ] result.M11 = FP.One; result.M12 = FP.Zero; result.M13 = FP.Zero; result.M14 = FP.Zero; result.M21 = FP.Zero; result.M22 = c; result.M23 = s; result.M24 = FP.Zero; result.M31 = FP.Zero; result.M32 = -s; result.M33 = c; result.M34 = FP.Zero; result.M41 = FP.Zero; result.M42 = y; result.M43 = z; result.M44 = FP.One; return(result); }
/// <summary> /// Creates a matrix for rotating points around the Y-axis, from a center point. /// </summary> /// <param name="radians">The amount, in radians, by which to rotate around the Y-axis.</param> /// <param name="centerPoint">The center point.</param> /// <returns>The rotation matrix.</returns> public static FPMatrix4x4 RotateY(FP radians, FPVector centerPoint) { FPMatrix4x4 result; FP c = FPMath.Cos(radians); FP s = FPMath.Sin(radians); FP x = centerPoint.x * (FP.One - c) - centerPoint.z * s; FP z = centerPoint.x * (FP.One - c) + centerPoint.x * s; // [ c 0 -s 0 ] // [ 0 1 0 0 ] // [ s 0 c 0 ] // [ x 0 z 1 ] result.M11 = c; result.M12 = FP.Zero; result.M13 = -s; result.M14 = FP.Zero; result.M21 = FP.Zero; result.M22 = FP.One; result.M23 = FP.Zero; result.M24 = FP.Zero; result.M31 = s; result.M32 = FP.Zero; result.M33 = c; result.M34 = FP.Zero; result.M41 = x; result.M42 = FP.Zero; result.M43 = z; result.M44 = FP.One; return(result); }
public void ChangeRoundCenter(FP _joystickAngle) { FPVector rv = _childObj.right; if (_joystickAngle > 90 && _joystickAngle < 270) { rv *= -1; } FP RvRate = 1; //这是为了根据角度值,求圆心 if (_joystickAngle > 180) { RvRate += FPMath.Sin((_joystickAngle - 180) * FPMath.Deg2Rad); } else { RvRate += FPMath.Sin((_joystickAngle) * FPMath.Deg2Rad); } _center = rv * Radius * RvRate; _center = _childObj.position + _center; RotationSpeed = FPMath.Abs(RotationSpeed); if (_joystickAngle > 90 && _joystickAngle < 270) { RotationSpeed = FPMath.Abs(RotationSpeed) * -1; } }
public static FPVector2 Rotate(FPVector2 v, float degrees) { float radians = degrees * FPMath.Deg2Rad; float sin = FPMath.Sin(radians); float cos = FPMath.Cos(radians); float tx = v.x; float ty = v.y; return(new FPVector2(cos * tx - sin * ty, sin * tx + cos * ty)); }
/// <summary> /// Creates a matrix which rotates around the given axis by the given angle. /// </summary> /// <param name="axis">The axis.</param> /// <param name="angle">The angle.</param> /// <param name="result">The resulting rotation matrix</param> public static void AxisAngle(ref FPVector axis, FP angle, out FPMatrix4x4 result) { // a: angle // x, y, z: unit vector for axis. // // Rotation matrix M can compute by using below equation. // // T T // M = uu + (cos a)( I-uu ) + (sin a)S // // Where: // // u = ( x, y, z ) // // [ 0 -z y ] // S = [ z 0 -x ] // [ -y x 0 ] // // [ 1 0 0 ] // I = [ 0 1 0 ] // [ 0 0 1 ] // // // [ xx+cosa*(1-xx) yx-cosa*yx-sina*z zx-cosa*xz+sina*y ] // M = [ xy-cosa*yx+sina*z yy+cosa(1-yy) yz-cosa*yz-sina*x ] // [ zx-cosa*zx-sina*y zy-cosa*zy+sina*x zz+cosa*(1-zz) ] // FP x = axis.x, y = axis.y, z = axis.z; FP sa = FPMath.Sin(angle), ca = FPMath.Cos(angle); FP xx = x * x, yy = y * y, zz = z * z; FP xy = x * y, xz = x * z, yz = y * z; result.M11 = xx + ca * (FP.One - xx); result.M12 = xy - ca * xy + sa * z; result.M13 = xz - ca * xz - sa * y; result.M14 = FP.Zero; result.M21 = xy - ca * xy - sa * z; result.M22 = yy + ca * (FP.One - yy); result.M23 = yz - ca * yz + sa * x; result.M24 = FP.Zero; result.M31 = xz - ca * xz + sa * y; result.M32 = yz - ca * yz - sa * x; result.M33 = zz + ca * (FP.One - zz); result.M34 = FP.Zero; result.M41 = FP.Zero; result.M42 = FP.Zero; result.M43 = FP.Zero; result.M44 = FP.One; }
public static FPQuaternion Euler(pfloat roll, pfloat pitch, pfloat yaw) { FPQuaternion quaternion; var num9 = roll * 0.5f; var num6 = FPMath.Sin(num9); var num5 = FPMath.Cos(num9); var num8 = pitch * 0.5f; var num4 = FPMath.Sin(num8); var num3 = FPMath.Cos(num8); var num7 = yaw * 0.5f; var num2 = FPMath.Sin(num7); var num = FPMath.Cos(num7); quaternion.x = ((num * num4) * num5) + ((num2 * num3) * num6); quaternion.y = ((num2 * num3) * num5) - ((num * num4) * num6); quaternion.z = ((num * num3) * num6) - ((num2 * num4) * num5); quaternion.w = ((num * num3) * num5) + ((num2 * num4) * num6); return(quaternion); }
// Runtime Properties Required for instantiating a destroyed projectile (load/save state) //private int opProjectileLayer; //private int opProjectileMask; void Start() { gameObject.AddComponent <SphereCollider>(); if (mirror == 1) { directionVector.x = -1; } if (totalHits == int.MinValue) { totalHits = data.totalHits; } Fix64 angleRad = ((Fix64)data.directionAngle / 180) * FPMath.Pi; movement = ((FPMath.Sin(angleRad) * FPVector.up) + (FPMath.Cos(angleRad) * directionVector)) * data.speed; fpTransform.Translate(new FPVector(data._castingOffSet.x * -mirror, data._castingOffSet.y, data._castingOffSet.z)); // Create Blockable Area blockableArea = new BlockArea(); blockableArea = data.blockableArea; // Create Hurtbox hurtBox = new HurtBox(); hurtBox = data.hurtBox; // Create Hitbox hitBox = new HitBox(); hitBox.shape = hurtBox.shape; hitBox._rect = hurtBox._rect; hitBox.followXBounds = hurtBox.followXBounds; hitBox.followYBounds = hurtBox.followYBounds; hitBox._radius = hurtBox._radius; hitBox._offSet = hurtBox._offSet; hitBox.position = gameObject.transform; UpdateRenderer(); if (data.spaceBetweenHits == Sizes.Small) { spaceBetweenHits = .15; } else if (data.spaceBetweenHits == Sizes.Medium) { spaceBetweenHits = .2; } else if (data.spaceBetweenHits == Sizes.High) { spaceBetweenHits = .3; } // Create Hit data hit = new Hit(); hit.hitType = data.hitType; hit.spaceBetweenHits = data.spaceBetweenHits; hit.hitStrength = data.hitStrength; hit.hitStunType = HitStunType.Frames; hit._hitStunOnHit = data.hitStunOnHit; hit._hitStunOnBlock = data.hitStunOnBlock; hit._damageOnHit = data._damageOnHit; hit._damageOnBlock = data._damageOnBlock; hit.damageScaling = data.damageScaling; hit.damageType = data.damageType; hit.groundHit = data.groundHit; hit.airHit = data.airHit; hit.downHit = data.downHit; hit.overrideHitEffects = data.overrideHitEffects; hit.armorBreaker = data.armorBreaker; hit.hitEffects = data.hitEffects; hit.resetPreviousHorizontalPush = data.resetPreviousHorizontalPush; hit.resetPreviousVerticalPush = data.resetPreviousVerticalPush; hit.applyDifferentAirForce = data.applyDifferentAirForce; hit.applyDifferentBlockForce = data.applyDifferentBlockForce; hit._pushForce = data._pushForce; hit._pushForceAir = data._pushForceAir; hit._pushForceBlock = data._pushForceBlock; hit.pullEnemyIn = new PullIn(); hit.pullEnemyIn.enemyBodyPart = BodyPart.none; if (data.mirrorOn2PSide && mirror > 0) { transform.localEulerAngles = new Vector3(transform.localEulerAngles.x, transform.localEulerAngles.y + 180, transform.localEulerAngles.z); } }