Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- public class vec_t
- {
- public vec_t(float in_x, float in_y, float in_z)
- {
- this.x = in_x;
- this.y = in_y;
- this.z = in_z;
- }
- public float x;
- public float y;
- public float z;
- }
- public class vec2_t
- {
- public float x;
- public float y;
- public vec2_t(float in_x, float in_y)
- {
- this.x = in_x;
- this.y = in_y;
- }
- public float distance(vec2_t to)
- {
- return 0F;
- }
- }
- public class map
- {
- private float width;
- private float height;
- private void _visibility_scan(List<float> @in, List<float> @out, vec_t eye, int start_x, int stop_x, int y, int prev_y)
- {
- int xdir = (start_x < stop_x)? 1: -1;
- for (int x = start_x; x != stop_x; x += xdir)
- {
- int x_diff = (int)Math.Abs(eye.x - x);
- int y_diff = (int)Math.Abs(eye.z - y);
- bool horiz = (x_diff >= y_diff);
- int x_step = horiz? 1: x_diff / y_diff;
- int in_x = x - x_step * xdir; // where in the in buffer would we get the inner value?
- float outer_d = (new vec2_t(x, y)).distance(new vec2_t(eye.x, eye.z));
- float inner_d = (new vec2_t(in_x, horiz? y: prev_y)).distance(new vec2_t(eye.x, eye.z));
- // get the inner value, scaling by distance
- float inner = (horiz? @out: @in).at(in_x) * (outer_d / inner_d);
- float outer = height_at(x, y) - eye.y; // height we are at right now in the map, eye-relative
- if (inner <= outer)
- {
- @out[x] = outer;
- vis[y * width + x] = GlobalMembers.VISIBLE;
- }
- else
- {
- @out[x] = inner;
- vis[y * width + x] = GlobalMembers.NOT_VISIBLE;
- }
- }
- }
- public List<float> vis = new List<float>();
- public map(float w, float h)
- {
- this.width = w;
- this.height = h;
- }
- public float height_at(int x, int y)
- {
- return 0.0F;
- }
- public void visibility_add(vec_t eye)
- {
- const float BASE = -10000F; // represents a downward vector that would always be visible
- List<float> scan_0 = new List<float>();
- List<float> scan_out = new List<float>();
- List<float> scan_in = new List<float>();
- scan_0.Resize(width);
- vis[eye.z * width + eye.x - 1] = vis[eye.z * width + eye.x] = vis[eye.z * width + eye.x + 1] = GlobalMembers.VISIBLE;
- scan_0[eye.x] = BASE;
- scan_0[eye.x - 1] = BASE;
- scan_0[eye.x + 1] = BASE;
- _visibility_scan(scan_0, scan_0, eye, (int)eye.x + 2, (int)width, (int)eye.z, (int)eye.z);
- _visibility_scan(scan_0, scan_0, eye, (int)eye.x - 2, -1, (int)eye.z, (int)eye.z);
- scan_out = new List<float>(scan_0);
- for (int y = (int)eye.z + 1; y < height; y++)
- {
- scan_in = new List<float>(scan_out);
- _visibility_scan(scan_in, scan_out, eye, (int)eye.x, -1, y, y - 1);
- _visibility_scan(scan_in, scan_out, eye, (int)eye.x, (int)width, y, y - 1);
- }
- scan_out = new List<float>(scan_0);
- for (int y = (int)eye.z - 1; y >= 0; y--)
- {
- scan_in = new List<float>(scan_out);
- _visibility_scan(scan_in, scan_out, eye, (int)eye.x, -1, y, y + 1);
- _visibility_scan(scan_in, scan_out, eye, (int)eye.x, (int)width, y, y + 1);
- }
- }
- }
- public static class GlobalMembers
- {
- public static readonly int VISIBLE = 1;
- public static readonly int NOT_VISIBLE = 0;
- internal static void Main()
- {
- vec_t p = new vec_t(1F, 2F, 3F);
- map m = new map(1000F, 1000F);
- m.visibility_add(p);
- }
- }
- //Helper class added by C++ to C# Converter:
- //----------------------------------------------------------------------------------------
- // Copyright © 2006 - 2020 Tangible Software Solutions, Inc.
- // This class can be used by anyone provided that the copyright notice remains intact.
- //
- // This class is used to convert some of the C++ std::vector methods to C#.
- //----------------------------------------------------------------------------------------
- using System.Collections.Generic;
- internal static class VectorHelper
- {
- public static void Resize<T>(this List<T> list, int newSize, T value = default(T))
- {
- if (list.Count > newSize)
- list.RemoveRange(newSize, list.Count - newSize);
- else if (list.Count < newSize)
- {
- for (int i = list.Count; i < newSize; i++)
- {
- list.Add(value);
- }
- }
- }
- public static void Swap<T>(this List<T> list1, List<T> list2)
- {
- List<T> temp = new List<T>(list1);
- list1.Clear();
- list1.AddRange(list2);
- list2.Clear();
- list2.AddRange(temp);
- }
- public static List<T> InitializedList<T>(int size, T value)
- {
- List<T> temp = new List<T>();
- for (int count = 1; count <= size; count++)
- {
- temp.Add(value);
- }
- return temp;
- }
- public static List<List<T>> NestedList<T>(int outerSize, int innerSize)
- {
- List<List<T>> temp = new List<List<T>>();
- for (int count = 1; count <= outerSize; count++)
- {
- temp.Add(new List<T>(innerSize));
- }
- return temp;
- }
- public static List<List<T>> NestedList<T>(int outerSize, int innerSize, T value)
- {
- List<List<T>> temp = new List<List<T>>();
- for (int count = 1; count <= outerSize; count++)
- {
- temp.Add(InitializedList(innerSize, value));
- }
- return temp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment