コード例 #1
0
        private void OnAttributeChanged(object sender, AttributeEventArgs e)
        {
            if (e.AttributeInfo.Equivalent(Schema.gameObjectType.pivotAttribute))
            {// Update translation to keep object pinned when moving pivot
                Matrix4F L0 = m_transformable.Transform;
                Matrix4F L1 = TransformUtils.CalcTransform(
                    m_transformable.Translation,
                    m_transformable.Rotation,
                    m_transformable.Scale,
                    m_transformable.Pivot);

                Vec3F deltaTranslation = L0.Translation - L1.Translation;
                m_transformable.Translation = m_transformable.Translation + deltaTranslation;
            }

            if (IsTransformAttribute(e.AttributeInfo))
            {
                ComputeTransform();
            }
        }
コード例 #2
0
        /// <summary>
        /// Performs custom actions on NodeSet events.
        /// Called after successfully attaching to internal DOM object.</summary>
        protected override void OnNodeSet()
        {
            base.OnNodeSet();

            // Initialize scale to (1, 1, 1) if missing
            DomNode.SetAttributeIfDefault(Schema.nodeType.scaleAttribute, new Vec3F(1, 1, 1));

            m_rotation     = DomNode.GetChild(Schema.nodeType.rotEulChild);
            m_rotationAxis = DomNode.GetChild(Schema.nodeType.rotAxisEulChild);
            Transform      = TransformUtils.CalcTransform(this);

            Box boxValue = DomNodeUtil.GetBox(DomNode, Schema.nodeType.boundingBoxAttribute);

            if (boxValue.IsEmpty)
            {
                m_boundingBox = new Cached <Box>(CalculateBoundingBox); // don't set value and force to compute
            }
            else
            {
                m_boundingBox = new Cached <Box>(CalculateBoundingBox, boxValue); // non-default value found, use it
            }
        }
コード例 #3
0
        public override void OnDragging(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None || m_activeOp == null || m_activeOp.NodeList.Count == 0)
            {
                return;
            }

            Matrix4F view = vc.Camera.ViewMatrix;
            // compute world * view
            Matrix4F wv = new Matrix4F();

            wv.Mul(HitMatrix, view);

            // create ray in view space.
            Ray3F rayV = vc.GetRay(scrPt, vc.Camera.ProjectionMatrix);

            Vec3F xAxis  = wv.XAxis;
            Vec3F yAxis  = wv.YAxis;
            Vec3F zAxis  = wv.ZAxis;
            Vec3F origin = wv.Translation;

            m_scale = new Vec3F(1, 1, 1);
            float scale = 1;
            float a1, a2;

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            case HitRegion.NegXAxis:
            {
                a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, yAxis));
                a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, zAxis));
                Vec3F axis       = (a1 > a2 ? yAxis : zAxis);
                Vec3F p0         = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                Vec3F p1         = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                float dragAmount = Vec3F.Dot((p1 - p0), xAxis);
                if (m_hitRegion == HitRegion.NegXAxis)
                {
                    dragAmount *= -1;
                }
                m_scale.X = 1.0f + dragAmount / m_hitScale;
                scale     = m_scale.X;
            }

            break;

            case HitRegion.YAxis:
            case HitRegion.NegYAxis:
            {
                a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, zAxis));
                a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, xAxis));
                Vec3F axis       = (a1 > a2 ? zAxis : xAxis);
                Vec3F p0         = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                Vec3F p1         = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                float dragAmount = Vec3F.Dot((p1 - p0), yAxis);
                if (m_hitRegion == HitRegion.NegYAxis)
                {
                    dragAmount *= -1;
                }
                m_scale.Y = 1.0f + dragAmount / m_hitScale;
                scale     = m_scale.Y;
            }
            break;

            case HitRegion.ZAxis:
            case HitRegion.NegZAxis:
            {
                a1 = Math.Abs(Vec3F.Dot(HitRayV.Direction, xAxis));
                a2 = Math.Abs(Vec3F.Dot(HitRayV.Direction, yAxis));
                Vec3F axis       = (a1 > a2 ? xAxis : yAxis);
                Vec3F p0         = HitRayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                Vec3F p1         = rayV.IntersectPlane(axis, -Vec3F.Dot(axis, origin));
                float dragAmount = Vec3F.Dot((p1 - p0), zAxis);
                if (m_hitRegion == HitRegion.NegZAxis)
                {
                    dragAmount *= -1;
                }
                m_scale.Z = 1.0f + dragAmount / m_hitScale;
                scale     = m_scale.Z;
            }
            break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            if (m_isUniformScaling)
            {
                m_scale = new Vec3F(scale, scale, scale);
            }


            // scale
            for (int i = 0; i < m_activeOp.NodeList.Count; i++)
            {
                ITransformable node = m_activeOp.NodeList[i];
                node.Scale = Vec3F.Mul(m_originalScales[i], m_scale);

                Matrix4F mtrx = TransformUtils.CalcTransform(
                    Vec3F.ZeroVector,
                    node.Rotation,
                    node.Scale,
                    m_pivotOffset[i]);
                node.Translation = m_originalTranslations[i] + mtrx.Translation;
            }
        }
