public static LuaSidedef NearestSidedef(LuaVector2D pos) { Sidedef side = MapSet.NearestSidedef(General.Map.Map.Sidedefs, pos.vec); if (side == null) { return null; } return new LuaSidedef(side); }
// This performs an accurate test for object picking public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) { u_ray = pickrayu; // Check on which side of the nearest sidedef we are Sidedef sd = MapSet.NearestSidedef(Sector.Sector.Sidedefs, pickintersect); float side = sd.Line.SideOfLine(pickintersect); //mxd. Alpha based picking. Used only on extrafloors with transparent or masked textures if ((side <= 0.0f && sd.IsFront) || (side > 0.0f && !sd.IsFront)) { if (!BuilderPlug.Me.AlphaBasedTextureHighlighting || !Texture.IsImageLoaded || extrafloor == null || RenderPass == RenderPass.Solid || (!Texture.IsTranslucent && !Texture.IsMasked)) { return(true); } // Some textures (e.g. HiResImage) may lie about their size, so use bitmap size instead Bitmap image = Texture.GetBitmap(); lock (image) { // Fetch ZDoom fields float rotate = Angle2D.DegToRad(level.sector.Fields.GetValue("rotationfloor", 0.0f)); Vector2D offset = new Vector2D(level.sector.Fields.GetValue("xpanningfloor", 0.0f), level.sector.Fields.GetValue("ypanningfloor", 0.0f)); Vector2D scale = new Vector2D(level.sector.Fields.GetValue("xscalefloor", 1.0f), level.sector.Fields.GetValue("yscalefloor", 1.0f)); Vector2D texscale = new Vector2D(1.0f / Texture.ScaledWidth, 1.0f / Texture.ScaledHeight); // Texture coordinates Vector2D o = pickintersect; o = o.GetRotated(rotate); o.y = -o.y; o = (o + offset) * scale * texscale; o.x = (o.x * image.Width) % image.Width; o.y = (o.y * image.Height) % image.Height; // Make sure coordinates are inside of texture dimensions... if (o.x < 0) { o.x += image.Width; } if (o.y < 0) { o.y += image.Height; } // Make final texture coordinates... int ox = General.Clamp((int)Math.Floor(o.x), 0, image.Width - 1); int oy = General.Clamp((int)Math.Floor(o.y), 0, image.Height - 1); // Check pixel alpha return(image.GetPixel(ox, oy).A > 0); } } return(false); }
// This performs an accurate test for object picking public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) { u_ray = pickrayu; // Check on which side of the nearest sidedef we are Sidedef sd = MapSet.NearestSidedef(Sector.Sector.Sidedefs, pickintersect); float side = sd.Line.SideOfLine(pickintersect); return(((side <= 0.0f) && sd.IsFront) || ((side > 0.0f) && !sd.IsFront)); }
public static LuaSector NearestSector(LuaVector2D pos) { Sidedef nearest_sidedef = MapSet.NearestSidedef(General.Map.Map.Sidedefs, pos.vec); if (nearest_sidedef == null) { return null; } Sector sector = nearest_sidedef.Sector; if (sector == null) { return null; } return new LuaSector(sector); }
/// <summary> /// This is called when the thing must be tested for line intersection. This should perform /// accurate hit detection and set u_ray to the position on the ray where this hits the geometry. /// </summary> public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray) { u_ray = pickrayu; Sidedef sd = MapSet.NearestSidedef(sidedef.Sector.Sidedefs, pickintersect); if (sd == sidedef) { float side = sd.Line.SideOfLine(pickintersect); if ((side <= 0.0f && sd.IsFront) || (side > 0.0f && !sd.IsFront)) { return(true); } } return(false); }
//mxd. Set as First wall public virtual void OnSetFirstWall() { // Find nearest sidedef Sidedef sd = MapSet.NearestSidedef(Sector.Sector.Sidedefs, pickintersect); // Set it as FirstWall if (sd != null) { // Make undo mode.CreateUndo("Set First wall"); mode.SetActionResult("First wall assigned."); // Set it Sector.Sector.FirstWall = sd; // Sector update required Sector.Changed = true; } }
/// <summary> /// This is called when the thing must be tested for line intersection. This should perform /// accurate hit detection and set u_ray to the position on the ray where this hits the geometry. /// </summary> public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref double u_ray) { u_ray = pickrayu; Sidedef sd = MapSet.NearestSidedef(sector.Sidedefs, pickintersect); Vertex v = MapSet.NearestVertex(new Vertex[] { sd.Line.Start, sd.Line.End }, pickintersect); if (v == vertex) { double side = sd.Line.SideOfLine(pickintersect); if ((side <= 0.0f && sd.IsFront) || (side > 0.0f && !sd.IsFront)) { return(true); } } return(false); }