Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- //C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found:
- //ORIGINAL LINE: inline void map::_visibility_scan(const STLVector<float>& in,STLVector<float>& out,const vec_t& eye,int start_x,int stop_x,int y,int prev_y)
- //C++ TO C# CONVERTER WARNING: The original C++ declaration of the following method implementation was not found:
- //ORIGINAL LINE: void map::visibility_add(const vec_t& eye)
- public partial class map
- {
- public 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 = Math.Abs(eye.x - x);
- int y_diff = 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 = vec2_t(x,y).distance(vec2_t(eye.x,eye.z));
- float inner_d = vec2_t(in_x,horiz? y: prev_y).distance(vec2_t(eye.x,eye.z));
- float inner = (horiz? @out: @in).at(in_x) * (outer_d / inner_d); // get the inner value, scaling by
- distance const 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.at(y * width + x) = VISIBLE;
- }
- else
- {
- @out[x] = inner;
- vis.at(y * width + x) = NOT_VISIBLE;
- }
- }
- }
- 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] = 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,eye.x + 2,width,eye.z,eye.z);
- _visibility_scan(scan_0,scan_0,eye,eye.x - 2,-1,eye.z,eye.z);
- scan_out = new List<float>(scan_0);
- for (int y = eye.z + 1; y < height; y++)
- {
- scan_in = new List<float>(scan_out);
- _visibility_scan(scan_in,scan_out,eye,eye.x,-1,y,y - 1);
- _visibility_scan(scan_in,scan_out,eye,eye.x,width,y,y - 1);
- }
- scan_out = new List<float>(scan_0);
- for (int y = eye.z - 1; y >= 0; y--)
- {
- scan_in = new List<float>(scan_out);
- _visibility_scan(scan_in,scan_out,eye,eye.x,-1,y,y + 1);
- _visibility_scan(scan_in,scan_out,eye,eye.x,width,y,y + 1);
- }
- }
- }
- //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
Advertisement