float SwapDis = .1f;//切换距离 #endregion void Start() { Instance = this; mTran = transform; Muzzle = mTran.Find("Muzzle"); Position = Camera.main.WorldToScreenPoint(mTran.position); Path = new RayPath(); }
public override double GetHitPointDistance(Shapes.Ray r) { double dist; Shapes.Ray subRay; Vect3 tmp = Position + _model.GetBoundingSphere().Position; if (RaySphere.IsRayOriginatingInSphere(r.Origin, r.Direction, tmp, _model.GetBoundingSphere().Radius)) { tmp = r.Origin - Position; subRay = new Shapes.Ray { Origin = tmp, Direction = r.Direction }; dist = 0; } else { dist = RaySphere.GetHitPointRaySphereDistance(r.Origin, r.Direction, tmp, _model.GetBoundingSphere().Radius); if (double.IsInfinity(dist)) { return(dist); } tmp = r.Origin + r.Direction * dist; tmp -= Position; subRay = new Shapes.Ray { Origin = tmp, Direction = r.Direction }; } var d = new CollisionData { Details = RayPath.GetFirstCollision(_model.GetTree(), subRay) }; if (!double.IsInfinity(d.Details.Distance)) { Vect3 hitPointLocal = subRay.Origin + subRay.Direction * d.Details.Distance; d.HitPointLocal = hitPointLocal; Vect3 hitPointGlobal = hitPointLocal + Position; d.HitPointGlobal = hitPointGlobal; return(d.Details.Distance + dist); } _lastCollision[Thread.CurrentThread] = d; return(d.Details.Distance); }
public List <Path> MultiplyMethod(Node tx, Terrain ter, ReceiveArea reArea, List <FrequencyBand> TxFrequencyBand) { List <Path> pathInfo = new List <Path>(); int cellAngle = 1; double divideAngle = 0.5; // if (tx.Position.x > reArea.OriginPoint.x && tx.Position.x < reArea.OriginPoint.x + reArea.rxLength && tx.Position.y > reArea.OriginPoint.y && tx.Position.y < reArea.OriginPoint.y + reArea.rxwidth)//若发射机在接收区域内或者正上方 if (RayPath.IsInTheArea(tx.Position, reArea))//若发射机在接收区域内 { divideAngle = 1; } // RayInfo.divideAngle = divideAngle; ClassNewRay[,] initArray = new ClassNewRay[360 / cellAngle + 1, 180 / cellAngle + 1]; ClassNewRay[,] temp = NewInit(tx, cellAngle, ter, reArea, TxFrequencyBand); for (int i = 0; i < 360 / cellAngle; i++) { for (int j = 0; j < 180 / cellAngle; j++) { initArray[i, j] = temp[i, j]; } } for (int i = 0; i < 360 / cellAngle; i++) { int temp1 = 180 / cellAngle; initArray[i, temp1] = initArray[i, 0]; } for (int i = 0; i < 180 / cellAngle; i++) { int temp1 = 360 / cellAngle; initArray[temp1, i] = initArray[0, i]; } initArray[360 / cellAngle, 180 / cellAngle] = initArray[0, 0]; for (int i = 0; i < 360 / cellAngle; i++) { for (int j = 0; j < 180 / cellAngle; j++) { if (initArray[i, j].Flag == true || initArray[i + 1, j].Flag == true || initArray[i, j + 1].Flag == true || initArray[i + 1, j + 1].Flag == true) { for (double m = i * cellAngle; m < (i + 1) * cellAngle; m += divideAngle) { for (double n = j * cellAngle; n < (j + 1) * cellAngle; n += divideAngle) { if (m != i * cellAngle || n != j * cellAngle) { SpectVector vector = new SpectVector(Math.Sin(Math.PI / 180 * n) * Math.Cos(Math.PI / 180 * m), Math.Sin(Math.Sin(Math.PI / 180 * n)) * Math.Sin(Math.PI / 180 * m), Math.Cos(Math.PI / 180 * n)); List <RayInfo> list = new List <RayInfo>(); list.Add(new RayInfo(tx.Position, vector)); List <Path> pathtemp = GetFanalPath(tx, ter, reArea, TxFrequencyBand, list); for (int a = 0; a < pathtemp.Count; a++) { pathInfo.Add(pathtemp[a]); } } } } } } } for (int i = 0; i < 360 / cellAngle; i++) { for (int j = 0; j < 180 / cellAngle; j++) { if (initArray[i, j].Flag == true) { pathInfo.AddRange(initArray[i, j].Path); } } } Console.WriteLine("算法完成:" + DateTime.Now); return(pathInfo); }