上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 48 下一页
摘要: 1) 加速原理:排除掉那些不可能发生的碰撞检测,通过减少碰撞检测次数来加速。 2) 如何排除不可能发生的碰撞检测? 比如:现在要检测左上角的物体A和哪些物体发生了碰撞,最简单的方式就是用for循环,把场景中的所有物体都检测一遍,看是否发生了碰撞。 但我们一眼就能看出,其他3个都在角落里,不可能和物体 阅读全文
posted @ 2023-11-29 23:29 yanghui01 阅读(535) 评论(0) 推荐(0)
摘要: 效果 //求射线与线段交点 - 直线方程方式 public static bool IsRaySegmentIntersect(Vector2 o, Vector2 dir, Vector2 a, Vector2 b, out Vector2 point) { point = Vector2.zer 阅读全文
posted @ 2023-11-29 00:36 yanghui01 阅读(571) 评论(0) 推荐(0)
摘要: 1) 在两侧 2) 与端点重合 3) 在端点之间 判断共线 1) 用pa和pb判断 图1:pa和pb为0度,pa•pb=|pa|*|pb|*cos(0)=|pa|*|pb|; pa×pb=|pa|*|pb|*sin(0)=0 图2:p和端点重合,pa•pb=pa.x*pb.x+pa.y*pb.y=0 阅读全文
posted @ 2023-11-28 23:30 yanghui01 阅读(67) 评论(0) 推荐(0)
摘要: AABBTree加速碰撞检测的原理? 减少碰撞检测的执行次数。怎么减少呢?排除那些不可能发生碰撞的形状间的检测。 最简单粗暴的碰撞检测就是两个for循环嵌套 void ForLoopCheckIntersect() { for (int i = 0; i < m_RectList.Count; ++ 阅读全文
posted @ 2023-11-28 00:04 yanghui01 阅读(657) 评论(0) 推荐(0)
摘要: 向量点乘ap•ab,即p在线段ab上的投影结果 上图的两种情况(重叠和直角),p在线段ab上的投影结果都是0, 可以用if (ap.sqrMagnitude <= float.Epsilon)判断重叠,如果不重叠则是直角的情况 阅读全文
posted @ 2023-11-26 00:32 yanghui01 阅读(73) 评论(0) 推荐(0)
摘要: 直线的点斜公式 y=kx+t, k为直线斜率, t为直线在y轴上的交点; 直线与y轴平行时, k不存在, 方程为x=a, a为常量值; //两直线交点 - 直线点斜式 public static bool IsTwoLineIntersect2(float k1, float t1, float k 阅读全文
posted @ 2023-11-24 23:18 yanghui01 阅读(267) 评论(0) 推荐(0)
摘要: 测试代码会用到的基类 using System; using UnityEngine; public abstract class CollideTestBase : MonoBehaviour { [Range(0, 9)] public int m_ApiType = 1; [Range(1, 阅读全文
posted @ 2023-11-24 21:39 yanghui01 阅读(32) 评论(0) 推荐(0)
摘要: 效果 //点是否在射线上 public static bool IsPointOnRay(Vector2 o, Vector2 dir, Vector2 p) { var op = p - o; if (Mathf.Approximately(op.sqrMagnitude, 0)) //o和p重叠 阅读全文
posted @ 2023-11-23 23:19 yanghui01 阅读(72) 评论(0) 推荐(0)
摘要: //求两直线交点 - 直线方程组方式 public static bool IsTwoLineIntersect(Vector2 A, Vector2 B, Vector2 C, Vector2 D, out Vector2 point) { point = Vector2.zero; /** 1 阅读全文
posted @ 2023-11-23 22:51 yanghui01 阅读(132) 评论(0) 推荐(0)
摘要: 1) 点在三角形的边上时 AP=AE+AF (向量加法) 设AE=v*AB, AF=u*AC; 则AP=v*AB+u*AC(二元一次方程,u, v为我们引入的变量) 根据向量三点共线定理可知:u+v=1 2) 点在三角形内时 AE不变, 让AF变短一些, 当用u*AC表示AF时, u的值肯定也比1) 阅读全文
posted @ 2023-11-22 20:47 yanghui01 阅读(303) 评论(0) 推荐(0)
上一页 1 ··· 12 13 14 15 16 17 18 19 20 ··· 48 下一页