Пример #1
0
            // Find a trajectory for which the trajectory's y is at least as high as any
            // of the vertices remaining in _edgesOnPrincipalPlane.
            private float GetTimeToTargetOnIntersection(
                PrincipalSpace3D principalSpace3D,
                PrincipalTrajectory principalTrajectory,
                Vector2 principalTargetPosition)
            {
                for (int index = 0; index < _edgesOnPrincipalPlane.vertexCount; index += 2)
                {
                    if (_edgeClassifier.CrossesXBound(
                            _edgesOnPrincipalPlane.vertices[index],
                            _edgesOnPrincipalPlane.vertices[index + 1]))
                    {
                        return(0);
                    }
                }


                float timeToTarget = 0.0f;

                for (int index = 0; index < _edgesOnPrincipalPlane.vertexCount; index += 2)
                {
                    Vector2 vertex = _edgesOnPrincipalPlane.vertices[index];
                    if (principalTrajectory.PositionYAtX(vertex.x) < vertex.y)
                    {
                        /*
                         * Debug.DrawLine(principalSpace3D.p0,
                         *             principalSpace3D.p0 + principalSpace3D.xAxis * vertex.x + principalSpace3D.yAxis * vertex.y,
                         *             Color.grey);
                         */
                        timeToTarget = PrincipalTimePlanners.GetTimeToTargetRGivenIntermediatePositionQ(
                            principalTrajectory,
                            principalTargetPosition,
                            vertex);

                        principalTrajectory.v0 =
                            principalTrajectory.GetInitialVelocityGivenRelativeTargetAndTime(
                                principalTargetPosition, timeToTarget);
                    }
                }
                return(timeToTarget);
            }