/// <summary> /// Sweeps a convex shape against the physics world reporting all hits on the path that are not ignored by the filter, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="shape">Shape to sweep</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="sweepRules">Collision rules to filter the sweep hits, anything above "NoSolver" is ignored</param> /// <param name="outSweepResults">All overlaps on the sweep path</param> /// <returns>True if any object was hit</returns> public bool MultiSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionRules sweepRules, List <SRaycastResult> outSweepResults) { SimpleCollisionRulesOwner rulesOwner = new SimpleCollisionRulesOwner(sweepRules); RigidTransform startTransform = new RigidTransform(startPos.ToBepu(), rotation.ToBepu()); Vector3 sweepVector = sweep.ToBepu(); List <RayCastResult> physicsResults = new List <RayCastResult>(); if (m_physicSpace.ConvexCast(shape, ref startTransform, ref sweepVector, GetOverlapFilter(rulesOwner), physicsResults)) { foreach (RayCastResult physicsResult in physicsResults) { if (physicsResult.HitObject.Tag is CEntity gameEntity) { CollisionRule rule = CollisionRules.GetCollisionRule(physicsResult.HitObject, rulesOwner); SRaycastResult gameResult = new SRaycastResult() { HitEntity = gameEntity, Location = physicsResult.HitData.Location.ToSharp(), Normal = -physicsResult.HitData.Normal.ToSharp(), Distance = physicsResult.HitData.T, bIsSolidHit = rule <= CollisionRule.Normal }; outSweepResults.Add(gameResult); } } return(outSweepResults.Count > 0); } return(false); }
public static Vector3 _newgetdirleft(SharpDX.Quaternion rotation) { Vector3 dirleft; //left vector dirleft.X = 1 - 2 * (rotation.Y * rotation.Y + rotation.Z * rotation.Z); dirleft.Y = 2 * (rotation.X * rotation.Y + rotation.W * rotation.Z); dirleft.Z = 2 * (rotation.X * rotation.Z - rotation.W * rotation.Y); return(dirleft); }
public static Vector3 _newgetdirup(SharpDX.Quaternion rotation) { Vector3 dirup; //up vector dirup.X = 2 * (rotation.X * rotation.Y - rotation.W * rotation.Z); dirup.Y = 1 - 2 * (rotation.X * rotation.X + rotation.Z * rotation.Z); dirup.Z = 2 * (rotation.Y * rotation.Z + rotation.W * rotation.X); return(dirup); }
public static Vector3 _newgetdirforward(SharpDX.Quaternion rotation) { Vector3 dirforward; //forward vector dirforward.X = 2 * (rotation.X * rotation.Z + rotation.W * rotation.Y); dirforward.Y = 2 * (rotation.Y * rotation.Z - rotation.W * rotation.X); dirforward.Z = 1 - 2 * (rotation.X * rotation.X + rotation.Y * rotation.Y); return(dirforward); }
//https://www.gamedev.net/forums/topic/56471-extracting-direction-vectors-from-quaternion/ public static void _newgetDirectiontotal(SharpDX.Quaternion rotation, out Vector3 forward, out Vector3 left, out Vector3 up) { //forward vector forward.X = 2 * (rotation.X * rotation.Z + rotation.W * rotation.Y); forward.Y = 2 * (rotation.Y * rotation.Z - rotation.W * rotation.X); forward.Z = 1 - 2 * (rotation.X * rotation.X + rotation.Y * rotation.Y); //up vector up.X = 2 * (rotation.X * rotation.Y - rotation.W * rotation.Z); up.Y = 1 - 2 * (rotation.X * rotation.X + rotation.Z * rotation.Z); up.Z = 2 * (rotation.Y * rotation.Z + rotation.W * rotation.X); //left vector left.X = 1 - 2 * (rotation.Y * rotation.Y + rotation.Z * rotation.Z); left.Y = 2 * (rotation.X * rotation.Y + rotation.W * rotation.Z); left.Z = 2 * (rotation.X * rotation.Z - rotation.W * rotation.Y); }
/// <summary> /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="shape">Shape to sweep</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="filter">Function to filter hits</param> /// <param name="outSweepResult">Closest hit to the start location</param> /// <returns>True if any object was hit</returns> public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, Func <BroadPhaseEntry, bool> filter, ref SRaycastResult outSweepResult) { RigidTransform startTransform = new RigidTransform(startPos.ToBepu(), rotation.ToBepu()); Vector3 sweepVector = sweep.ToBepu(); if (m_physicSpace.ConvexCast(shape, ref startTransform, ref sweepVector, filter, out RayCastResult result)) { if (result.HitObject.Tag is CEntity gameEntity) { outSweepResult.HitEntity = gameEntity; outSweepResult.Location = result.HitData.Location.ToSharp(); outSweepResult.Normal = -result.HitData.Normal.ToSharp(); outSweepResult.Distance = result.HitData.T; outSweepResult.bIsSolidHit = true; return(true); } } return(false); }
/* * public float sc_check_distance_sebastian_lague_node_3d() * { * if (dstX > dstZ) * { * if (dstX > dstY) * { * return 14 * dstY + 14 * dstZ + 10 * (dstX - dstZ) + 10 * (dstX - dstY); * } * else * { * return 14 * dstX + 14 * dstZ + 10 * (dstX - dstZ) + 10 * (dstY - dstX); * } * } * * //calculating x * if (dstX > dstY && dstX > dstZ) * { * var part_00 = 14 * dstY + 10 * (dstX - dstY); * var part_01 = 14 * dstZ + 10 * (dstX - dstZ); * return part_00 + part_01; * } * else if (dstX > dstY && dstX < dstZ) * { * var part_00 = 14 * dstY + 10 * (dstX - dstY); * var part_01 = 14 * dstX + 10 * (dstZ - dstX); * return part_00 + part_01; * } * else if (dstX < dstY && dstX < dstZ) * { * var part_00 = 14 * dstX + 10 * (dstY - dstX); * var part_01 = 14 * dstX + 10 * (dstZ - dstX); * return part_00 + part_01; * } * else if (dstX < dstY && dstX > dstZ) * { * var part_00 = 14 * dstX + 10 * (dstY - dstX); * var part_01 = 14 * dstZ + 10 * (dstX - dstZ); * return part_00 + part_01; * } * //calculating y * else if (dstY > dstX && dstY > dstZ) * { * var part_00 = 14 * dstX + 10 * (dstY - dstX); * var part_01 = 14 * dstZ + 10 * (dstY - dstZ); * return part_00 + part_01; * } * else if (dstY > dstX && dstY < dstZ) * { * var part_00 = 14 * dstX + 10 * (dstY - dstX); * var part_01 = 14 * dstY + 10 * (dstZ - dstY); * return part_00 + part_01; * } * else if (dstY < dstX && dstY < dstZ) * { * var part_00 = 14 * dstY + 10 * (dstX - dstY); * var part_01 = 14 * dstY + 10 * (dstZ - dstY); * return part_00 + part_01; * } * else if (dstY < dstX && dstY > dstZ) * { * var part_00 = 14 * dstY + 10 * (dstX - dstY); * var part_01 = 14 * dstZ + 10 * (dstY - dstZ); * return part_00 + part_01; * } * * //calculating z * else if (dstZ > dstX && dstZ > dstY) * { * var part_00 = 14 * dstX + 10 * (dstZ - dstX); * var part_01 = 14 * dstY + 10 * (dstZ - dstY); * return part_00 + part_01; * } * else if (dstZ > dstX && dstZ < dstY) * { * var part_00 = 14 * dstX + 10 * (dstZ - dstX); * var part_01 = 14 * dstZ + 10 * (dstY - dstZ); * return part_00 + part_01; * } * else if (dstZ < dstX && dstZ < dstY) * { * var part_00 = 14 * dstZ + 10 * (dstX - dstZ); * var part_01 = 14 * dstZ + 10 * (dstY - dstZ); * return part_00 + part_01; * } * else if (dstZ < dstX && dstZ > dstY) * { * var part_00 = 14 * dstZ + 10 * (dstX - dstZ); * var part_01 = 14 * dstY + 10 * (dstZ - dstY); * return part_00 + part_01; * }*/ //calculating diagonals ? not sure that covers them all. and it doesnt work /*else * { * var part_00 = 10 * dstX; //14 * var part_01 = 10 * dstY; //14 * var part_02 = 10 * dstZ; //14 * return 10; //part_00 + part_01 + part_02 * } * }*/ //https://pastebin.com/fAFp6NnN // Also found on the unity3D forums. public static Vector3 _getDirection(Vector3 value, SharpDX.Quaternion rotation) { Vector3 vector; double num12 = rotation.X + rotation.X; double num2 = rotation.Y + rotation.Y; double num = rotation.Z + rotation.Z; double num11 = rotation.W * num12; double num10 = rotation.W * num2; double num9 = rotation.W * num; double num8 = rotation.X * num12; double num7 = rotation.X * num2; double num6 = rotation.X * num; double num5 = rotation.Y * num2; double num4 = rotation.Y * num; double num3 = rotation.Z * num; double num15 = ((value.X * ((1f - num5) - num3)) + (value.Y * (num7 - num9))) + (value.Z * (num6 + num10)); double num14 = ((value.X * (num7 + num9)) + (value.Y * ((1f - num8) - num3))) + (value.Z * (num4 - num11)); double num13 = ((value.X * (num6 - num10)) + (value.Y * (num4 + num11))) + (value.Z * ((1f - num8) - num5)); vector.X = (float)num15; vector.Y = (float)num14; vector.Z = (float)num13; return(vector); }
/// <summary> /// Sweeps a capsule against the physics world reporting all hits on the path even if they ignore collisions, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="length">Length of the capsule</param> /// <param name="radius">Radius of the capsule</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="outSweepResults">All overlaps on the sweep path</param> /// <returns>True if any object was hit</returns> public bool CapsuleMultiSweep(float length, float radius, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, List <SRaycastResult> outSweepResults) { CapsuleShape capsuleShape = new CapsuleShape(length, radius); return(MultiSweep(capsuleShape, ref startPos, ref rotation, ref sweep, outSweepResults)); }
/// <summary> /// Sweeps a capsule against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="length">Length of the capsule</param> /// <param name="radius">Radius of the capsule</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="group">Collision group to filter the sweep hits, anything above "Normal" is ignored</param> /// <param name="outSweepResult">Closest hit to the start location</param> /// <returns>True if any object was hit</returns> public bool CapsuleSweep(float length, float radius, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionGroup group, ref SRaycastResult outSweepResult) { CapsuleShape capsuleShape = new CapsuleShape(length, radius); return(ConvexSweep(capsuleShape, ref startPos, ref rotation, ref sweep, group, ref outSweepResult)); }
/// <summary> /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="shape">Shape to sweep</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="group">Collision group to filter the sweep hits, anything above "Normal" is ignored</param> /// <param name="outSweepResult">Closest hit to the start location</param> /// <returns>True if any object was hit</returns> public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionGroup group, ref SRaycastResult outSweepResult) { return(ConvexSweep(shape, ref startPos, ref rotation, ref sweep, GetSolidFilter(group), ref outSweepResult)); }
/// <summary> /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="shape">Shape to sweep</param> /// <param name="startPos">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweep">Direction in which to sweep, the length of the vector is the length of the sweep</param> /// <param name="sweepRules">Collision rules to filter the sweep hits, anything above "Normal" is ignored</param> /// <param name="outSweepResult">Closest hit to the start location</param> /// <returns>True if any object was hit</returns> public bool ConvexSweep(ConvexShape shape, ref SharpDX.Vector3 startPos, ref SharpDX.Quaternion rotation, ref SharpDX.Vector3 sweep, CollisionRules sweepRules, ref SRaycastResult outSweepResult) { SimpleCollisionRulesOwner rulesOwner = new SimpleCollisionRulesOwner(sweepRules); return(ConvexSweep(shape, ref startPos, ref rotation, ref sweep, GetSolidFilter(rulesOwner), ref outSweepResult)); }
/// <summary> /// Sweeps a convex shape against the physics world reporting the closest hit to the start location, beware convex sweeps can be very costly especially if they are long /// </summary> /// <param name="shape">Shape to sweep</param> /// <param name="startPosition">Location to start the sweep from</param> /// <param name="rotation">Rotation of the shape during the sweep</param> /// <param name="sweepDir">Direction in which to sweep</param> /// <param name="length">Length of the sweep</param> /// <param name="outSweepResult">Closest hit to the start location</param> /// <returns>True if any object was hit</returns> public bool ConvexSweep(ConvexShape shape, SharpDX.Vector3 startPosition, SharpDX.Quaternion rotation, SharpDX.Vector3 sweepDir, float length, ref SRaycastResult outSweepResult) { SharpDX.Vector3 sweep = sweepDir * length; return(ConvexSweep(shape, ref startPosition, ref rotation, ref sweep, ref outSweepResult)); }