Ejemplo n.º 1
0
        public void AddLightMesh()
        {
            Direct3D.Material mat = new Direct3D.Material();
            mat.Diffuse           = Color.Yellow;
            mat.Ambient           = Color.Yellow;
            mat.Specular          = Color.Yellow;
            mat.SpecularSharpness = 1;

            Direct3D.Material matoff = new Direct3D.Material();
            matoff.Diffuse           = Color.DarkGray;
            matoff.Ambient           = Color.DarkGray;
            matoff.Specular          = Color.DarkGray;
            matoff.SpecularSharpness = 1;
            Mesh m  = Mesh.Sphere(Device, 0.2f, 10, 4);
            Mesh mp = Mesh.Box(Device, 0.2f, 0.2f, 0.2f);

            MeshBox mb;

            for (int i = 0; i < Device.Lights.Count; i++)
            {
                Light l = Device.Lights[i];
                if (!l.Enabled)
                {
                    mb = new MeshBox("Light", m, 1, matoff);
                }
                else
                {
                    mb = new MeshBox("Light", m, 1, mat);
                }

                Vector3 v = l.Position;

                mb.Transform = MeshTransform.Translation(v);
                this.Meshes.Add(mb);

                if (!l.Enabled)
                {
                    mb = new MeshBox("Light", mp, 1, matoff);
                }
                else
                {
                    mb = new MeshBox("Light", mp, 1, mat);
                }
                mb.Transform = MeshTransform.Translation(l.Position + 0.4f * l.Direction);
                this.Meshes.Add(mb);

                if (!l.Enabled)
                {
                    mb = new MeshBox("Light", mp, 1, matoff);
                }
                else
                {
                    mb = new MeshBox("Light", mp, 1, mat);
                }
                mb.Transform = MeshTransform.Translation(l.Position + 0.5f * l.Direction);
                this.Meshes.Add(mb);
            }
        }
Ejemplo n.º 2
0
        public void AddAxisMesh()
        {
            Direct3D.Material mat = new Direct3D.Material();
            mat.Diffuse           = Color.Red;
            mat.Ambient           = mat.Diffuse;
            mat.Specular          = mat.Diffuse;
            mat.SpecularSharpness = 1;



            Mesh    m  = Mesh.Cylinder(device, 0.001f, 0.001f, 1, 6, 1);
            MeshBox mb = new MeshBox("Axis", m, 1, mat);

            mb.Transform = MeshTransform.Translation(new Vector3(0, 0, 0));
            mb.Wire      = false;
            this.Meshes.Add(mb);

            mat.Diffuse  = Color.Green;
            mat.Ambient  = mat.Diffuse;
            mat.Specular = mat.Diffuse;
            m            = Mesh.Cylinder(device, 0.001f, 0.001f, 1, 6, 1);
            mb           = new MeshBox("Axis", m, 1, mat);
            mb.Transform = MeshTransform.RotationYawPitchRoll(
                0,
                -Math.PI / 2.0,
                0
                );
            mb.Wire = false;
            this.Meshes.Add(mb);

            mat.Diffuse  = Color.Blue;
            mat.Ambient  = mat.Diffuse;
            mat.Specular = mat.Diffuse;
            m            = Mesh.Cylinder(device, 0.001f, 0.001f, 1, 6, 1);
            mb           = new MeshBox("Axis", m, 1, mat);
            mb.Transform = MeshTransform.RotationYawPitchRoll(
                -Math.PI / 2.0,
                0,
                0
                );
            mb.Wire = false;
            this.Meshes.Add(mb);
        }
Ejemplo n.º 3
0
        protected void ResetView()
        {
            vp.Reset();

            try
            {
                Vector3 min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
                Vector3 max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

                foreach (NodeBox n in meshes)
                {
                    MeshBox m = null;
                    if (n is MeshBox)
                    {
                        m = (MeshBox)n;
                    }
                    else
                    {
                        continue;
                    }

                    Mesh mesh = m.Mesh;

                    int[] rank = { mesh.NumberVertices };
                    if (mesh.VertexBuffer.Description.VertexFormat == (VertexFormats)0x112)
                    {
                        CustomVertex.PositionNormalTextured[] vertices = (CustomVertex.PositionNormalTextured[])mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormalTextured), LockFlags.None, rank);
                        try
                        {
                            foreach (CustomVertex.PositionNormalTextured v in vertices)
                            {
                                if (v.X < min.X)
                                {
                                    min.X = v.X;
                                }
                                if (v.Y < min.Y)
                                {
                                    min.Y = v.Y;
                                }
                                if (v.Z < min.Z)
                                {
                                    min.Z = v.Z;
                                }

                                if (v.X > max.X)
                                {
                                    max.X = v.X;
                                }
                                if (v.Y > max.Y)
                                {
                                    max.Y = v.Y;
                                }
                                if (v.Z > max.Z)
                                {
                                    max.Z = v.Z;
                                }
                            }
                        }
                        finally
                        {
                            mesh.UnlockVertexBuffer();
                        }
                    }
                    else if (mesh.VertexBuffer.Description.VertexFormat == VertexFormats.PositionNormal)
                    {
                        CustomVertex.PositionNormal[] vertices = (CustomVertex.PositionNormal[])mesh.LockVertexBuffer(typeof(CustomVertex.PositionNormal), LockFlags.None, rank);
                        try
                        {
                            foreach (CustomVertex.PositionNormal v in vertices)
                            {
                                if (v.X < min.X)
                                {
                                    min.X = v.X;
                                }
                                if (v.Y < min.Y)
                                {
                                    min.Y = v.Y;
                                }
                                if (v.Z < min.Z)
                                {
                                    min.Z = v.Z;
                                }

                                if (v.X > max.X)
                                {
                                    max.X = v.X;
                                }
                                if (v.Y > max.Y)
                                {
                                    max.Y = v.Y;
                                }
                                if (v.Z > max.Z)
                                {
                                    max.Z = v.Z;
                                }
                            }
                        }
                        finally
                        {
                            mesh.UnlockVertexBuffer();
                        }
                    }
                }

                if (min == max)
                {
                    max.X = min.X + 1;
                    max.Y = min.Y + 1;
                    max.Z = min.Z + 1;
                }

                ResetView(min, max);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace);
            }
        }
Ejemplo n.º 4
0
        void DoRender(NodeBox nbox, Matrix basem, int effectct)
        {
            MeshBox box = null;

            if (nbox is MeshBox)
            {
                box = (MeshBox)nbox;
            }

            if (box != null)
            {
                if (box.Wire)
                {
                    device.RenderState.FillMode = FillMode.WireFrame;
                }
                else
                {
                    device.RenderState.FillMode = FillMode.Solid;
                }

                device.Material = box.Material;
            }


            Matrix tr = Matrix.Multiply(nbox.Transform, basem);

            if (nbox.Transform.IsAbsolute)
            {
                tr = nbox.Transform;
            }
            device.Transform.World = tr;

            if (box != null)
            {
                if (effect != null && PrepareEffect != null && this.usefx)
                {
                    PrepareEffect(this, new PrepareEffectEventArgs(box));
                }

                for (int s = 0; s < effectct; s++)
                {
                    if (effect != null && this.usefx)
                    {
                        effect.BeginPass(s);
                    }
                    for (int i = 0; i < box.SubSetCount; i++)
                    {
                        box.Mesh.DrawSubset(i);
                    }
                    if (effect != null && this.usefx)
                    {
                        effect.EndPass();
                    }
                }
            }

            foreach (NodeBox cld in nbox)
            {
                DoRender(cld, tr, effectct);
            }
        }