コード例 #1
0
        public TriangleData(Vector3 p1, Vector3 p2, Vector3 p3, Rigidbody boatRB, float timeSinceStart)
        {
            this.p1 = p1;
            this.p2 = p2;
            this.p3 = p3;

            //Center of the triangle
            this.center = (p1 + p2 + p3) / 3f;

            //Distance to the surface from the center of the triangle
            this.distanceToSurface = Mathf.Abs(WaterController.current.DistanceToWater(this.center, timeSinceStart));

            //Normal to the triangle
            this.normal = Vector3.Cross(p2 - p1, p3 - p1).normalized;

            //Area of the triangle
            this.area = BoatPhysicsMath.GetTriangleArea(p1, p2, p3);

            //Velocity vector of the triangle at the center
            this.velocity = BoatPhysicsMath.GetTriangleVelocity(boatRB, this.center);

            //Velocity direction
            this.velocityDir = this.velocity.normalized;

            //Angle between the normal and the velocity
            //Negative if pointing in the opposite direction
            //Positive if pointing in the same direction
            this.cosTheta = Vector3.Dot(this.velocityDir, this.normal);
        }
コード例 #2
0
        //Calculate the current velocity at the center of each triangle of the original boat mesh
        private void CalculateSlammingVelocities(List <SlammingForceData> slammingForceData)
        {
            for (int i = 0; i < slammingForceData.Count; i++)
            {
                //Set the new velocity to the old velocity
                slammingForceData[i].previousVelocity = slammingForceData[i].velocity;

                //Center of the triangle in world space
                Vector3 center = transform.TransformPoint(slammingForceData[i].triangleCenter);

                //Get the current velocity at the center of the triangle
                slammingForceData[i].velocity = BoatPhysicsMath.GetTriangleVelocity(boatRB, center);
            }
        }