Just as I was thinking about an interesting demo to play withdrawing functions in
I did some research and below Ipresent
Drawing lines with LineRenderer
When it comes to lines, the first thing you'll bump into in theUnity3D API is the
It has an important limitation:
It was easy to implement, but not very fast since I end up spawninglots of GameObjects each with a LineRenderer attached. It seems tobe the
Drawing lines as a meshusing Graphics
The
Since meshes are composed of surfaces rather than lines or points,in 3D space a line is best rendered as a very thin quad. A quad isdescribed with 4 vertices, and usually you'll only have the startand end points and a width. Based on this data you can compute aline like this:
-
Vector3 normal = Vector3. Cross (start,end );
-
Vector3 side = Vector3. Cross (normal,end-start );
-
side. Normalize ( );
-
Vector3 a = start + side *
(lineWidth/ 2 ); -
Vector3 b = start + side *
(lineWidth/ - 2 ); -
Vector3 c = end + side *
(lineWidth/ 2 ); -
Vector3 d = end + side *
(lineWidth/ - 2 );
First, you get the normal of the plane on which both start and endvectors lie. This will be the plane on which the line-quad willlocated. The cross product of the normal and of the differencebetween end and start vectors gives you the side vector (the "thin"side of the quad). You need to normalize it to make it a unitvector. Finally calculate all 4 points of the rectangle by addingthe side vector multiplied by half width to both start and endpoints in both directions. In the MakeQuad
AddLine
It wasn't easy to implement, but once I was there it runs prettyfast.
Direct drawing withGL
No fast is fastenough!