Beispiel #1
0
        static bool SetTexture(Board board, int textureIndex)
        {
            LightingEffect lightingEffect = board.LightingEffect;
            Texture2D      texture        = null;

            if (board.CurrentPictureSet != null)
            {
                texture = board.CurrentPictureSet.GetTexture(textureIndex);
            }

            if ((texture == null) && (board.NextPictureSet != null))
            {
                texture = board.NextPictureSet.GetTexture(textureIndex);
            }

            lightingEffect.DiffuseTexture.SetValue(texture);

            return(texture != null);
        }
Beispiel #2
0
        public void Draw(Board board, Model chipModel, Matrix baseTransform, Matrix[] chipTransforms)
        {
            Matrix         world          = OrientationMatrix * baseTransform;
            LightingEffect lightingEffect = board.LightingEffect;

            lightingEffect.GlowScale.SetValue(GlowScale);
            lightingEffect.ColorOverride.SetValue(ColorOverride);
            lightingEffect.TexCoordScale.SetValue(TexCoordScale);

            foreach (ModelMesh mesh in chipModel.Meshes)
            {
                Matrix modelWorld               = chipTransforms[mesh.ParentBone.Index] * world;
                Matrix modelWorldView           = modelWorld * board.Camera.ViewMatrix;
                Matrix modelWorldViewProjection = modelWorldView * board.Camera.ProjectionMatrix;

                lightingEffect.World.SetValue(modelWorld);
                lightingEffect.WorldView.SetValue(modelWorldView);
                lightingEffect.WorldViewProjection.SetValue(modelWorldViewProjection);

                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    bool   textureSet         = false;
                    string materialIdentifier = meshPart.Tag as string;
                    if (materialIdentifier != null)
                    {
                        switch (materialIdentifier)
                        {
                        case "Front":
                            lightingEffect.TexCoordTranslation.SetValue(this.TexCoordTranslationFront);
                            textureSet = SetTexture(board, 0);
                            break;

                        case "Back":
                            lightingEffect.TexCoordTranslation.SetValue(this.TexCoordTranslationBack);
                            if (board.TwoSided)
                            {
                                textureSet = SetTexture(board, 1);
                            }
                            else
                            {
                                textureSet = SetTexture(board, 0);
                            }
                            break;

                        default:
                            lightingEffect.DiffuseTexture.SetValue((Texture2D)null);
                            break;
                        }
                    }

                    if (textureSet)
                    {
                        lightingEffect.Effect.CurrentTechnique = lightingEffect.SingleTextureTechnique;
                    }
                    else
                    {
                        lightingEffect.Effect.CurrentTechnique = lightingEffect.NoTextureTechnique;
                    }

                    lightingEffect.Effect.Begin();
                    DrawHelper.DrawMeshPart(mesh, meshPart, lightingEffect.Effect);
                    lightingEffect.Effect.End();
                }
            }
        }