Advertisement
jewalky

Untitled

Feb 9th, 2017
207
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1.         //mxd. Alpha based picking
  2.         public override bool PickAccurate(Vector3D from, Vector3D to, Vector3D dir, ref float u_ray)
  3.         {
  4.             if(!BuilderPlug.Me.AlphaBasedTextureHighlighting || !Texture.IsImageLoaded || (!Texture.IsTranslucent && !Texture.IsMasked)) return base.PickAccurate(from, to, dir, ref u_ray);
  5.  
  6.             float u;
  7.             new Line2D(from, to).GetIntersection(Sidedef.Line.Line, out u);
  8.             if(Sidedef != Sidedef.Line.Front) u = 1.0f - u;
  9.  
  10.             // Some textures (e.g. HiResImage) may lie about their size, so use bitmap size instead
  11.             Bitmap image = Texture.GetBitmap();
  12.  
  13.             // Determine texture scale...
  14.             Vector2D imgscale = new Vector2D((float)Texture.Width / image.Width, (float)Texture.Height / image.Height);
  15.             Vector2D texscale = (Texture is HiResImage) ? imgscale * Texture.Scale : Texture.Scale;
  16.  
  17.             // Get correct offset to texture space...
  18.             int ox = (int)Math.Floor((u * Sidedef.Line.Length * UniFields.GetFloat(Sidedef.Fields, "scalex_mid", 1.0f) / texscale.x
  19.                 + ((Sidedef.OffsetX + UniFields.GetFloat(Sidedef.Fields, "offsetx_mid")) / imgscale.x))
  20.                 % image.Width);
  21.            
  22.             int oy;
  23.             if(repeatmidtex)
  24.             {
  25.                 bool pegbottom = Sidedef.Line.IsFlagSet(General.Map.Config.LowerUnpeggedFlag);
  26.                 float zoffset = (pegbottom ? Sidedef.Sector.FloorHeight : Sidedef.Sector.CeilHeight);
  27.                 oy = (int)Math.Floor(((pickintersect.z - zoffset) * UniFields.GetFloat(Sidedef.Fields, "scaley_mid", 1.0f) / texscale.y
  28.                     - ((Sidedef.OffsetY - UniFields.GetFloat(Sidedef.Fields, "offsety_mid")) / imgscale.y))
  29.                     % image.Height);
  30.             }
  31.             else
  32.             {
  33.                 float zoffset = bottomclipplane.GetZ(pickintersect);
  34.                 oy = (int)Math.Ceiling(((pickintersect.z - zoffset) * UniFields.GetFloat(Sidedef.Fields, "scaley_mid", 1.0f) / texscale.y) % image.Height);
  35.             }
  36.  
  37.             // Make sure offsets are inside of texture dimensions...
  38.             if(ox < 0) ox += image.Width;
  39.             if(oy < 0) oy += image.Height;
  40.  
  41.             // Check pixel alpha
  42.             Point pixelpos = new Point(General.Clamp(ox, 0, image.Width - 1), General.Clamp(image.Height - oy, 0, image.Height - 1));
  43.             return (image.GetPixel(pixelpos.X, pixelpos.Y).A > 0 && base.PickAccurate(from, to, dir, ref u_ray));
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement