-- 在学习这个之前,建议复习下向量知识
local isCollison = false --碰撞状态
local dx,dy = 0, 0 --位置差
local fb_alpha = 0 --拉莫大
local fb_beta = 0 --贝塔
local fDelta = 1 --的塔值 - -
local c_r = 0 --半径和
local fDsitSqr = 0
local a,b,c = 0,0,0
local d = 0
local t = 1
--------------------------check hit func -----------------------------
-- 扇形圆心在 圆内
local function isCollisonFposWithCirlPos()
dx = cilre.x - fanshaped.x
dy = cilre.y - fanshaped.y
fDsitSqr = dx * dx + dy * dy
------is true >> collision
isCollison = fDsitSqr <= cilre.r * cilre.r and true or false
print("fDsitSqr value si ",fDsitSqr)
print("cilre.r * cilre.r ",cilre.r * cilre.r)
if isCollison then
return isCollison
end
end
dx = cilre.x - fanshaped.x
dy = cilre.y - fanshaped.y
fDsitSqr = dx * dx + dy * dy -- vec_1 = cc.pSub(cc.p(c.x,c.y),cc.p(f.x,f.y))
-- 圆心在扇形的两个向量之间。(矩阵 和 定比分点公式结合) 。
--bit 开头均为位运算。
local function isCollisonFVecWithCiclePos()
-- 叉乘的结果是一个向量,结果为Z轴的模 。绝对值为其 ab向量形成的四边形的面积,即为ab包围三角形面积2倍
-- 所以可以有第二种方法
--[[方法2 与 扇形的 三个向量 做叉乘。如果同号则在扇形(也适用于三角形)里面
-- vec_1 = cc.pSub(cc.p(c.x,c.y),cc.p(f.x,f.y))
-- local vec_1 = cc.pSub(cc.p(cilre.x,cilre.y),cc.p(fanshaped.vec_x,fanshaped.vec_y))
-- local vec_2 = cc.pSub(cc.p(cilre.x,cilre.y),cc.p(fanshaped.vec_x2,fanshaped.vec_y_2))
-- local vec_3 = cc.pSub(cc.p(cilre.x,cilre.y),cc.p(fanshaped.x,fanshaped.y))
-- local vx1 = cc.pCross(vec_1,vec_2)
-- local vx2 = cc.pCross(vec_2,vec_3)
-- local vx3 = cc.pCross(vec_3,vec_1)
-- 采取 位运算更快判断是否同号
-- if (bit._or(vx1,vx2) < 0 and bit._or(vx2,vx3) < 0 and bit._or(vx1,vx3) < 0) or (bit._or(vx1,vx2) < 0 and bit._or(vx2,vx3) < 0 and bit._or(vx1,vx3) > 0) then
在内部
end
-- print(" vx vx vx ",vx1,vx2,vx3)]]
fDelta = fanshaped.vec_x * fanshaped.vec_y_2 - fanshaped.vec_x2 * fanshaped.vec_y
fb_alpha = (dx * fanshaped.vec_y_2 - dy * fanshaped.vec_x2) / fDelta
fb_beta = (-dx * fanshaped.vec_y + dy * fanshaped.vec_x) / fDelta
if fb_alpha >= 0 and fb_beta >= 0 then
ar = fanshaped.r + cilre.r
if (fDsitSqr) <= ar * ar then
isCollison = true
return isCollison
end
end
end
---------暂时就考虑这2种情况吧
isCollison = isCollisonFposWithCirlPos()
if isCollison then
return isCollison
elseif not isCollison then
isCollison = isCollisonFVecWithCiclePos()
return isCollison
else
end