Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gebied instellen op amsterdam #306

Open
wants to merge 4 commits into
base: feature/amsterdam-time-machine
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using DG.Tweening;
using Netherlands3D.Coordinates;
using Netherlands3D.Events;
using Netherlands3D.Twin.PackageStagingArea.eu.netherlands3d.cameras.Runtime.Scripts.Cameras;
using UnityEngine;
Expand Down Expand Up @@ -99,19 +98,13 @@ public class FreeCamera : MonoBehaviour
private Vector3 previousPosition;
public OrthographicSwitcher orthographicSwitcher;

private Bounds areaBoundingBox;
private GameObject test;

void Awake()
{
cameraComponent = GetComponent<Camera>();
orthographicSwitcher = orthographicSwitcher ? orthographicSwitcher : GetComponent<OrthographicSwitcher>();

worldPlane = new Plane(Vector3.up, Vector3.zero);

areaBoundingBox = new Bounds();
test = GameObject.CreatePrimitive(PrimitiveType.Cube);

horizontalInput.AddListenerStarted(MoveHorizontally);
verticalInput.AddListenerStarted(MoveForwardBackwards);
upDownInput.AddListenerStarted(MoveUpDown);
Expand Down Expand Up @@ -320,16 +313,6 @@ void Update()
{
Clamp();
}

//lon lat amstel 1
Coordinate coord = new Coordinate(CoordinateSystem.WGS84, 52.36748063234993, 4.901222522254939, 0);
areaBoundingBox.center = coord.ToUnity();
areaBoundingBox.size = Vector3.one * 10000;
test.transform.position = areaBoundingBox.center;
test.transform.transform.localScale = Vector3.one * 10000;

if(!areaBoundingBox.Contains(transform.position))
transform.position = areaBoundingBox.ClosestPoint(transform.position);
}

/// <summary>
Expand Down
72 changes: 68 additions & 4 deletions Assets/Scenes/Main.unity

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

86 changes: 86 additions & 0 deletions Assets/Scripts/UI/MinimapBoundingBoxController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using Netherlands3D.Coordinates;
using Netherlands3D.Minimap;
using UnityEngine;

namespace Netherlands3D.Twin
{
public class MinimapBoundingBoxController : MonoBehaviour
{
private UIBoundingBox bbox;
private WMTSMap wmtsMap;
private RectTransform minimapTransform;
private RectTransform rTransform;
private FreeCamera freeCam;
private GameObject test;
public Bounds BoundingBox;

public float lineWidth;
public Color lineColor;
public float boxSize = 20000;

//lon lat amstel 1
private Coordinate coord = new Coordinate(CoordinateSystem.WGS84, 52.36748063234993, 4.901222522254939, 0);

private void Start()
{
freeCam = FindObjectOfType<FreeCamera>();
MinimapUI map = FindObjectOfType<MinimapUI>();
wmtsMap = map.GetComponentInChildren<WMTSMap>();
minimapTransform = map.GetComponent<RectTransform>();
rTransform = GetComponent<RectTransform>();
transform.SetParent(wmtsMap.transform, false);

GameObject bboxObject = new GameObject("boundingbox");
bboxObject.transform.SetParent(map.transform, false);
bbox = bboxObject.AddComponent<UIBoundingBox>();
BoundingBox = new Bounds();
//test = GameObject.CreatePrimitive(PrimitiveType.Cube);
}

private Vector3 GetLocalMapPositionForWorldPosition(Vector3 unityPosition)
{
Vector3RD rdPos = CoordinateConverter.UnitytoRD(unityPosition);
Vector3 mapPos = wmtsMap.DeterminePositionOnMap(rdPos);
rTransform.localPosition = mapPos;
Vector3 worldPosition = rTransform.position;
Vector3 localPositionInGrandparent = minimapTransform.InverseTransformPoint(worldPosition);
return localPositionInGrandparent - (Vector3)minimapTransform.sizeDelta * 0.5f;
}

private void Update()
{
Vector3 target = coord.ToUnity();
target.y = 0;

wmtsMap.PositionObjectOnMap(rTransform, CoordinateConverter.UnitytoRD(target));
BoundingBox.center = target;
BoundingBox.size = new Vector3(boxSize, Mathf.Max(boxSize, 100000000), boxSize);
//test.transform.position = BoundingBox.center;
//test.transform.transform.localScale = Vector3.one * boxSize;

UpdateMap();


if (!BoundingBox.Contains(freeCam.transform.position))
freeCam.transform.position = BoundingBox.ClosestPoint(freeCam.transform.position);
}

private void UpdateMap()
{
RectTransform rt = wmtsMap.GetComponent<RectTransform>();
float width = BoundingBox.size.x;
float depth = BoundingBox.size.z;
bbox.points = new Vector2[]
{
GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, 0.5f * depth)),
GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(0.5f * width, 0, 0.5f * depth)),
GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(0.5f * width, 0, -0.5f * depth)),
GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, -0.5f * depth)),
GetLocalMapPositionForWorldPosition(BoundingBox.center + new Vector3(-0.5f * width, 0, 0.5f * depth))
};
bbox.lineWidth = lineWidth;
bbox.color = lineColor;
bbox.SetVerticesDirty();
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UI/MinimapBoundingBoxController.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

54 changes: 54 additions & 0 deletions Assets/Scripts/UI/UIBoundingBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using UnityEngine;
using UnityEngine.UI;


namespace Netherlands3D.Twin
{
[RequireComponent(typeof(CanvasRenderer))]
public class UIBoundingBox : MaskableGraphic
{
public Vector2[] points; // Array of points to draw lines between
public float lineWidth = 2.0f; // Width of the line

protected override void OnPopulateMesh(VertexHelper vh)
{
vh.Clear();
if (points == null || points.Length < 2) return;

// Loop through each pair of points to create line segments
for (int i = 0; i < points.Length - 1; i++)
{
Vector2 start = points[i];
Vector2 end = points[i + 1];
AddLineSegment(vh, start, end);
}
}

void AddLineSegment(VertexHelper vh, Vector2 start, Vector2 end)
{
// Calculate the direction and perpendicular vector for line width
Vector2 direction = end - start;
direction.Normalize();
Vector2 perpendicular = new Vector2(-direction.y, direction.x) * (lineWidth / 2);

// Define the four corners of the quad
Vector2 p1 = start + perpendicular; // Top left
Vector2 p2 = start - perpendicular; // Bottom left
Vector2 p3 = end - perpendicular; // Bottom right
Vector2 p4 = end + perpendicular; // Top right

// Add the vertices for the quad
vh.AddVert(p1, color, new Vector2(0, 0));
vh.AddVert(p2, color, new Vector2(0, 1));
vh.AddVert(p3, color, new Vector2(1, 1));
vh.AddVert(p4, color, new Vector2(1, 0));

// Calculate the starting vertex index for this quad
int startIndex = vh.currentVertCount - 4;

// Add the two triangles that make up the quad
vh.AddTriangle(startIndex, startIndex + 1, startIndex + 2); // First triangle
vh.AddTriangle(startIndex, startIndex + 2, startIndex + 3); // Second triangle
}
}
}
11 changes: 11 additions & 0 deletions Assets/Scripts/UI/UIBoundingBox.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading