Пример #1
0
        public override void Draw(Matrix currentViewMatrix, Vector3 cameraPosition)
        {
            if (loadedModel_ != null)
            {
                //  the drawdetails set-up can be re-used for all items in the scene
                KiloWatt.Animation.Graphics.DrawDetails dd = drawDetails_;
                dd.dev          = this.RunningGameSession.device;// GraphicsDevice;
                dd.fogColor     = new Vector4(0.5f, 0.5f, 0.5f, 1);
                dd.fogDistance  = 10 * 1000;
                dd.lightAmbient = new Vector4(0.2f, 0.2f, 0.2f, 1.0f);
                dd.lightDiffuse = new Vector4(0.8f, 0.8f, 0.8f, 0);
                dd.lightDir     = Vector3.Normalize(new Vector3(1, 3, 2));

                dd.viewInv  = Matrix.Invert(currentViewMatrix);
                dd.viewProj = currentViewMatrix * this.RunningGameSession.PlayerCamera.projectionMatrix;// projection_;
                dd.world    = Matrix.Identity;

                //  draw the loaded model (the only model I have)
                loadedModel_.ScenePrepare(dd);
                if (loadedModel_.SceneDraw(dd, 0))
                {
                    loadedModel_.SceneDrawTransparent(dd, 0);
                }
            }



            //base.Draw(currentViewMatrix, cameraPosition);
        }
Пример #2
0
 public void CopyTo(DrawDetails o)
 {
     o.dev = dev;
       o.world = world;
       o.view = view;
       o.viewProj = viewProj;
       o.viewInv = viewInv;
       o.projection = projection;
       o.environmentTexture = environmentTexture;
       o.lightDir = lightDir;
       o.lightDiffuse = lightDiffuse;
       o.lightAmbient = lightAmbient;
       o.fogDistance = fogDistance;
       o.fogColor = fogColor;
       o.fogHeight = fogHeight;
       o.fogDepth = fogDepth;
       o.frame = frame;
       o.time = time;
 }
Пример #3
0
 //  do the device and effect magic to render a given chunk of geometry
 private void DrawChunk(DrawDetails dd, Chunk ch)
 {
     //  configure the device and actually draw
       dd.dev.Indices = ch.Part.IndexBuffer;
       dd.dev.SetVertexBuffer(ch.Part.VertexBuffer, ch.Part.VertexOffset);
       //  note: calculating the world matrix overrides the previous value, hence the use
       //  of the saved copy of the world transform
       Matrix.Multiply(ref matrices_[ch.Mesh.ParentBone.Index], ref world_, out dd.world);
       ch.Fx.Setup(dd);
       EffectTechnique et = ch.Fx.FX.CurrentTechnique;
       //  most my effects are single-pass, but at least transparency is multi-pass
       for (int i = 0, n = et.Passes.Count; i != n; ++i)
       {
     EffectPass ep = et.Passes[i];
     ep.Apply();
     dd.dev.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0,
     0, ch.Part.NumVertices, ch.Part.StartIndex, ch.Part.PrimitiveCount);
       }
 }
Пример #4
0
 //  Draw helper that actually issues geometry, or defers for later.
 internal bool Draw(DrawDetails dd, bool asDeferred, uint mask)
 {
     //  keep a copy of world, because I override it in the DrawDetails
       bool added = false;
       //  each chunk is drawn separately, as it represents a different
       //  shader set-up (world transform, texture, etc).
       foreach (Chunk ch in chunks_)
       {
     if (((ch.Bitmask & mask) == 0) && (mask != 0))
       continue;
     if (asDeferred)
     {
       //  If I'm called back to draw deferred pieces, don't draw if this
       //  piece is not deferred.
       if (!ch.Deferred)
     continue;
     }
     else if (ch.Deferred)
     {
       added = true;
       continue;
     }
     DrawChunk(dd, ch);
       }
       return added;
 }
Пример #5
0
 public void ScenePrepare(DrawDetails dd)
 {
     if (PoseSource != null)
     PoseSource.Get(out world_);
       //  if animating, then pose it
       if (instance_ != null)
       {
     Matrix temp;
     Keyframe[] kfs = instance_.CurrentPose;
     unchecked
     {
       int i = 0, n = matrices_.Length;
       foreach (Keyframe kf in kfs)
       {
     if (i == n)
       break;
     if (kf != null)
     {
       kf.ToMatrix(out temp);
       //  set up the model in parent-relative pose
       model_.Bones[i].Transform = temp;
     }
     ++i;
       }
     }
       }
       else
       {
       }
       //  get the object-relative matrices (object->world is separate)
       model_.CopyAbsoluteBoneTransformsTo(matrices_);
     #if DRAW_SKELETON
       //  draw the skeleton, but only in debug mode
       foreach (ModelBone mb in model_.Bones)
       {
     if (mb.Parent != null)
     {
       Matrix m = matrices_[mb.Index];
       Vector3 c = m.Translation;
       DebugLines.Global.AddLine(
       c,
       matrices_[mb.Parent.Index].Translation,
       Color.White);
       DebugLines.Global.AddLine(
       c,
       c + m.Right * 0.5f,
       Color.Red);
       DebugLines.Global.AddLine(
       c,
       c + m.Up * 0.5f,
       Color.Green);
       DebugLines.Global.AddLine(
       c,
       c + m.Backward * 0.5f,
       Color.Blue);
     }
       }
     #endif
       //  If I have a 3x4 matrix pose, then generate that for skinning
       if (pose_ != null)
     GeneratePose();
 }
Пример #6
0
 //  callback for transparent drawing
 public void SceneDrawTransparent(DrawDetails dd, int technique)
 {
     Draw(dd, true, (1U << technique));
 }
Пример #7
0
 //  Only call Draw() once per object instance per frame. Else
 //  transparently sorted pieces won't draw correctly, as there is
 //  only one set of state per ModelDraw. Use multiple ModelDraw
 //  instances for multiple object instances.
 //  Immediately draw the parts that do not require transparency.
 //  put parts that need transparency on a deferred list, to be
 //  drawn later (z sorted) using DrawDeferred().
 public bool SceneDraw(DrawDetails dd, int pass)
 {
     //  chain to an internal helper
       return Draw(dd, false, (1U << pass));
 }
Пример #8
0
 public void Setup(DrawDetails dd, Matrix worldOverride)
 {
     if (lightAmbient_ != null) lightAmbient_.SetValue(dd.lightAmbient);
       if (lightDiffuse_ != null) lightDiffuse_.SetValue(dd.lightDiffuse);
       if (environmentTexture_ != null) environmentTexture_.SetValue(dd.environmentTexture);
       if (lightDir_ != null) lightDir_.SetValue(dd.lightDir);
       if (viewInv_ != null) viewInv_.SetValue(dd.viewInv);
       if (viewProj_ != null) viewProj_.SetValue(dd.viewProj);
       if (world_ != null) world_.SetValue(worldOverride);
       if (worldView_ != null) worldView_.SetValue(worldOverride * dd.view);
       if (view_ != null) view_.SetValue(dd.view);
       if (projection_ != null) projection_.SetValue(dd.projection);
       if (worldViewProj_ != null) worldViewProj_.SetValue(worldOverride * dd.viewProj);
       if (fogDistance_ != null) fogDistance_.SetValue(dd.fogDistance);
       if (fogColor_ != null)
     if (fogColor_.ColumnCount == 3)
       fogColor_.SetValue(new Vector3(dd.fogColor.X, dd.fogColor.Y, dd.fogColor.Z));
     else
       fogColor_.SetValue(dd.fogColor);
       if (fogHeight_ != null) fogHeight_.SetValue(dd.fogHeight);
       if (fogDepth_ != null) fogDepth_.SetValue(dd.fogDepth);
       if (frame_ != null)
     frame_.SetValue(dd.frame);
       if (time_ != null)
     time_.SetValue(dd.time);
       if (pose_ != null)
     pose_.SetValue(PoseData);
 }
Пример #9
0
 public void Setup(DrawDetails dd)
 {
     Setup(dd, dd.world);
 }