コード例 #1
0
        /// <summary>
        /// Gets the rotation matrix for this object.
        /// </summary>
        public Matrix4x4 GetRotationMatrix()
        {
            switch (m_transformationType)
            {
            case SpacialTransformationType.ScalingTranslationEulerAngles:
            case SpacialTransformationType.TranslationEulerAngles:
                return(Matrix4x4.CreateFromYawPitchRoll(m_rotation.Y, m_rotation.X, m_rotation.Z));

            case SpacialTransformationType.ScalingTranslationQuaternion:
            case SpacialTransformationType.TranslationQuaternion:
                return(Matrix4x4.CreateFromQuaternion(m_rotationQuaternion));

            case SpacialTransformationType.ScalingTranslationDirection:
            case SpacialTransformationType.TranslationDirection:
                return(Matrix4x4Ex.CreateRotationDirection(m_rotationUp, m_rotationForward));

            case SpacialTransformationType.Translation:
            case SpacialTransformationType.None:
            case SpacialTransformationType.CustomTransform:
                return(Matrix4x4.Identity);

            case SpacialTransformationType.TakeFromOtherObject:
                if (m_transformSourceObject != null)
                {
                    return(m_transformSourceObject.GetRotationMatrix());
                }
                else
                {
                    return(Matrix4x4.Identity);
                }

            default:
                throw new SeeingSharpGraphicsException("Unknown transformation type: " + m_transformationType);
            }
        }
コード例 #2
0
        /// <summary>
        /// Updates the object.
        /// </summary>
        /// <param name="updateState">Current update state.</param>
        protected override void UpdateInternal(SceneRelatedUpdateState updateState)
        {
            //Calculates local transform matrix (transforms local space to world space)
            bool doRecreateShaderParameters = false;

            base.TransormationChanged =
                m_transformParamsChanged || updateState.ForceTransformUpdatesOnChilds;

            // Update local transform matrix if transform values have changed
            if (m_transformParamsChanged || updateState.ForceTransformUpdatesOnChilds)
            {
                m_transformParamsChanged       = false;
                m_forceTransformUpdateOnChilds = this.HasChilds;
                doRecreateShaderParameters     = true;

                // Calculate new transformation matrix
                switch (m_transformationType)
                {
                case SpacialTransformationType.ScalingTranslationEulerAngles:
                    m_transform =
                        Matrix4x4.CreateScale(m_scaling) *
                        Matrix4x4.CreateFromYawPitchRoll(m_rotation.Y, m_rotation.X, m_rotation.Z) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.ScalingTranslationQuaternion:
                    m_transform =
                        Matrix4x4.CreateScale(m_scaling) *
                        Matrix4x4.CreateFromQuaternion(m_rotationQuaternion) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.ScalingTranslationDirection:
                    m_transform =
                        Matrix4x4.CreateScale(m_scaling) *
                        Matrix4x4Ex.CreateRotationDirection(m_rotationUp, m_rotationForward) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.ScalingTranslation:
                    m_transform =
                        Matrix4x4.CreateScale(m_scaling) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.TranslationEulerAngles:
                    m_transform =
                        Matrix4x4.CreateFromYawPitchRoll(m_rotation.Y, m_rotation.X, m_rotation.Z) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.TranslationQuaternion:
                    m_transform =
                        Matrix4x4.CreateFromQuaternion(m_rotationQuaternion) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.TranslationDirection:
                    m_transform =
                        Matrix4x4Ex.CreateRotationDirection(m_rotationUp, m_rotationForward) *
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.Translation:
                    m_transform =
                        Matrix4x4.CreateTranslation(m_position) *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.CustomTransform:
                    m_transform =
                        m_customTransform *
                        updateState.World.Top;
                    break;

                case SpacialTransformationType.TakeFromOtherObject:
                    if (m_transformSourceObject != null)
                    {
                        m_transform = m_transformSourceObject.m_transform;
                    }
                    else
                    {
                        m_transform = updateState.World.Top;
                    }
                    break;

                case SpacialTransformationType.None:
                    m_transform = updateState.World.Top;
                    break;
                }
            }

            // Trigger recreation of shader parameters
            if (doRecreateShaderParameters)
            {
                TriggerRecreateOfParameters();
            }
        }