示例#1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AgaQ.Bricks.Positioners.PossibleJoint"/> struct.
        /// </summary>
        /// <param name="projectedBrickJoint">Proejected brick joint.</param>
        /// <param name="projectedOtherJoint">Proejected other joint.</param>
        public PossibleJoint(ProjectedJoint projectedBrickJoint, ProjectedJoint projectedOtherJoint)
        {
            this.projectedBrickJoint = projectedBrickJoint;
            this.projectedOtherJoint = projectedOtherJoint;

            projectedDistance = (projectedBrickJoint.projectedPosition - projectedOtherJoint.projectedPosition).magnitude;

            var vector          = projectedBrickJoint.joint.transform.position - projectedOtherJoint.joint.transform.position;
            var projectedVector = Vector3.Project(vector, UnityEngine.Camera.main.transform.forward);

            cameraVectorDistance = projectedVector.magnitude;
        }
示例#2
0
        /// <summary>
        /// Project joints to screen coordinates.
        /// </summary>
        /// <returns>The joints.</returns>
        /// <param name="brick">AgaQ brick</param>
        public static ProjectedJoint[] ProjectJoints(AgaQBrick brick)
        {
            ProjectedJoint[] brickJoints = new ProjectedJoint[brick.joints.Length];

            //itareate over all joints and move its coordinates to screen space
            int j = 0;

            for (int i = 0; i < brickJoints.Length; i++)
            {
                if (brick.joints[i].other == null)
                {
                    brickJoints[j++] = new ProjectedJoint(ProjectPosition(brick.joints[i].transform.position), brick.joints[i]);
                }
            }

            Array.Resize <ProjectedJoint>(ref brickJoints, j);
            return(brickJoints);
        }
示例#3
0
        /// <summary>
        /// Comare two projected joints by type, rotation and position.
        /// </summary>
        /// <returns><c>true</c>, if joints can be joined, <c>false</c> otherwise.</returns>
        /// <param name="projectedJoint1">Joint 1.</param>
        /// <param name="projectedJoint2">Joint 2.</param>
        /// <param name="positionTolerance">Position tolerance.</param>
        public static bool Compare(ProjectedJoint projectedJoint1, ProjectedJoint projectedJoint2, float positionTolerance)
        {
            //compare joints type, has to be oposite type
            if (!Joints.Joint.AreJoinable(projectedJoint1.joint, projectedJoint2.joint))
            {
                return(false);
            }

            //compare joints rotation
            float angle = 0;

            if (projectedJoint1.joint.ignoreYRotation || projectedJoint2.joint.ignoreYRotation)
            {
                angle = Quaternion.Angle(
                    new Quaternion(
                        projectedJoint1.joint.transform.rotation.x, 0,
                        projectedJoint1.joint.transform.rotation.z,
                        projectedJoint1.joint.transform.rotation.w),
                    new Quaternion(
                        projectedJoint2.joint.transform.rotation.x, 0,
                        projectedJoint2.joint.transform.rotation.z,
                        projectedJoint2.joint.transform.rotation.w)
                    );
            }
            else
            {
                angle = Quaternion.Angle(projectedJoint1.joint.transform.rotation, projectedJoint2.joint.transform.rotation);
            }
            if (angle > rotationTolerance)
            {
                return(false);
            }

            //compare position
            if ((projectedJoint1.projectedPosition - projectedJoint2.projectedPosition).magnitude > positionTolerance)
            {
                return(false);
            }

            return(true);
        }
示例#4
0
 /// <summary>
 /// Comare joint by type, rotation and position.
 /// </summary>
 /// <returns><c>true</c>, if joints can be joined, <c>false</c> otherwise.</returns>
 /// <param name="otherProjectedJoint">Other projected joint.</param>
 /// <param name="positionTolerance">Position tolerance.</param>
 public bool Compare(ProjectedJoint otherProjectedJoint, float positionTolerance)
 {
     return(Compare(this, otherProjectedJoint, positionTolerance));
 }