Tanoda
Bipyramid.cs
Go to the documentation of this file.
1/******************************************************************************
2 * Copyright (C) Ultraleap, Inc. 2011-2020. *
3 * *
4 * Use subject to the terms of the Apache License 2.0 available at *
5 * http://www.apache.org/licenses/LICENSE-2.0, or another agreement *
6 * between Ultraleap and you, your company or other organization. *
7 ******************************************************************************/
8
9using UnityEngine;
10
11namespace Leap.Unity.Geometry {
12
13 public struct Bipyramid {
14
15 public Vector3 a;
16 public Vector3 b;
17 public int polySegments;
18 public float lengthFraction;
19 public float? absoluteRadius;
20 public float? radiusFraction;
21 public Transform transform;
22 private Matrix4x4? overrideMatrix;
23 public Matrix4x4 matrix { get {
24 if (overrideMatrix != null) { return overrideMatrix.Value; }
25 if (transform != null) { return transform.localToWorldMatrix; }
26 return Matrix4x4.identity;
27 }}
28 public float radius { get {
29 if (absoluteRadius != null) { return absoluteRadius.Value; }
30 if (radiusFraction != null) { return (b - a).magnitude * radiusFraction.Value; }
31 else { return (b - a).magnitude * 0.125f; }
32 }}
33
34 public Bipyramid(Vector3 a, Vector3 b, int polySegments = 6,
35 float lengthFraction = 0.5f, float? radiusFraction = null,
36 float? absoluteRadius = null, Transform transform = null,
37 Matrix4x4? overrideMatrix = null)
38 {
39 this.a = a;
40 this.b = b;
41 this.polySegments = polySegments;
42 this.lengthFraction = lengthFraction;
43 this.radiusFraction = radiusFraction;
44 this.absoluteRadius = absoluteRadius;
45 this.transform = transform;
46 this.overrideMatrix = overrideMatrix;
47 }
48
51 public static Bipyramid ModelBone(Vector3 a, Vector3 b, int polySegments = 4,
52 float lengthFraction = 0.38f, float? radiusFraction = 0.0125f,
53 float? absoluteRadius = null, Transform transform = null,
54 Matrix4x4? overrideMatrix = null)
55 {
59 overrideMatrix: overrideMatrix);
60 }
61
65 public static Bipyramid ThinArrow(Vector3 a, Vector3 b, int polySegments = 4,
66 float lengthFraction = 0.3f, float? radiusFraction = null,
67 float? absoluteRadius = 0.005f, Transform transform = null,
68 Matrix4x4? overrideMatrix = null)
69 {
73 overrideMatrix: overrideMatrix);
74 }
75
78 public static Bipyramid Arrowhead(Vector3 a, Vector3 b, int polySegments = 6,
79 float lengthFraction = 0.38f, float? radiusFraction = 0.16f,
80 float? absoluteRadius = null, Transform transform = null,
81 Matrix4x4? overrideMatrix = null)
82 {
86 overrideMatrix: overrideMatrix);
87 }
88
89 public void DrawLines(System.Action<Vector3, Vector3> drawLine) {
90 var matrix = this.matrix;
91 var radius = this.radius;
92 var localLength = (b - a).magnitude;
93 if (localLength == 0f) { localLength = 0.0001f; }
94 var localDirection = (b - a) / localLength;
95
96 var circle = new Geometry.Circle(
97 center: a + localDirection * localLength * lengthFraction,
98 direction: localDirection,
100 overrideMatrix: matrix
101 );
102 var startPos = matrix.MultiplyPoint3x4(a);
103 var endPos = matrix.MultiplyPoint3x4(b);
104
105 foreach (var point in circle.Points(polySegments)) {
106 drawLine(startPos, point);
107 drawLine(point, endPos);
108 }
109 foreach (var edge in circle.Segments(polySegments)) {
110 drawLine(edge.a, edge.b);
111 }
112 }
113
114 }
115
116}
static Bipyramid Arrowhead(Vector3 a, Vector3 b, int polySegments=6, float lengthFraction=0.38f, float? radiusFraction=0.16f, float? absoluteRadius=null, Transform transform=null, Matrix4x4? overrideMatrix=null)
Arrowhead defaults for a bipyramid. Can override any of the parameters like a normal bipyramid constr...
Definition: Bipyramid.cs:78
Bipyramid(Vector3 a, Vector3 b, int polySegments=6, float lengthFraction=0.5f, float? radiusFraction=null, float? absoluteRadius=null, Transform transform=null, Matrix4x4? overrideMatrix=null)
Definition: Bipyramid.cs:34
void DrawLines(System.Action< Vector3, Vector3 > drawLine)
Definition: Bipyramid.cs:89
static Bipyramid ModelBone(Vector3 a, Vector3 b, int polySegments=4, float lengthFraction=0.38f, float? radiusFraction=0.0125f, float? absoluteRadius=null, Transform transform=null, Matrix4x4? overrideMatrix=null)
Rig model bone defaults for a bipyramid. Can override any of the parameters like a normal bipyramid c...
Definition: Bipyramid.cs:51
static Bipyramid ThinArrow(Vector3 a, Vector3 b, int polySegments=4, float lengthFraction=0.3f, float? radiusFraction=null, float? absoluteRadius=0.005f, Transform transform=null, Matrix4x4? overrideMatrix=null)
Thin directed arrow, good for adding directionality to an edge between two points....
Definition: Bipyramid.cs:65