/** * Starts up a new trace ray using a new trace result. * * @param pos Starting position of the ray. * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. * @return Ray trace handle, which must be closed via CloseHandle(). */ public static Handle TR_TraceRayEx(float[] /*3*/ pos, float[] /*3*/ vec, int flags, RayType rtype) { throw new NotImplementedException(); }
public groundInfo(bool isGrd, Vector3 normal, float dist, RayType m_rayType) { isGrounded = isGrd; groundNormal = normal; distanceToGround = dist; rayType = m_rayType; }
public LaserRay(FPoint s, FPoint e, LaserRay src, LaserRayTerminator t, int d, bool g, object sign, object eign, float sd, Cannon tc, RayType rt) { Depth = d; InGlass = g; StartIgnoreObj = sign; EndIgnoreObj = eign; Start = s; End = e; Source = src; Terminator = t; TargetCannon = tc; TerminatorRays = new List <Tuple <LaserRay, LaserSource> >(); SourceDistance = sd; RayType = rt; #if DEBUG if (!Start.IsValid) { SAMLog.Error("LASER::Assert_1-SV", "!Start.IsValid"); } if (!End.IsValid) { SAMLog.Error("LASER::Assert_1-EV", "!End.IsValid"); } if ((End - Start).LengthSquared() < FloatMath.EPSILON7 * FloatMath.EPSILON7) { SAMLog.Error("LASER::Assert_1-ESV", "(End - Start).LengthSquared() < FloatMath.EPSILON7 * FloatMath.EPSILON7"); } #endif }
/** * Clips a ray to a particular entity. * * @param pos Starting position of the ray. * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. * @param entity Entity to clip to. * @return Ray trace handle, which must be closed via CloseHandle(). */ public static Handle TR_ClipRayToEntityEx(float[] /*3*/ pos, float[] /*3*/ vec, int flags, RayType rtype, int entity) { throw new NotImplementedException(); }
// 2018.12.04 public static NodeInfo oneRay(Vector3 pt, Vector3 pt1, RayType rayType) { Vector3 normal = new Vector3(0, 0, 1); Vector3 dir = pt1 - pt; NodeInfo ray = new NodeInfo(new Point(pt.x, pt.y, pt.z), new Point(pt1.x, pt1.y, pt1.z), null, null, 0, 0, normal, rayType, Vector3.getAngle(ref dir, ref normal) - Math.PI / 2.0); return(ray); }
/** * public enumerates over entities along a ray. This may find entities that are * close to the ray but do not actually intersect it. Use TR_Clip*RayToEntity * with TR_DidHit to check if the ray actually intersects the entity. * * @param pos Starting position of the ray. * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param mask Mask to use for the trace. See PARTITION_* flags. * @param rtype Method to calculate the ray direction. * @param public enumerator Function to use as public enumerator. For each entity found * along the ray, this function is called. * @param data Arbitrary data value to pass through to the public enumerator. */ public static void TR_EnumerateEntities(float[] /*3*/ pos, float[] /*3*/ vec, int mask, RayType rtype, TraceEntityEnumerator enumerator, any?data = null) { throw new NotImplementedException(); }
/** * Starts up a new trace ray using a new trace result and a customized * trace ray filter. * * Calling TR_Trace*Filter or TR_TraceRay*Ex from inside a filter * function is currently not allowed and may not work. * * @param pos Starting position of the ray. * @param vec Depending on RayType, it will be used as the ending * point, or the direction angle. * @param flags Trace flags. * @param rtype Method to calculate the ray direction. * @param filter Function to use as a filter. * @param data Arbitrary data value to pass through to the filter function. * @return Ray trace handle, which must be closed via CloseHandle(). */ public static Handle TR_TraceRayFilterEx(float[] /*3*/ pos, float[] /*3*/ vec, int flags, RayType rtype, TraceEntityFilter filter, any?data = null) { throw new NotImplementedException(); }
public LaserSource(LaserNetwork owner, FPoint position, Fraction fracNeutral, ILaserCannon userData, RayType t) { Owner = owner; Position = position; Type = t; LaserActive = false; LaserPowered = false; LaserFraction = fracNeutral; LaserRotation = 0f; UserData = userData; }
// 2018.12.11 public static NodeInfo createRay(ref Ray ray) { Vector3 dir = ray.m_b - ray.m_a; RayType rayType = RayType.Direction; Vector3 normal = new Vector3(0, 0, 1); double angle = Vector3.getAngle(ref dir, ref normal) - Math.PI / 2.0; NodeInfo rayInfo = new NodeInfo(new Point(ray.m_a.x, ray.m_a.y, ray.m_a.z), new Point(ray.m_b.x, ray.m_b.y, ray.m_b.z), null, null, 0, 0, normal, rayType, angle); return(rayInfo); }
//用于系数校正的 射线段构造函数 public NodeInfo(int cellID, int gxid, int gyid, int trajID, RayType rayType, double dis, double angle, double attenuation, double recePwr) { this.cellID = cellID; this.gxid = gxid; this.gyid = gyid; this.trajID = trajID; this.rayType = rayType; this.distance = dis; this.Angle = angle; this.attenuation = attenuation; this.recePwr = recePwr; }
private static string BuildVmessShareLink(RayType xrayType, V2raySettings settings) { var vmess = new Vmess { v = "2", add = settings.Domain, port = settings.Port.ToString(), id = settings.UUID, aid = "0", net = "", type = "none", host = "", path = "", tls = "tls", ps = "", }; switch (xrayType) { case RayType.VMESS_TCP: vmess.ps = "vmess-tcp-tls"; vmess.net = "tcp"; vmess.type = "http"; vmess.path = settings.VMESS_TCP_Path; break; case RayType.VMESS_WS: vmess.ps = "vmess-ws-tls"; vmess.net = "ws"; vmess.type = "none"; vmess.path = settings.VMESS_WS_Path; break; case RayType.VMESS_KCP: vmess.ps = "vmess-mKCP"; vmess.port = settings.VMESS_KCP_Port.ToString(); vmess.net = "kcp"; vmess.type = settings.VMESS_KCP_Type; vmess.path = settings.VMESS_KCP_Seed; vmess.tls = ""; break; default: return(string.Empty); } var base64Url = Utils.Base64Encode(JsonConvert.SerializeObject(vmess)); return($"vmess://" + base64Url); }
//用于系数校正的 射线段构造函数,参数包含射线段的起点和终点 public NodeInfo(int cellID, int gxid, int gyid, int trajID, RayType rayType, double dis, double angle, double attenuation, double recePwr, Point pointOfIncidence, Point crossPoint) { this.cellID = cellID; this.gxid = gxid; this.gyid = gyid; this.trajID = trajID; this.rayType = rayType; this.distance = dis; this.Angle = angle; this.attenuation = attenuation; this.recePwr = recePwr; this.PointOfIncidence = pointOfIncidence; this.CrossPoint = crossPoint; }
/// <summary> /// 根据xray类型获取路径 /// </summary> /// <param name="type"></param> /// <returns></returns> public string GetPath(RayType type) { switch (type) { case RayType.VLESS_WS: return(VLESS_WS_Path); case RayType.VMESS_TCP: return(VMESS_TCP_Path); case RayType.VMESS_WS: return(VMESS_WS_Path); default: return(string.Empty); } }
void LaunchCallbacks(CharacterRay2D[] rays, RayType rayType) { m_curHits.Clear(); for (int i = 0; i < rays.Length; i++) { CharacterRay2D curRay = rays[i]; // do not send message twice for same collider & same raytype if (curRay.m_collider != null && !m_curHits.Contains(curRay.m_collider)) { m_curHits.Add(curRay.m_collider); APHitable hitable = curRay.m_collider.GetComponent <APHitable>(); if (hitable) { hitable.OnCharacterTouch(m_character, rayType); } } } }
/// <summary> /// Mark all future points on the current path that are walkable/castable as visited. /// </summary> /// <param name="maxDistance">beyond this range nodes will be left alone</param> /// <param name="type">the type of check to make</param> public void AdvanceNavigatorPath(float maxDistance, RayType type) { var path = Core.DBNavProvider.CurrentPath; if (path == null || path.Count == 0) { return; } var startPosition = ZetaDia.Me.Position; for (int i = path.Index; i < path.Count; i++) { var point = path[i]; if (startPosition.Distance(point) > maxDistance || type == RayType.Cast && !CanRayCast(startPosition, point) || type == RayType.Walk && !CanRayWalk(startPosition, point)) { path.Index = i; break; } } }
public static string Build(RayType xrayType, V2raySettings settings) { switch (xrayType) { case RayType.VLESS_TCP: case RayType.VLESS_TCP_XTLS: case RayType.VLESS_WS: case RayType.VLESS_KCP: case RayType.VLESS_gRPC: case RayType.Trojan_TCP: return(BuildVlessShareLink(xrayType, settings)); case RayType.VMESS_TCP: case RayType.VMESS_WS: case RayType.VMESS_KCP: return(BuildVmessShareLink(xrayType, settings)); case RayType.ShadowsocksAEAD: return(BuildShadowSocksShareLink(settings)); default: return(string.Empty); } }
public NodeInfo(Point PointOfIncidence, Point CrossPoint, Point SideFromPoint, Point SideToPoint, int buildingID, double BuildingHeight, Vector3 normal, RayType rayType, double angle) { this.distance = getDistanceOf3DPoints(PointOfIncidence, CrossPoint); this.PointOfIncidence = PointOfIncidence; this.CrossPoint = CrossPoint; this.SideFromPoint = SideFromPoint; this.SideToPoint = SideToPoint; this.buildingID = buildingID; this.BuildingHeight = BuildingHeight; this.Normal = normal; this.rayType = rayType; this.Angle = angle; }
public NodeInfo(RayType rayType, double dis, double angle) { this.rayType = rayType; this.distance = dis; this.Angle = angle; }
public NodeInfo(Point PointOfIncidence, Point CrossPoint, RayType rayType, double angle) { this.distance = getDistanceOf3DPoints(PointOfIncidence, CrossPoint); this.rayType = rayType; this.Angle = angle; }
/// <summary> /// 判断点是否在多边形内,废弃方法,替代方法 PointInPolygon /// </summary> /// <param name="points"></param> /// <param name="point"></param> /// <param name="rayType"></param> /// <param name="diffractType"></param> /// <returns></returns> public static bool PointInBox2(Point[] points, Point point, out RayType rayType) { double sumTheta = 0; rayType = RayType.HReflection; Vector3D preV = new Vector3D(), nextV = new Vector3D(); for (int i = 0; i < points.Length - 1; i++) { double alfa = 0; preV.XComponent = points[i].X - point.X; preV.YComponent = points[i].Y - point.Y; preV.ZComponent = 0;// points[i].Z - point.Z; if (i == points.Length - 2) { nextV.XComponent = points[0].X - point.X; nextV.YComponent = points[0].Y - point.Y; nextV.ZComponent = 0;// points[0].Z - point.Z; } else { nextV.XComponent = points[i + 1].X - point.X; nextV.YComponent = points[i + 1].Y - point.Y; nextV.ZComponent = 0;// points[i + 1].Z - point.Z; } //multiVec=0 则说明三点共线 >0说明 nextV在preV的逆时针方向 否侧 nextV在preV的顺时针方向 //Double multiVec = multiDot(preV, nextV, point); double cos = GeometricUtilities.getAngleofVector3Ds(preV, nextV); alfa = Math.Acos(cos) * 180 / Math.PI; if (alfa > 180) { alfa = 360 - alfa; } //multiVec=0 则说明三点共线 >0说明 nextV在preV的逆时针方向 否侧 nextV在preV的顺时针方向 Double multiVec = preV.XComponent * nextV.YComponent - nextV.XComponent * preV.YComponent; if (multiVec > 0) { sumTheta = sumTheta + alfa; } else if (multiVec < 0) { sumTheta = sumTheta - alfa; } else { rayType = RayType.HDiffraction; return(true); } } if (Math.Abs(Math.Abs(sumTheta) - 360) < 0.000001) { return(true); } else { return(false); } }
private static string BuildVlessShareLink(RayType xrayType, V2raySettings settings) { var _protocol = string.Empty; var _uuid = settings.UUID; var _domain = settings.Domain; var _port = settings.Port; var _type = string.Empty; var _encryption = "none"; var _security = "tls"; var _path = "/"; var _host = settings.Domain; var _descriptiveText = string.Empty; var _headerType = "none"; var _seed = string.Empty; switch (xrayType) { case RayType.VLESS_TCP: _protocol = "vless"; _type = "tcp"; _descriptiveText = "vless-tcp-tls"; break; case RayType.VLESS_TCP_XTLS: _protocol = "vless"; _type = "tcp"; _security = "xtls"; _descriptiveText = "vless-tcp-xtls"; break; case RayType.VLESS_WS: _protocol = "vless"; _type = "ws"; _path = settings.VLESS_WS_Path; _descriptiveText = "vless-ws-tls"; break; case RayType.VLESS_KCP: _protocol = "vless"; _type = "kcp"; _headerType = settings.VLESS_KCP_Type; _seed = settings.VLESS_KCP_Seed; _port = settings.VLESS_KCP_Port; _security = "none"; _descriptiveText = "vless-mKCP"; break; case RayType.VLESS_gRPC: _protocol = "vless"; _type = "grpc"; _port = settings.VLESS_gRPC_Port; _descriptiveText = "vless-gRPC"; break; case RayType.Trojan_TCP: _protocol = "trojan"; _uuid = settings.TrojanPassword; _descriptiveText = "trojan-tcp"; break; default: throw new Exception("暂未实现的协议"); } string parametersURL = string.Empty; if (xrayType != RayType.Trojan_TCP) { // 4.3 传输层相关段 parametersURL = $"?type={_type}&encryption={_encryption}&security={_security}&path={HttpUtility.UrlEncode(_path)}&headerType={_headerType}"; // kcp if (xrayType == RayType.VLESS_KCP) { parametersURL += $"&seed={_seed}"; } // 4.4 TLS 相关段 if (xrayType == RayType.VLESS_TCP_XTLS) { parametersURL += "&flow=xtls-rprx-direct"; } if (xrayType == RayType.VLESS_gRPC) { parametersURL += $"&serviceName={settings.VLESS_gRPC_ServiceName}&mode=gun"; } } return($"{_protocol}://{HttpUtility.UrlEncode(_uuid)}@{_domain}:{_port}{parametersURL}#{HttpUtility.UrlEncode(_descriptiveText)}"); }
/// <summary> /// Main and only required method. Registers ray with of type RayType and optional number of parameters /// </summary> /// <param name="rayType">Type of ray from RayType enum</param> /// <param name="parameters">Arbitrary number of any objects used as parameters. RegisterRay itself must decide what to do with them</param> public abstract void RegisterRay(RayType rayType, params object[] parameters);
// key:"cellid,gxid,gyid" // value: TrajInfo{ key: "trajID", value: List<NodeInfo> } public static Dictionary <string, TrajInfo> buildingGrids(ref DataTable tb) { Dictionary <string, TrajInfo> rayDic = new Dictionary <string, TrajInfo>(); //DataTable tb = new DataTable(); //tb = IbatisHelper.ExecuteQueryForDataTable("getRays", null); double h = (int)GridHelper.getInstance().getGHeight(); if (tb.Rows.Count < 1) { return(rayDic); } else { for (int i = 0; i < tb.Rows.Count; i++) { int cellID = Convert.ToInt32(tb.Rows[i]["cellID"].ToString()); int Gxid = Convert.ToInt32(tb.Rows[i]["gxid"].ToString()); int Gyid = Convert.ToInt32(tb.Rows[i]["gyid"].ToString()); int trajID = Convert.ToInt32(tb.Rows[i]["trajID"].ToString()); double EmitPwrW = Convert.ToDouble(tb.Rows[i]["emitPwrW"].ToString()); int rayType = Convert.ToInt32(tb.Rows[i]["rayType"].ToString()); int rayLevel = Convert.ToInt32(tb.Rows[i]["rayLevel"].ToString()); double distance = Convert.ToDouble(tb.Rows[i]["distance"].ToString()); double Angle = Convert.ToDouble(tb.Rows[i]["angle"].ToString()); double attenuation = Convert.ToDouble(tb.Rows[i]["attenuation"].ToString()); double RecePwrW = Convert.ToDouble(tb.Rows[i]["recePwrW"].ToString()); string scen = tb.Rows[i]["proportion"].ToString(); int ptScen = Convert.ToInt32(tb.Rows[i]["endPointScen"].ToString()); RayType rayT = new RayType(); switch (rayType) { case 0: rayT = RayType.Direction; break; case 1: rayT = RayType.VReflection; break; case 2: rayT = RayType.HReflection; break; case 3: rayT = RayType.HDiffraction; break; case 4: rayT = RayType.VDiffraction; break; } NodeInfo ni = new NodeInfo(cellID, Gxid, Gyid, trajID, rayT, distance, Angle, attenuation, RecePwrW); // 射线经过各场景的距离 string[] scenArr = scen.Split(';'); int n = scenArr.Count(); ni.trajScen = new double[n]; for (int j = 0; j < n; j++) { ni.trajScen[j] = Convert.ToDouble(scenArr[j]) * distance; } ni.endPointScen = ptScen; string key = string.Format("{0},{1},{2}", cellID, Gxid, Gyid); if (rayDic.Keys.Contains(key)) // 存在 rayDic[key] { if (rayDic[key].traj.Keys.Contains(trajID)) // 存在 rayDic[key].traj[trajID] { rayDic[key].traj[trajID].rayList.Add(ni); if (EmitPwrW != 0) // 射线轨迹的第一段 { rayDic[key].traj[trajID].emitPwrW = EmitPwrW; } if (ni.recePwr != 0) // 射线轨迹的最后一段 { rayDic[key].traj[trajID].recePwrW = ni.recePwr; rayDic[key].sumReceivePwrW += ni.recePwr; } } else { RayInfo rays = new RayInfo(); rays.rayList.Add(ni); rayDic[key].traj[trajID] = rays; if (EmitPwrW != 0) // 射线轨迹的第一段 { rayDic[key].traj[trajID].emitPwrW = EmitPwrW; } if (ni.recePwr != 0) // 射线轨迹的最后一段 { rayDic[key].traj[trajID].recePwrW = ni.recePwr; rayDic[key].sumReceivePwrW += ni.recePwr; } } } else { RayInfo rays = new RayInfo(); rays.rayList.Add(ni); TrajInfo ti = new TrajInfo(); ti.traj[trajID] = rays; rayDic[key] = ti; if (EmitPwrW != 0) // 射线轨迹的第一段 { rayDic[key].traj[trajID].emitPwrW = EmitPwrW; } if (ni.recePwr != 0) // 射线轨迹的最后一段 { rayDic[key].traj[trajID].recePwrW = ni.recePwr; rayDic[key].sumReceivePwrW += ni.recePwr; } } } } foreach (string key in rayDic.Keys) { rayDic[key].sumPwrDbm = convertw2dbm(rayDic[key].sumReceivePwrW); } return(rayDic); }
private void CheckCollision(RaycastHit2D hit, RayType rayType) { if (hit.collider != null) { OnCollisionCustomAction customAction = hit.collider.GetComponent <OnCollisionCustomAction>(); float hitPointCoordinate = 0; switch (hit.collider.name) { case "Top": if (rayType == RayType.SouthWestDown) { hitPointCoordinate = hit.point.y + spriteHalfSizeY * spriteScaleY; hitSouthWestDown = true; } else if (rayType == RayType.SouthEastDown) { hitPointCoordinate = hit.point.y + spriteHalfSizeY * spriteScaleY; hitSouthEastDown = true; } if ((hitSouthWestDown || hitSouthEastDown) && !downIsBeingClamped) { engine.ClampYBelow(true, hitPointCoordinate, customAction); downIsBeingClamped = true; } break; case "Bottom": if (rayType == RayType.NorthWestTop) { hitPointCoordinate = hit.point.y - spriteHalfSizeY * spriteScaleY; hitNorthWestTop = true; } else if (rayType == RayType.NorthEastTop) { hitPointCoordinate = hit.point.y - spriteHalfSizeY * spriteScaleY; hitNorthEastTop = true; } if ((hitNorthWestTop || hitNorthEastTop) && !topIsBeingClamped) { engine.ClampYAbove(true, hitPointCoordinate, customAction); topIsBeingClamped = true; } break; case "Left": if (rayType == RayType.SouthWestLeft) { hitPointCoordinate = hit.point.x + spriteHalfSizeX * spriteScaleX; hitSouthWestLeft = true; } else if (rayType == RayType.NorthWestLeft) { hitPointCoordinate = hit.point.x + spriteHalfSizeX * spriteScaleX; hitNorthWestLeft = true; } if ((hitSouthWestLeft || hitNorthWestLeft) && !leftIsBeingClamped) { engine.ClampXBelow(true, hitPointCoordinate, customAction); leftIsBeingClamped = true; } break; case "Right": if (rayType == RayType.SouthEastRight) { hitPointCoordinate = hit.point.x - spriteHalfSizeX * spriteScaleX; hitSouthEastRight = true; } else if (rayType == RayType.NorthEastRight) { hitPointCoordinate = hit.point.x - spriteHalfSizeX * spriteScaleX; hitNorthEastRight = true; } if ((hitNorthEastRight || hitSouthEastRight) && !rightIsBeingClamped) { engine.ClampXAbove(true, hitPointCoordinate, customAction); rightIsBeingClamped = true; } break; default: break; } } else { switch (rayType) { // Bottom case RayType.SouthWestDown: downIsBeingClamped = false; hitSouthWestDown = false; break; case RayType.SouthEastDown: downIsBeingClamped = false; hitSouthEastDown = false; break; // Top case RayType.NorthWestTop: topIsBeingClamped = false; hitNorthWestTop = false; break; case RayType.NorthEastTop: topIsBeingClamped = false; hitNorthEastTop = false; break; // Left case RayType.SouthWestLeft: leftIsBeingClamped = false; hitSouthWestLeft = false; break; case RayType.NorthWestLeft: leftIsBeingClamped = false; hitNorthWestLeft = false; break; // Right case RayType.SouthEastRight: rightIsBeingClamped = false; hitSouthEastRight = false; break; case RayType.NorthEastRight: rightIsBeingClamped = false; hitNorthEastRight = false; break; default: break; } } }
private void BuildQrCode(RayType type) { string shareLink = string.Empty; switch (type) { case RayType.VLESS_TCP_XTLS: shareLink = Settings.VLESS_TCP_XTLS_ShareLink; break; case RayType.VLESS_TCP: shareLink = Settings.VLESS_TCP_ShareLink; break; case RayType.VLESS_WS: shareLink = Settings.VLESS_WS_ShareLink; break; case RayType.VLESS_H2: break; case RayType.VLESS_KCP: shareLink = Settings.VLESS_KCP_ShareLink; break; case RayType.VLESS_gRPC: shareLink = Settings.VLESS_gRPC_ShareLink; break; case RayType.VMESS_TCP: shareLink = Settings.VMESS_TCP_ShareLink; break; case RayType.VMESS_WS: shareLink = Settings.VMESS_WS_ShareLink; break; case RayType.VMESS_H2: break; case RayType.VMESS_KCP: shareLink = Settings.VMESS_KCP_ShareLink; break; case RayType.Trojan_TCP: shareLink = Settings.Trojan_TCP_ShareLink; break; case RayType.Trojan_WS: break; case RayType.ShadowsocksAEAD: shareLink = Settings.ShadowSocksShareLink; break; default: break; } QRCodeGenerator qrGenerator = new QRCodeGenerator(); QRCodeData qrCodeData = qrGenerator.CreateQrCode(shareLink, QRCodeGenerator.ECCLevel.Q); QRCode qrCode = new QRCode(qrCodeData); Bitmap qrCodeImage = qrCode.GetGraphic(20); MemoryStream ms = new MemoryStream(); qrCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp); byte[] bytes = ms.GetBuffer(); ms.Close(); BitmapImage image = new BitmapImage(); image.BeginInit(); image.StreamSource = new MemoryStream(bytes); image.EndInit(); QrImage.Source = image; QrImage.Tag = type.ToString(); }
/* AABB and Ray Intersection Algorithm * * "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes" * by Martin Eisemann, Thorsten Grosch, Stefan Muller and Marcus Magnor * Computer Graphics Lab, TU Braunschweig, Germany and * University of Koblenz-Landau, Germany * * Breaks the 3 dimensions into 3 planes (xy, yz, xz) to perform * trivial calculations to determine if an intersect has occured. * * Conversion and Tweaking for Orchard Sun by Giawa */ /// <summary> /// Precalculates the slopes and 2D projections for intersection tests. /// </summary> private void PreCalculate() { inverse = 1.0f / direction; ibyj = direction.x * inverse.y; jbyi = direction.y * inverse.x; jbyk = direction.y * inverse.z; kbyj = direction.z * inverse.y; ibyk = direction.x * inverse.z; kbyi = direction.z * inverse.x; c_xy = origin.y - jbyi * origin.x; c_xz = origin.z - kbyi * origin.x; c_yx = origin.x - ibyj * origin.y; c_yz = origin.z - kbyj * origin.y; c_zx = origin.x - ibyk * origin.z; c_zy = origin.y - jbyk * origin.z; if (direction.x < 0) { if (direction.y < 0) { if (direction.z < 0) classification = RayType.MMM; else if (direction.z > 0) classification = RayType.MMP; else classification = RayType.MMO; } else { if (direction.z < 0) { classification = RayType.MPM; if (direction.y == 0) classification = RayType.MOM; } else { if ((direction.y == 0) && (direction.z == 0)) classification = RayType.MOO; else if (direction.z == 0) classification = RayType.MPO; else if (direction.y == 0) classification = RayType.MOP; else classification = RayType.MPP; } } } else { if (direction.y < 0) { if (direction.z < 0) { classification = RayType.PMM; if (direction.x == 0) classification = RayType.OMM; } else { if ((direction.x == 0) && (direction.z == 0)) classification = RayType.OMO; else if (direction.z == 0) classification = RayType.PMO; else if (direction.x == 0) classification = RayType.OMP; else classification = RayType.PMP; } } else { if (direction.z < 0) { if ((direction.x == 0) && (direction.y == 0)) classification = RayType.OOM; else if (direction.x == 0) classification = RayType.OPM; else if (direction.y == 0) classification = RayType.POM; else classification = RayType.PPM; } else { if (direction.x == 0) { if (direction.y == 0) classification = RayType.OOP; else if (direction.z == 0) classification = RayType.OPO; else classification = RayType.OPP; } else { if ((direction.y == 0) && (direction.z == 0)) classification = RayType.POO; else if (direction.y == 0) classification = RayType.POP; else if (direction.z == 0) classification = RayType.PPO; else classification = RayType.PPP; } } } } dirty = false; }
private Vector3 GetFurthestPathPosition(IndexedList <Vector3> path, float maxDistance, RayType type, bool updatePath) { if (path == null || path.Count == 0) { return(Vector3.Zero); } Vector3 startPosition = Core.Player.Position; Vector3 reachablePosition = startPosition; Vector3 unreachablePosition = path.LastOrDefault(); // Find closest valid path point; for (int i = path.Index; i < path.Count; i++) { var point = path[i]; if (startPosition.Distance(point) > maxDistance || type == RayType.Cast && !CanRayCast(startPosition, point) || type == RayType.Walk && !CanRayWalk(startPosition, point)) { if (updatePath) { path.Index = i; } unreachablePosition = point; break; } reachablePosition = point; } var distance = reachablePosition.Distance(unreachablePosition); const float incrementDistance = 2f; var totalSegments = distance / incrementDistance; // Find closest valid portion of path. for (int i = 0; i < totalSegments; i++) { var point = MathEx.CalculatePointFrom(unreachablePosition, reachablePosition, i * incrementDistance); if (startPosition.Distance(point) > maxDistance || type == RayType.Cast && !CanRayCast(startPosition, point) || type == RayType.Walk && !CanRayWalk(startPosition, point)) { break; } reachablePosition = point; } return(reachablePosition); }
public Ray(Point origin, Vector direction, RayType type) { this.Origin = origin; this.Direction = direction; this.Type = type; }
public Ray(Vector3 start, Vector3 direction) { X = start.X; Y = start.Y; Z = start.Z; I = direction.X; J = direction.Y; K = direction.Z; II = 1.0f / I; IJ = 1.0f / J; IK = 1.0f / K; R0 = start.X * J - I * start.Y; R1 = start.X * K - I * start.Z; R3 = start.Y * K - J * start.Z; // If direction.X/Y/Z are 0.0, for some reason they are getting treated as -0.0. // Fix that here if (II == Single.NegativeInfinity) II = Single.PositiveInfinity; if (IJ == Single.NegativeInfinity) IJ = Single.PositiveInfinity; if (IK == Single.NegativeInfinity) IK = Single.PositiveInfinity; if (I < 0f) { if (J < 0f) { if (K < 0f) Type = RayType.MMM; else Type = RayType.MMP; } else { if (K < 0f) Type = RayType.MPM; else Type = RayType.MPP; } } else { if (J < 0f) { if (K < 0f) Type = RayType.PMM; else Type = RayType.PMP; } else { if (K < 0f) Type = RayType.PPM; else Type = RayType.PPP; } } }
/* AABB and Ray Intersection Algorithm * * "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes" * by Martin Eisemann, Thorsten Grosch, Stefan Muller and Marcus Magnor * Computer Graphics Lab, TU Braunschweig, Germany and * University of Koblenz-Landau, Germany * * Breaks the 3 dimensions into 3 planes (xy, yz, xz) to perform * trivial calculations to determine if an intersect has occured. * * Conversion and Tweaking for Orchard Sun by Giawa */ /// <summary> /// Precalculates the slopes and 2D projections for intersection tests. /// </summary> private void PreCalculate() { inverse = new Vector3(1.0f / direction.X, 1.0f / direction.Y, 1.0f / direction.Z); ibyj = direction.X * inverse.Y; jbyi = direction.Y * inverse.X; jbyk = direction.Y * inverse.Z; kbyj = direction.Z * inverse.Y; ibyk = direction.X * inverse.Z; kbyi = direction.Z * inverse.X; c_xy = origin.Y - jbyi * origin.X; c_xz = origin.Z - kbyi * origin.X; c_yx = origin.X - ibyj * origin.Y; c_yz = origin.Z - kbyj * origin.Y; c_zx = origin.X - ibyk * origin.Z; c_zy = origin.Y - jbyk * origin.Z; if (direction.X < 0) { if (direction.Y < 0) { if (direction.Z < 0) { classification = RayType.MMM; } else if (direction.Z > 0) { classification = RayType.MMP; } else { classification = RayType.MMO; } } else { if (direction.Z < 0) { classification = RayType.MPM; if (direction.Y == 0) { classification = RayType.MOM; } } else { if ((direction.Y == 0) && (direction.Z == 0)) { classification = RayType.MOO; } else if (direction.Z == 0) { classification = RayType.MPO; } else if (direction.Y == 0) { classification = RayType.MOP; } else { classification = RayType.MPP; } } } } else { if (direction.Y < 0) { if (direction.Z < 0) { classification = RayType.PMM; if (direction.X == 0) { classification = RayType.OMM; } } else { if ((direction.X == 0) && (direction.Z == 0)) { classification = RayType.OMO; } else if (direction.Z == 0) { classification = RayType.PMO; } else if (direction.X == 0) { classification = RayType.OMP; } else { classification = RayType.PMP; } } } else { if (direction.Z < 0) { if ((direction.X == 0) && (direction.Y == 0)) { classification = RayType.OOM; } else if (direction.X == 0) { classification = RayType.OPM; } else if (direction.Y == 0) { classification = RayType.POM; } else { classification = RayType.PPM; } } else { if (direction.X == 0) { if (direction.Y == 0) { classification = RayType.OOP; } else if (direction.Z == 0) { classification = RayType.OPO; } else { classification = RayType.OPP; } } else { if ((direction.Y == 0) && (direction.Z == 0)) { classification = RayType.POO; } else if (direction.Y == 0) { classification = RayType.POP; } else if (direction.Z == 0) { classification = RayType.PPO; } else { classification = RayType.PPP; } } } } } dirty = false; }
/* AABB and Ray Intersection Algorithm * * "Fast Ray / Axis-Aligned Bounding Box Overlap Tests using Ray Slopes" * by Martin Eisemann, Thorsten Grosch, Stefan Muller and Marcus Magnor * Computer Graphics Lab, TU Braunschweig, Germany and * University of Koblenz-Landau, Germany * * Breaks the 3 dimensions into 3 planes (xy, yz, xz) to perform * trivial calculations to determine if an intersect has occured. * * Conversion and Tweaking for Orchard Sun by Giawa */ /// <summary> /// Precalculates the slopes and 2D projections for intersection tests. /// </summary> private void PreCalculate() { inverse = 1.0f / direction; ibyj = direction.x * inverse.y; jbyi = direction.y * inverse.x; jbyk = direction.y * inverse.z; kbyj = direction.z * inverse.y; ibyk = direction.x * inverse.z; kbyi = direction.z * inverse.x; c_xy = origin.y - jbyi * origin.x; c_xz = origin.z - kbyi * origin.x; c_yx = origin.x - ibyj * origin.y; c_yz = origin.z - kbyj * origin.y; c_zx = origin.x - ibyk * origin.z; c_zy = origin.y - jbyk * origin.z; if (direction.x < 0) { if (direction.y < 0) { if (direction.z < 0) { classification = RayType.MMM; } else if (direction.z > 0) { classification = RayType.MMP; } else { classification = RayType.MMO; } } else { if (direction.z < 0) { classification = RayType.MPM; if (direction.y == 0) { classification = RayType.MOM; } } else { if ((direction.y == 0) && (direction.z == 0)) { classification = RayType.MOO; } else if (direction.z == 0) { classification = RayType.MPO; } else if (direction.y == 0) { classification = RayType.MOP; } else { classification = RayType.MPP; } } } } else { if (direction.y < 0) { if (direction.z < 0) { classification = RayType.PMM; if (direction.x == 0) { classification = RayType.OMM; } } else { if ((direction.x == 0) && (direction.z == 0)) { classification = RayType.OMO; } else if (direction.z == 0) { classification = RayType.PMO; } else if (direction.x == 0) { classification = RayType.OMP; } else { classification = RayType.PMP; } } } else { if (direction.z < 0) { if ((direction.x == 0) && (direction.y == 0)) { classification = RayType.OOM; } else if (direction.x == 0) { classification = RayType.OPM; } else if (direction.y == 0) { classification = RayType.POM; } else { classification = RayType.PPM; } } else { if (direction.x == 0) { if (direction.y == 0) { classification = RayType.OOP; } else if (direction.z == 0) { classification = RayType.OPO; } else { classification = RayType.OPP; } } else { if ((direction.y == 0) && (direction.z == 0)) { classification = RayType.POO; } else if (direction.y == 0) { classification = RayType.POP; } else if (direction.z == 0) { classification = RayType.PPO; } else { classification = RayType.PPP; } } } } } dirty = false; }
public Ray(Vector3 start, Vector3 direction) { X = start.X; Y = start.Y; Z = start.Z; I = direction.X; J = direction.Y; K = direction.Z; II = 1.0f / I; IJ = 1.0f / J; IK = 1.0f / K; R0 = start.X * J - I * start.Y; R1 = start.X * K - I * start.Z; R3 = start.Y * K - J * start.Z; // If direction.X/Y/Z are 0.0, for some reason they are getting treated as -0.0. // Fix that here if (II == Single.NegativeInfinity) { II = Single.PositiveInfinity; } if (IJ == Single.NegativeInfinity) { IJ = Single.PositiveInfinity; } if (IK == Single.NegativeInfinity) { IK = Single.PositiveInfinity; } if (I < 0f) { if (J < 0f) { if (K < 0f) { Type = RayType.MMM; } else { Type = RayType.MMP; } } else { if (K < 0f) { Type = RayType.MPM; } else { Type = RayType.MPP; } } } else { if (J < 0f) { if (K < 0f) { Type = RayType.PMM; } else { Type = RayType.PMP; } } else { if (K < 0f) { Type = RayType.PPM; } else { Type = RayType.PPP; } } } }