コード例 #4
0
        public override void OnBeginDrag(ViewControl vc, Point scrPt)
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }

            m_activeOp = null;

            var op = new ManipulatorActiveOperation(
                "Extend", DesignView.Context.As <ISelectionContext>(),
                (ITransformable node) => (node.TransformationType & TransformationTypes.Scale) != 0,
                false);

            // to compute offset use bounding box in local space.
            Vec3F offset = Vec3F.ZeroVector;// 0.5f; // use bounding box in local space

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            case HitRegion.YAxis:
            case HitRegion.ZAxis:
                offset = new Vec3F(-1, -1, -1);
                break;

            case HitRegion.NegXAxis:
            case HitRegion.NegYAxis:
            case HitRegion.NegZAxis:
                offset = new Vec3F(1, 1, 1);
                break;

            default:
                break;
            }

            m_isUniformScaling     = false;
            m_originalScales       = new Vec3F[op.NodeList.Count];
            m_originalTranslations = new Vec3F[op.NodeList.Count];
            m_pivotOffset          = new Vec3F[op.NodeList.Count];
            int k = 0;

            foreach (ITransformable node in op.NodeList)
            {
                //  if any of the selected nodes are marked as "UniformScale", then the
                //  entire operation must be a uniform scale operaion
                if ((node.TransformationType & TransformationTypes.UniformScale) == TransformationTypes.UniformScale)
                {
                    m_isUniformScaling = true;
                }

                IBoundable boundable = node.As <IBoundable>();
                Vec3F      pivot     = Vec3F.Mul(boundable.LocalBoundingBox.Radius, offset);
                m_pivotOffset[k] = pivot;

                m_originalScales[k] = node.Scale;

                Matrix4F mtrx = TransformUtils.CalcTransform(
                    Vec3F.ZeroVector,
                    node.Rotation,
                    node.Scale,
                    pivot
                    );

                m_originalTranslations[k] = node.Translation - mtrx.Translation;
                k++;
            }

            m_activeOp = op;
        }
コード例 #5
0
        public override void OnBeginDrag()
        {
            if (m_hitRegion == HitRegion.None)
            {
                return;
            }

            var selection          = DesignView.Context.As <ISelectionContext>().Selection;
            var transactionContext = DesignView.Context.As <ITransactionContext>();

            NodeList.Clear();

            m_isUniformScaling = false;

            IEnumerable <DomNode> rootDomNodes = DomNode.GetRoots(selection.AsIEnumerable <DomNode>());

            foreach (DomNode node in rootDomNodes)
            {
                ITransformable transNode = node.As <ITransformable>();
                if (transNode == null || (transNode.TransformationType & TransformationTypes.Scale) == 0)
                {
                    continue;
                }

                IVisible vn = node.As <IVisible>();
                if (!vn.Visible)
                {
                    continue;
                }

                ILockable lockable = node.As <ILockable>();
                if (lockable.IsLocked)
                {
                    continue;
                }

                // force uniform scaling if any node requires it
                if ((transNode.TransformationType & TransformationTypes.UniformScale) == TransformationTypes.UniformScale)
                {
                    m_isUniformScaling = true;
                }

                NodeList.Add(transNode);

                IManipulatorNotify notifier = transNode.As <IManipulatorNotify>();
                if (notifier != null)
                {
                    notifier.OnBeginDrag();
                }
            }


            // to compute offset use bounding box in local space.
            Vec3F offset = Vec3F.ZeroVector;// 0.5f; // use bounding box in local space

            switch (m_hitRegion)
            {
            case HitRegion.XAxis:
            case HitRegion.YAxis:
            case HitRegion.ZAxis:
                offset = new Vec3F(-1, -1, -1);
                break;

            case HitRegion.NegXAxis:
            case HitRegion.NegYAxis:
            case HitRegion.NegZAxis:
                offset = new Vec3F(1, 1, 1);
                break;

            default:
                break;
            }

            m_originalScales       = new Vec3F[NodeList.Count];
            m_originalTranslations = new Vec3F[NodeList.Count];
            m_pivotOffset          = new Vec3F[NodeList.Count];
            int k = 0;

            foreach (ITransformable node in NodeList)
            {
                IBoundable boundable = node.As <IBoundable>();
                Vec3F      pivot     = Vec3F.Mul(boundable.LocalBoundingBox.Radius, offset);
                m_pivotOffset[k] = pivot;

                m_originalScales[k] = node.Scale;

                Matrix4F mtrx = TransformUtils.CalcTransform(
                    Vec3F.ZeroVector,
                    node.Rotation,
                    node.Scale,
                    pivot
                    );

                m_originalTranslations[k] = node.Translation - mtrx.Translation;
                k++;
            }

            if (NodeList.Count > 0)
            {
                transactionContext.Begin("Extend".Localize());
            }
        }
コード例 #6
0
        public virtual void UpdateTransform()
        {
            Matrix4F xform = TransformUtils.CalcTransform(this);

            SetAttribute(Schema.gameObjectType.transformAttribute, xform.ToArray());
        }
コード例 #7
0
ファイル: TransformObject.cs プロジェクト: coreafive/XLE
 public virtual void UpdateTransform()
 {
     this.SetMatrix4x4(TransformableST.transformAttribute, TransformUtils.CalcTransform(this));
 }
コード例 #8
0
        /// <summary>
        /// Computes transformation matrix from transformation related atrributes.</summary>
        public void ComputeTransform()
        {
            Matrix4F xform = TransformUtils.CalcTransform(m_transformable);

            SetAttribute(Schema.gameObjectType.transformAttribute, xform.ToArray());
        }