summaryrefslogtreecommitdiff
path: root/Docs/TAB_DebugRigidBody.txt
diff options
context:
space:
mode:
authorchai <215380520@qq.com>2023-10-19 15:36:59 +0800
committerchai <215380520@qq.com>2023-10-19 15:36:59 +0800
commitf4a633ea5125025216cc1d260d5dbac66f6ed194 (patch)
tree2c1d70c22b712dd895afcdc41bda158b1e2ee2ae /Docs/TAB_DebugRigidBody.txt
parentbc77bc7bc8b1a9b04ff598ff45eec0a1df5c6d8c (diff)
*doc
Diffstat (limited to 'Docs/TAB_DebugRigidBody.txt')
-rw-r--r--Docs/TAB_DebugRigidBody.txt135
1 files changed, 135 insertions, 0 deletions
diff --git a/Docs/TAB_DebugRigidBody.txt b/Docs/TAB_DebugRigidBody.txt
new file mode 100644
index 0000000..095c105
--- /dev/null
+++ b/Docs/TAB_DebugRigidBody.txt
@@ -0,0 +1,135 @@
+
+using UnityEngine;
+
+public class DebugRigidBody : MonoBehaviour
+{
+
+ public enum EMode
+ {
+ Axis,
+ Cube,
+ }
+ public EMode mode = EMode.Axis;
+
+ // When added to an object, draws colored rays from the
+ // transform position.
+ public int lineCount = 100;
+ public float radius = 3.0f;
+
+ static Material lineMaterial;
+ static void CreateLineMaterial()
+ {
+ if (!lineMaterial)
+ {
+ // Unity has a built-in shader that is useful for drawing
+ // simple colored things.
+ Shader shader = Shader.Find("Hidden/Internal-Colored");
+ lineMaterial = new Material(shader);
+ lineMaterial.hideFlags = HideFlags.HideAndDontSave;
+ // Turn on alpha blending
+ lineMaterial.SetInt("_SrcBlend", (int)UnityEngine.Rendering.BlendMode.SrcAlpha);
+ lineMaterial.SetInt("_DstBlend", (int)UnityEngine.Rendering.BlendMode.OneMinusSrcAlpha);
+ // Turn backface culling off
+ lineMaterial.SetInt("_Cull", (int)UnityEngine.Rendering.CullMode.Off);
+ // Turn off depth writes
+ lineMaterial.SetInt("_ZWrite", 0);
+ }
+ }
+
+ private void PutVertex(Vector3 vert)
+ {
+ GL.Vertex3(vert.x, vert.y, vert.z);
+ }
+
+ // Will be called after all regular rendering is done
+ public void OnRenderObject()
+ {
+ CreateLineMaterial();
+ // Apply the line material
+ lineMaterial.SetPass(0);
+
+ if (mode == EMode.Axis)
+ {
+ GL.PushMatrix();
+ // Set transformation matrix for drawing to
+ // match our transform
+ GL.MultMatrix(transform.localToWorldMatrix);
+
+ // Draw lines
+ GL.Begin(GL.LINES);
+
+ float len = 0.3f;
+
+ GL.Color(Color.red);
+ PutVertex(Vector3.zero);
+ PutVertex(Vector3.right * len);
+
+ GL.Color(Color.green);
+ PutVertex(Vector3.zero);
+ PutVertex(Vector3.up * len);
+
+ GL.Color(Color.blue);
+ PutVertex(Vector3.zero);
+ PutVertex(Vector3.forward * len);
+
+ GL.End();
+ GL.PopMatrix();
+ }
+ else if (mode == EMode.Cube)
+ {
+ GL.PushMatrix();
+ // Set transformation matrix for drawing to
+ // match our transform
+ GL.MultMatrix(transform.localToWorldMatrix);
+
+ float len = 0.05f;
+
+ GL.wireframe = true;
+
+ GL.Begin(GL.QUADS);
+
+ GL.Color(Color.white);
+
+ GL.Vertex3(len, len, -len);
+ GL.Vertex3(-len, len, -len);
+ GL.Vertex3(-len, len, len);
+ GL.Vertex3(len, len, len);
+
+ // Bottom face (y = -len)
+ GL.Vertex3(len, -len, len);
+ GL.Vertex3(-len, -len, len);
+ GL.Vertex3(-len, -len, -len);
+ GL.Vertex3(len, -len, -len);
+
+ // Front face (z = len)
+ GL.Vertex3(len, len, len);
+ GL.Vertex3(-len, len, len);
+ GL.Vertex3(-len, -len, len);
+ GL.Vertex3(len, -len, len);
+
+ // Back face (z = -len)
+ GL.Vertex3(len, -len, -len);
+ GL.Vertex3(-len, -len, -len);
+ GL.Vertex3(-len, len, -len);
+ GL.Vertex3(len, len, -len);
+
+ // Left face (x = -len)
+ GL.Vertex3(-len, len, len);
+ GL.Vertex3(-len, len, -len);
+ GL.Vertex3(-len, -len, -len);
+ GL.Vertex3(-len, -len, len);
+
+ // Right face (x = len)
+ GL.Vertex3(len, len, -len);
+ GL.Vertex3(len, len, len);
+ GL.Vertex3(len, -len, len);
+ GL.Vertex3(len, -len, -len);
+ GL.End(); // End of drawing color-cube
+
+ GL.wireframe = false;
+
+ GL.PopMatrix();
+ }
+ }
+
+}