Exemple #1
0
        private void OnPreStepForwardCallback()
        {
            if (m_camera == null)
            {
                return;
            }

            if (ConstraintGameObject == null && Input.GetKey(TriggerKey) && m_mouseButtonState.ButtonDown != MouseButton.None)
            {
                Ray ray = m_camera.ScreenPointToRay(Input.mousePosition);
                List <BroadPhaseResult> results = FindRayBoundingVolumeOverlaps(ray);
                if (results.Count > 0)
                {
                    ConstraintGameObject = TryCreateConstraint(ray,
                                                               results[0].GameObject,
                                                               MouseButtonToDofTypes(m_mouseButtonState.ButtonDown),
                                                               "PickHandlerConstraint");
                    if (ConstraintGameObject != null)
                    {
                        ConstraintGameObject.AddComponent <Rendering.PickHandlerRenderer>();
                        Constraint.DrawGizmosEnable = false;
                        m_distanceFromCamera        = FindDistanceFromCamera(m_camera,
                                                                             Constraint.AttachmentPair.ReferenceFrame.Position);
                    }
                }

                m_mouseButtonState.Use(m_mouseButtonState.ButtonDown, buttonUp =>
                {
                    if (ConstraintGameObject != null)
                    {
                        DestroyImmediate(ConstraintGameObject);
                        ConstraintGameObject = null;
                        m_distanceFromCamera = -1f;
                    }
                });
            }

            if (ConstraintGameObject != null)
            {
                Constraint.AttachmentPair.ConnectedFrame.Position = m_camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
                                                                                                            Input.mousePosition.y,
                                                                                                            m_distanceFromCamera));

                SetComplianceDamping(Constraint);

                ConstraintGameObject.GetComponent <Rendering.PickHandlerRenderer>().ThisMethodIsntAllowedToBeNamedUpdateByUnity(Constraint);
            }
        }
Exemple #2
0
        private void OnPreStepForwardCallback()
        {
            // Trigger key + mouse button down and we enable the line geometry
            // here - similar to preCollide. In pre-step event if the line
            // geometry is enabled, collect geometry contacts with our line
            // and create constraint with the closest point.

            if (m_camera == null)
            {
                return;
            }

            if (ConstraintGameObject == null && Input.GetKey(TriggerKey) && m_mouseButtonState.ButtonDown != MouseButton.None)
            {
                var ray = m_camera.ScreenPointToRay(Input.mousePosition);
                m_lineShape.set(ray.origin.ToHandedVec3(), ray.GetPoint(5000.0f).ToHandedVec3());
                m_lineGeometry.setEnable(true);

                m_mouseButtonState.Use(m_mouseButtonState.ButtonDown, buttonUp =>
                {
                    if (ConstraintGameObject != null)
                    {
                        DestroyImmediate(ConstraintGameObject);
                        ConstraintGameObject = null;
                        m_distanceFromCamera = -1f;
                    }
                    m_lineGeometry.setEnable(false);
                });
            }

            if (ConstraintGameObject != null)
            {
                Constraint.AttachmentPair.ConnectedFrame.Position = m_camera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x,
                                                                                                            Input.mousePosition.y,
                                                                                                            m_distanceFromCamera));

                SetComplianceDamping(Constraint);

                ConstraintGameObject.GetComponent <Rendering.PickHandlerRenderer>().ThisMethodIsntAllowedToBeNamedUpdateByUnity(Constraint, m_camera);
            }
        }