mirror of
https://github.com/misternebula/quantum-space-buddies.git
synced 2025-02-28 22:13:23 +00:00
update gizmos stuff
This commit is contained in:
parent
5826404701
commit
25f9f388fa
@ -90,7 +90,7 @@ namespace QSB.Animation.Player.Thrusters
|
||||
return;
|
||||
}
|
||||
|
||||
Popcron.Gizmos.Sphere(_light.transform.position, 0.05f, Color.yellow, false, 4);
|
||||
Popcron.Gizmos.Sphere(_light.transform.position, 0.05f, Color.yellow, 4);
|
||||
Popcron.Gizmos.Line(_light.transform.position, _light.transform.parent.position, Color.yellow);
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
using QSB.Events;
|
||||
using QSB.Player;
|
||||
using QSB.QuantumSync.WorldObjects;
|
||||
using QSB.Syncs;
|
||||
using QSB.Utility;
|
||||
using QSB.WorldSync;
|
||||
using System;
|
||||
@ -76,6 +77,18 @@ namespace QSB.QuantumSync
|
||||
{
|
||||
Popcron.Gizmos.Sphere(Shrine.transform.position, 10f, Color.magenta);
|
||||
}
|
||||
|
||||
foreach (var quantumObject in QSBWorldSync.GetWorldObjects<IQSBQuantumObject>())
|
||||
{
|
||||
if (quantumObject.ControllingPlayer == 0)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Popcron.Gizmos.Line((quantumObject as IWorldObject).ReturnObject().transform.position,
|
||||
QSBPlayerManager.GetPlayer(quantumObject.ControllingPlayer).Body.transform.position,
|
||||
Color.magenta);
|
||||
}
|
||||
}
|
||||
|
||||
public static Tuple<bool, List<PlayerInfo>> IsVisibleUsingCameraFrustum(ShapeVisibilityTracker tracker, bool ignoreLocalCamera)
|
||||
|
@ -6,6 +6,5 @@ namespace Popcron
|
||||
{
|
||||
public Vector3[] points = { };
|
||||
public Color color = Color.white;
|
||||
public bool dashed = false;
|
||||
}
|
||||
}
|
@ -111,7 +111,7 @@ namespace Popcron
|
||||
}
|
||||
}
|
||||
|
||||
public static void Draw<T>(Color? color, bool dashed, params object[] args) where T : Drawer
|
||||
public static void Draw<T>(Color? color, params object[] args) where T : Drawer
|
||||
{
|
||||
var drawer = Drawer.Get<T>();
|
||||
if (drawer != null)
|
||||
@ -121,78 +121,78 @@ namespace Popcron
|
||||
//copy from buffer and add to the queue
|
||||
var array = new Vector3[points];
|
||||
Array.Copy(buffer, array, points);
|
||||
GizmosInstance.Submit(array, color, dashed);
|
||||
GizmosInstance.Submit(array, color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Lines(Vector3[] lines, Color? color = null, bool dashed = false)
|
||||
=> GizmosInstance.Submit(lines, color, dashed);
|
||||
public static void Lines(Vector3[] lines, Color? color = null)
|
||||
=> GizmosInstance.Submit(lines, color);
|
||||
|
||||
public static void Line(Vector3 a, Vector3 b, Color? color = null, bool dashed = false)
|
||||
=> Draw<LineDrawer>(color, dashed, a, b);
|
||||
public static void Line(Vector3 a, Vector3 b, Color? color = null)
|
||||
=> Draw<LineDrawer>(color, a, b);
|
||||
|
||||
public static void Square(Vector2 position, Vector2 size, Color? color = null, bool dashed = false)
|
||||
=> Square(position, Quaternion.identity, size, color, dashed);
|
||||
public static void Square(Vector2 position, Vector2 size, Color? color = null)
|
||||
=> Square(position, Quaternion.identity, size, color);
|
||||
|
||||
public static void Square(Vector2 position, float diameter, Color? color = null, bool dashed = false)
|
||||
=> Square(position, Quaternion.identity, Vector2.one * diameter, color, dashed);
|
||||
public static void Square(Vector2 position, float diameter, Color? color = null)
|
||||
=> Square(position, Quaternion.identity, Vector2.one * diameter, color);
|
||||
|
||||
public static void Square(Vector2 position, Quaternion rotation, Vector2 size, Color? color = null, bool dashed = false)
|
||||
=> Draw<SquareDrawer>(color, dashed, position, rotation, size);
|
||||
public static void Square(Vector2 position, Quaternion rotation, Vector2 size, Color? color = null)
|
||||
=> Draw<SquareDrawer>(color, position, rotation, size);
|
||||
|
||||
public static void Cube(Vector3 position, Quaternion rotation, Vector3 size, Color? color = null, bool dashed = false)
|
||||
=> Draw<CubeDrawer>(color, dashed, position, rotation, size);
|
||||
public static void Cube(Vector3 position, Quaternion rotation, Vector3 size, Color? color = null)
|
||||
=> Draw<CubeDrawer>(color, position, rotation, size);
|
||||
|
||||
public static void Rect(Rect rect, Camera camera, Color? color = null, bool dashed = false)
|
||||
public static void Rect(Rect rect, Camera camera, Color? color = null)
|
||||
{
|
||||
rect.y = Screen.height - rect.y;
|
||||
Vector2 corner = camera.ScreenToWorldPoint(new Vector2(rect.x, rect.y - rect.height));
|
||||
Draw<SquareDrawer>(color, dashed, corner + (rect.size * 0.5f), Quaternion.identity, rect.size);
|
||||
Draw<SquareDrawer>(color, corner + (rect.size * 0.5f), Quaternion.identity, rect.size);
|
||||
}
|
||||
|
||||
public static void Bounds(Bounds bounds, Color? color = null, bool dashed = false)
|
||||
=> Draw<CubeDrawer>(color, dashed, bounds.center, Quaternion.identity, bounds.size);
|
||||
public static void Bounds(Bounds bounds, Color? color = null)
|
||||
=> Draw<CubeDrawer>(color, bounds.center, Quaternion.identity, bounds.size);
|
||||
|
||||
public static void Cone(Vector3 position, Quaternion rotation, float length, float angle, Color? color = null, bool dashed = false, int pointsCount = 16)
|
||||
public static void Cone(Vector3 position, Quaternion rotation, float length, float angle, Color? color = null, int pointsCount = 16)
|
||||
{
|
||||
//draw the end of the cone
|
||||
var endAngle = Mathf.Tan(angle * 0.5f * Mathf.Deg2Rad) * length;
|
||||
var forward = rotation * Vector3.forward;
|
||||
var endPosition = position + (forward * length);
|
||||
var offset = 0f;
|
||||
Draw<PolygonDrawer>(color, dashed, endPosition, pointsCount, endAngle, offset, rotation);
|
||||
Draw<PolygonDrawer>(color, endPosition, pointsCount, endAngle, offset, rotation);
|
||||
|
||||
//draw the 4 lines
|
||||
for (var i = 0; i < 4; i++)
|
||||
{
|
||||
var a = i * 90f * Mathf.Deg2Rad;
|
||||
var point = rotation * new Vector3(Mathf.Cos(a), Mathf.Sin(a)) * endAngle;
|
||||
Line(position, position + point + (forward * length), color, dashed);
|
||||
Line(position, position + point + (forward * length), color);
|
||||
}
|
||||
}
|
||||
|
||||
public static void Sphere(Vector3 position, float radius, Color? color = null, bool dashed = false, int pointsCount = 16)
|
||||
public static void Sphere(Vector3 position, float radius, Color? color = null, int pointsCount = 16)
|
||||
{
|
||||
var offset = 0f;
|
||||
Draw<PolygonDrawer>(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(0f, 0f, 0f));
|
||||
Draw<PolygonDrawer>(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(90f, 0f, 0f));
|
||||
Draw<PolygonDrawer>(color, dashed, position, pointsCount, radius, offset, Quaternion.Euler(0f, 90f, 90f));
|
||||
Draw<PolygonDrawer>(color, position, pointsCount, radius, offset, Quaternion.Euler(0f, 0f, 0f));
|
||||
Draw<PolygonDrawer>(color, position, pointsCount, radius, offset, Quaternion.Euler(90f, 0f, 0f));
|
||||
Draw<PolygonDrawer>(color, position, pointsCount, radius, offset, Quaternion.Euler(0f, 90f, 90f));
|
||||
}
|
||||
|
||||
public static void Circle(Vector3 position, float radius, Camera camera, Color? color = null, bool dashed = false, int pointsCount = 16)
|
||||
public static void Circle(Vector3 position, float radius, Camera camera, Color? color = null, int pointsCount = 16)
|
||||
{
|
||||
var offset = 0f;
|
||||
var rotation = Quaternion.LookRotation(position - camera.transform.position);
|
||||
Draw<PolygonDrawer>(color, dashed, position, pointsCount, radius, offset, rotation);
|
||||
Draw<PolygonDrawer>(color, position, pointsCount, radius, offset, rotation);
|
||||
}
|
||||
|
||||
public static void Circle(Vector3 position, float radius, Quaternion rotation, Color? color = null, bool dashed = false, int pointsCount = 16)
|
||||
public static void Circle(Vector3 position, float radius, Quaternion rotation, Color? color = null, int pointsCount = 16)
|
||||
{
|
||||
var offset = 0f;
|
||||
Draw<PolygonDrawer>(color, dashed, position, pointsCount, radius, offset, rotation);
|
||||
Draw<PolygonDrawer>(color, position, pointsCount, radius, offset, rotation);
|
||||
}
|
||||
|
||||
public static void Frustum(OWCamera camera, Color? color = null, bool dashed = false)
|
||||
=> Draw<FrustumDrawer>(color, dashed, camera);
|
||||
public static void Frustum(OWCamera camera, Color? color = null)
|
||||
=> Draw<FrustumDrawer>(color, camera);
|
||||
}
|
||||
}
|
||||
|
@ -1,3 +1,4 @@
|
||||
using QSB.Utility;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
@ -83,8 +84,10 @@ namespace Popcron
|
||||
//none were found, create a new one
|
||||
if (!instance)
|
||||
{
|
||||
instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent<GizmosInstance>();
|
||||
instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
|
||||
//instance = new GameObject(typeof(GizmosInstance).FullName).AddComponent<GizmosInstance>();
|
||||
//instance.gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
|
||||
instance = Locator.GetPlayerCamera().gameObject.AddComponent<GizmosInstance>();
|
||||
DebugLog.DebugWrite("CREATE GIZMOS INSTANCE!");
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +99,7 @@ namespace Popcron
|
||||
/// <summary>
|
||||
/// Submits an array of points to draw into the queue.
|
||||
/// </summary>
|
||||
internal static void Submit(Vector3[] points, Color? color, bool dashed)
|
||||
internal static void Submit(Vector3[] points, Color? color)
|
||||
{
|
||||
var inst = GetOrCreate();
|
||||
|
||||
@ -122,7 +125,6 @@ namespace Popcron
|
||||
|
||||
inst.queue[inst.queueIndex].color = color ?? Color.white;
|
||||
inst.queue[inst.queueIndex].points = points;
|
||||
inst.queue[inst.queueIndex].dashed = dashed;
|
||||
|
||||
inst.queueIndex++;
|
||||
}
|
||||
@ -135,17 +137,13 @@ namespace Popcron
|
||||
{
|
||||
queue[i] = new Element();
|
||||
}
|
||||
|
||||
Camera.onPostRender += OnRendered;
|
||||
}
|
||||
|
||||
private void OnDisable() => Camera.onPostRender -= OnRendered;
|
||||
|
||||
private void Update() =>
|
||||
//always render something
|
||||
Gizmos.Line(default, default);
|
||||
|
||||
private void OnRendered(Camera camera)
|
||||
private void OnPostRender()
|
||||
{
|
||||
Material.SetPass(0);
|
||||
|
||||
@ -155,8 +153,6 @@ namespace Popcron
|
||||
GL.MultMatrix(Matrix4x4.identity);
|
||||
GL.Begin(GL.LINES);
|
||||
|
||||
var alt = CurrentTime % 1 > 0.5f;
|
||||
var dashGap = Mathf.Clamp(Gizmos.DashGap, 0.01f, 32f);
|
||||
var points = new List<Vector3>();
|
||||
|
||||
//draw le elements
|
||||
@ -171,44 +167,7 @@ namespace Popcron
|
||||
var element = queue[e];
|
||||
|
||||
points.Clear();
|
||||
if (element.dashed)
|
||||
{
|
||||
//subdivide
|
||||
for (var i = 0; i < element.points.Length - 1; i++)
|
||||
{
|
||||
var pointA = element.points[i];
|
||||
var pointB = element.points[i + 1];
|
||||
var direction = pointB - pointA;
|
||||
if (direction.sqrMagnitude > dashGap * dashGap * 2f)
|
||||
{
|
||||
var magnitude = direction.magnitude;
|
||||
var amount = Mathf.RoundToInt(magnitude / dashGap);
|
||||
direction /= magnitude;
|
||||
|
||||
for (var p = 0; p < amount - 1; p++)
|
||||
{
|
||||
if (p % 2 == (alt ? 1 : 0))
|
||||
{
|
||||
var startLerp = p / (amount - 1f);
|
||||
var endLerp = (p + 1) / (amount - 1f);
|
||||
var start = Vector3.Lerp(pointA, pointB, startLerp);
|
||||
var end = Vector3.Lerp(pointA, pointB, endLerp);
|
||||
points.Add(start);
|
||||
points.Add(end);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
points.Add(pointA);
|
||||
points.Add(pointB);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
points.AddRange(element.points);
|
||||
}
|
||||
points.AddRange(element.points);
|
||||
|
||||
GL.Color(element.color);
|
||||
for (var i = 0; i < points.Count; i++)
|
||||
|
Loading…
x
Reference in New Issue
Block a user