コード例 #1
0
        protected override void LoadContent()
        {
            spriteBatch       = new SpriteBatch(GraphicsDevice);
            currentFont       = Content.Load <SpriteFont>("MgGenFont");
            defaultTexture    = Content.Load <Texture2D>("CheckerBoardTemplateImage");
            orientationArrows = Content.Load <Texture2D>("OrientationImage_PartiallyTransparent");

            LoadUpDefaultCamera();

            LoadEffects();

            bigShere     = new SpherePNTT(false, 12, 25f, false, true);
            littleSphere = new SpherePNTT(false, 12, 5f, true);
            lineToLight  = new LinePCT(.1f, Color.White, Vector3.Zero, initialLightPosition);

            // prep model reader.
            RiggedModelLoader modelReader = new RiggedModelLoader(Content, riggedEffect);

            RiggedModelLoader.DefaultTexture     = defaultTexture;
            modelReader.AddAdditionalLoopingTime = true;
            modelReader.AddedLoopingDuration     = .1f;
            //
            //model = modelReader.LoadAsset("dude.fbx", 24);
            //model = modelReader.LoadAsset("new_thin_zombie.fbx", 24);
            //model = modelReader.LoadAsset("AnimatedCube5.fbx", 24);
            model = modelReader.LoadAsset("PipeFromCube16VGrpsLCRetexAnimKeyframesMovedUp.fbx", 24); // damn its hard to find models that work.

            modelVisualNormals    = new ModelsVisualNormals(model, orientationArrows, .5f, 1f);
            primitiveNormalArrows = new NormalArrow(bigShere.vertices, bigShere.indices, orientationArrows, 1f);
        }
コード例 #2
0
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.Black);
            GraphicsDevice.Clear(ClearOptions.DepthBuffer, Color.Black, 1f, 1);
            GraphicsDevice.BlendState        = BlendState.Opaque;
            GraphicsDevice.SamplerStates[0]  = ss_point_clamp;
            GraphicsDevice.DepthStencilState = ds_standard_less;
            if (WireframeOnOrOff)
            {
                GraphicsDevice.RasterizerState = rs_nocullwireframe;
            }
            else
            {
                GraphicsDevice.RasterizerState = rs_cull_cw_solid;
            }

            // set model world
            var modelWorld = Matrix.Identity;
            //modelWorld = Matrix.CreateRotationY(1.5f);
            //modelWorld.Translation = new Vector3(5f, -0f, 0f);
            // set sphere orientation
            var sphereOrientation = Matrix.Identity * lightTransform;

            sphereOrientation.Translation = new Vector3(0, -50f, 0f);
            // light pos
            var lightpos = Vector3.Transform(initialLightPosition, lightTransform);

            // set light to shader
            riggedEffect.Parameters["WorldLightPosition"].SetValue(lightpos);
            // set view to shader
            riggedEffect.Parameters["View"].SetValue(cam.View);
            // set camera world position to shader
            riggedEffect.Parameters["CameraPosition"].SetValue(cam.Position); // cam.Position // cam.View.Translation
            // remake the line
            lineToLight = new LinePCT(.1f, Color.White, sphereOrientation.Translation, lightpos);

            //_______________________________
            // draw a line to the light source.
            //_______________________________

            riggedEffect.CurrentTechnique = riggedEffect.Techniques["ColorDraw"];
            riggedEffect.Parameters["World"].SetValue(Matrix.Identity);
            riggedEffect.Parameters["TextureA"].SetValue(defaultTexture);

            lineToLight.Draw(GraphicsDevice, riggedEffect);

            //_______________________________
            // draw sphere.
            //_______________________________

            // move the spheres down a bit first
            riggedEffect.Parameters["World"].SetValue(sphereOrientation);

            riggedEffect.CurrentTechnique = riggedEffect.Techniques["ColorTextureLightingDraw"];

            littleSphere.Draw(GraphicsDevice, riggedEffect);
            bigShere.Draw(GraphicsDevice, riggedEffect);

            // draw sphere normals
            riggedEffect.CurrentTechnique  = riggedEffect.Techniques["ColorTextureLightingNormalsDraw"];
            GraphicsDevice.RasterizerState = rs_nocullsolid;
            if (ShowNormals)
            {
                primitiveNormalArrows.Draw(GraphicsDevice, riggedEffect);
            }

            if (WireframeOnOrOff)
            {
                GraphicsDevice.RasterizerState = rs_nocullwireframe;
            }
            else
            {
                GraphicsDevice.RasterizerState = rs_cull_cw_solid;
            }

            //_______________________________
            // model and normals
            //_______________________________


            // draw a little sphere in the model just make sure the model isnt backface.
            var m = Matrix.Identity;

            m.Translation = new Vector3(0, 20, 0);
            riggedEffect.Parameters["World"].SetValue(m);
            littleSphere.Draw(GraphicsDevice, riggedEffect);

            // draw models.

            if (model != null)
            {
                riggedEffect.CurrentTechnique = riggedEffect.Techniques["RiggedModelDraw"];
                modelWorld = Matrix.Identity;
                riggedEffect.Parameters["World"].SetValue(modelWorld);
                model.effect = riggedEffect;
                model.Draw(GraphicsDevice, modelWorld);
            }

            // draw models normals.

            riggedEffect.CurrentTechnique  = riggedEffect.Techniques["RiggedModelNormalDraw"];
            GraphicsDevice.RasterizerState = rs_nocullsolid;
            if (ShowNormals)
            {
                modelVisualNormals.Draw(GraphicsDevice, riggedEffect);
            }


            DrawSpriteBatches(gameTime);
            base.Draw(gameTime);
        }