Exemplo n.º 1
0
        public virtual void OnRenderShadow(Device device, Vector3 p1, Vector3 p2, Vector3 p3, Vector3 lightDir)
        {
            if (Visible == false)
            {
                return;
            }
            if (matrixInvalid)
            {
                // scale
                transformMatrix = Matrix.Scaling(scale);
                // Rotate
                switch (orientationMode)
                {
                case OrientationModeEnum.XYZ:
                    transformMatrix.Multiply(Matrix.RotationX(orientation.X));
                    transformMatrix.Multiply(Matrix.RotationY(orientation.Y));
                    transformMatrix.Multiply(Matrix.RotationZ(orientation.Z));
                    break;

                case OrientationModeEnum.Axis:
                    transformMatrix.Multiply(Matrix.RotationAxis(orientation, rotationAngle));
                    break;

                case OrientationModeEnum.YawPitchRoll:
                    transformMatrix.Multiply(Matrix.RotationYawPitchRoll(orientation.X, orientation.Y, orientation.Z));
                    break;

                case OrientationModeEnum.Quaternion:
                    // TODO
                    break;

                case OrientationModeEnum.YXZ:
                    transformMatrix.Multiply(Matrix.RotationY(orientation.Y));
                    transformMatrix.Multiply(Matrix.RotationX(orientation.X));
                    transformMatrix.Multiply(Matrix.RotationZ(orientation.Z));
                    break;
                }
                // Translate
                transformMatrix.Multiply(Matrix.Translation(position));
                matrixInvalid = false;
            }

            /*
             * Matrix newTransformMatrix = transformMatrix;
             * if (parent != null)
             * {
             *  newTransformMatrix.Multiply(parent.transformMatrix);
             * }
             */
            Matrix newTransformMatrix = InheritedTransformMatrix;

            Plane  plane     = Plane.FromPoints(p1, p2, p3);
            Matrix shadowMat = new Matrix();

            shadowMat.Shadow(new Vector4(lightDir.X, lightDir.Y, lightDir.Z, 0f), plane);
            newTransformMatrix.Multiply(shadowMat);

            // Move
            device.Transform.World = newTransformMatrix;

            // Render
            if (mesh != null)
            {
                if (mesh is XMesh)
                {
                    XMesh xmesh = mesh as XMesh;
                    xmesh.OnRenderShadow(device);
                }
            }
            // Reset transformation
            device.Transform.World = Matrix.Identity;

            // Forward to children
            foreach (GameObject child in children)
            {
                child.OnRenderShadow(device, p1, p2, p3, lightDir);
            }
        }