Files
ProjectBall.Unity/Assets/Scripts/CubeSlice.cs
T

76 lines
1.9 KiB
C#
Raw Normal View History

2025-05-13 05:18:03 +03:00
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class CubeSlice : MonoBehaviour {
public Mesh testMesh;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
void OnDrawGizmos(){
if (testMesh == null) {
return;
}
float totalVolume = AdvancedMath.MeshVolume (testMesh.vertices, testMesh.triangles, transform.localToWorldMatrix);
Debug.Log ("Underwater volume = " + totalVolume);
Debug.Log ("Expected volume = " + AdvancedMath.CylinderVolume(0.5f, 1.0f));
//List<Vector3> prismTriangles = new List<Vector3> ();
/*for (int i = 0; i < 1; ++i) {
Vector3 v0 = new Vector3(0,-1,0);
Vector3 v1 = new Vector3(1,-1,0);
Vector3 v2 = new Vector3(0.5f,-5,1);
Vector3 normal = AdvancedMath.TriangleNormal(v0, v1, v2);
float sign = Mathf.Sign(Vector3.Dot (normal, p.normal));
float h0 = p.GetDistanceToPoint(v0);
float h1 = p.GetDistanceToPoint(v1);
float h2 = p.GetDistanceToPoint(v2);
float avgH = (h0 + h1 + h2) / 3.0f;
Vector3 vp0 = v0 - p.normal * h0;
Vector3 vp1 = v1 - p.normal * h1;
Vector3 vp2 = v2 - p.normal * h2;
float triangleSquare = AdvancedMath.TriangleSquare(vp0, vp1, vp2);
float prismVolume = AdvancedMath.PrismVolume(triangleSquare, avgH) * sign;
totalVolume += prismVolume;
Vector3 com = AdvancedMath.PrismCenterOfMass(vp0, vp1, vp2, p.normal, h0, h1, h2);
AdvancedGizmo.DrawTriangle(v0, v1, v2, true);
AdvancedGizmo.DrawTriangle(vp0, vp1, vp2, true);
Debug.DrawLine(v0, vp0);
Debug.DrawLine(v1, vp1);
Debug.DrawLine(v2, vp2);
Gizmos.DrawSphere(new Vector3(com.x, com.y, com.z), 0.05f);
}*/
//Debug.Log ("Cut: " + cut);
//Debug.Log ("Not cut: " + notCut);
//AdvancedGizmo.DrawMesh (cuttedTriangles.ToArray (), true);
//AdvancedGizmo.DrawMesh (vertices, indices, false);
}
}