romanilyinfb

Untitled

Sep 4th, 2020
1,313
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class vec_t
  5. {
  6.   public vec_t(float in_x, float in_y, float in_z)
  7.   {
  8.       this.x = in_x;
  9.       this.y = in_y;
  10.       this.z = in_z;
  11.   }
  12.   public float x;
  13.   public float y;
  14.   public float z;
  15. }
  16.  
  17. public class vec2_t
  18. {
  19.   public float x;
  20.   public float y;
  21.  
  22.   public vec2_t(float in_x, float in_y)
  23.   {
  24.       this.x = in_x;
  25.       this.y = in_y;
  26.   }
  27.  
  28.   public float distance(vec2_t to)
  29.   {
  30.     return 0F;
  31.   }
  32. }
  33.  
  34. public class map
  35. {
  36.   private float width;
  37.   private float height;
  38.  
  39.   private void _visibility_scan(List<float> @in, List<float> @out, vec_t eye, int start_x, int stop_x, int y, int prev_y)
  40.   {
  41.     int xdir = (start_x < stop_x)? 1: -1;
  42.     for (int x = start_x; x != stop_x; x += xdir)
  43.     {
  44.       int x_diff = (int)Math.Abs(eye.x - x);
  45.       int y_diff = (int)Math.Abs(eye.z - y);
  46.       bool horiz = (x_diff >= y_diff);
  47.       int x_step = horiz? 1: x_diff / y_diff;
  48.       int in_x = x - x_step * xdir; // where in the in buffer would we get the inner value?
  49.       float outer_d = (new vec2_t(x, y)).distance(new vec2_t(eye.x, eye.z));
  50.       float inner_d = (new vec2_t(in_x, horiz? y: prev_y)).distance(new vec2_t(eye.x, eye.z));
  51.       // get the inner value, scaling by distance
  52.       float inner = (horiz? @out: @in).at(in_x) * (outer_d / inner_d);
  53.       float outer = height_at(x, y) - eye.y; // height we are at right now in the map, eye-relative
  54.       if (inner <= outer)
  55.       {
  56.         @out[x] = outer;
  57.         vis[y * width + x] = GlobalMembers.VISIBLE;
  58.       }
  59.       else
  60.       {
  61.         @out[x] = inner;
  62.         vis[y * width + x] = GlobalMembers.NOT_VISIBLE;
  63.       }
  64.     }
  65.   }
  66.  
  67.   public List<float> vis = new List<float>();
  68.  
  69.   public map(float w, float h)
  70.   {
  71.       this.width = w;
  72.       this.height = h;
  73.   }
  74.  
  75.   public float height_at(int x, int y)
  76.   {
  77.     return 0.0F;
  78.   }
  79.  
  80.   public void visibility_add(vec_t eye)
  81.   {
  82.     const float BASE = -10000F; // represents a downward vector that would always be visible
  83.     List<float> scan_0 = new List<float>();
  84.     List<float> scan_out = new List<float>();
  85.     List<float> scan_in = new List<float>();
  86.     scan_0.Resize(width);
  87.     vis[eye.z * width + eye.x - 1] = vis[eye.z * width + eye.x] = vis[eye.z * width + eye.x + 1] = GlobalMembers.VISIBLE;
  88.     scan_0[eye.x] = BASE;
  89.     scan_0[eye.x - 1] = BASE;
  90.     scan_0[eye.x + 1] = BASE;
  91.  
  92.     _visibility_scan(scan_0, scan_0, eye, (int)eye.x + 2, (int)width, (int)eye.z, (int)eye.z);
  93.     _visibility_scan(scan_0, scan_0, eye, (int)eye.x - 2, -1, (int)eye.z, (int)eye.z);
  94.  
  95.     scan_out = new List<float>(scan_0);
  96.  
  97.     for (int y = (int)eye.z + 1; y < height; y++)
  98.     {
  99.       scan_in = new List<float>(scan_out);
  100.       _visibility_scan(scan_in, scan_out, eye, (int)eye.x, -1, y, y - 1);
  101.       _visibility_scan(scan_in, scan_out, eye, (int)eye.x, (int)width, y, y - 1);
  102.     }
  103.     scan_out = new List<float>(scan_0);
  104.     for (int y = (int)eye.z - 1; y >= 0; y--)
  105.     {
  106.       scan_in = new List<float>(scan_out);
  107.       _visibility_scan(scan_in, scan_out, eye, (int)eye.x, -1, y, y + 1);
  108.       _visibility_scan(scan_in, scan_out, eye, (int)eye.x, (int)width, y, y + 1);
  109.     }
  110.   }
  111.  
  112. }
  113.  
  114. public static class GlobalMembers
  115. {
  116.     public static readonly int VISIBLE = 1;
  117.     public static readonly int NOT_VISIBLE = 0;
  118.  
  119.     internal static void Main()
  120.     {
  121.       vec_t p = new vec_t(1F, 2F, 3F);
  122.       map m = new map(1000F, 1000F);
  123.       m.visibility_add(p);
  124.     }
  125.  
  126. }
  127.  
  128. //Helper class added by C++ to C# Converter:
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //  Copyright © 2006 - 2020 Tangible Software Solutions, Inc.
  132. //  This class can be used by anyone provided that the copyright notice remains intact.
  133. //
  134. //  This class is used to convert some of the C++ std::vector methods to C#.
  135. //----------------------------------------------------------------------------------------
  136.  
  137. using System.Collections.Generic;
  138.  
  139. internal static class VectorHelper
  140. {
  141.     public static void Resize<T>(this List<T> list, int newSize, T value = default(T))
  142.     {
  143.         if (list.Count > newSize)
  144.             list.RemoveRange(newSize, list.Count - newSize);
  145.         else if (list.Count < newSize)
  146.         {
  147.             for (int i = list.Count; i < newSize; i++)
  148.             {
  149.                 list.Add(value);
  150.             }
  151.         }
  152.     }
  153.  
  154.     public static void Swap<T>(this List<T> list1, List<T> list2)
  155.     {
  156.         List<T> temp = new List<T>(list1);
  157.         list1.Clear();
  158.         list1.AddRange(list2);
  159.         list2.Clear();
  160.         list2.AddRange(temp);
  161.     }
  162.  
  163.     public static List<T> InitializedList<T>(int size, T value)
  164.     {
  165.         List<T> temp = new List<T>();
  166.         for (int count = 1; count <= size; count++)
  167.         {
  168.             temp.Add(value);
  169.         }
  170.  
  171.         return temp;
  172.     }
  173.  
  174.     public static List<List<T>> NestedList<T>(int outerSize, int innerSize)
  175.     {
  176.         List<List<T>> temp = new List<List<T>>();
  177.         for (int count = 1; count <= outerSize; count++)
  178.         {
  179.             temp.Add(new List<T>(innerSize));
  180.         }
  181.  
  182.         return temp;
  183.     }
  184.  
  185.     public static List<List<T>> NestedList<T>(int outerSize, int innerSize, T value)
  186.     {
  187.         List<List<T>> temp = new List<List<T>>();
  188.         for (int count = 1; count <= outerSize; count++)
  189.         {
  190.             temp.Add(InitializedList(innerSize, value));
  191.         }
  192.  
  193.         return temp;
  194.     }
  195. }
  196.  
RAW Paste Data