示例#1
0
        private void DrawEdges(Mesh m, Effect effect, Matrix world, Matrix view, Matrix projection)
        {
            foreach (var edge in m.HalfEdges.Where(a => a.Primary))
            {
                var start = edge.Twin.End.Position;
                var end   = edge.End.Position;

                Vector3 position   = start * 0.5f + end * 0.5f;
                Vector3 difference = end - start;

                float  length = difference.Length();
                Matrix scale  = Matrix.CreateScale(new Vector3(0.2f, length, 0.2f));

                difference.Normalize();
                Matrix  rotation = Matrix.Identity;
                Vector3 axis     = Vector3.Cross(Vector3.Up, difference);
                if (axis != Vector3.Zero)
                {
                    axis.Normalize();
                    float angle = (float)Math.Acos(Vector3.Dot(Vector3.Up, difference));
                    rotation = Matrix.CreateFromAxisAngle(axis, (float.IsNaN(angle) ? 0 : angle));
                }

                Matrix myWorld = scale * rotation * Matrix.CreateTranslation(position) * world;

                effect.Parameters["World"].SetValue(myWorld);
                effect.Parameters["WorldViewProj"].SetValue(myWorld * view * projection);
                if (effect.Parameters["DiffuseColor"] != null)
                {
                    effect.Parameters["DiffuseColor"].SetValue(Color.Green.ToVector4());
                }

                cylinder.Draw(effect);
            }
        }
示例#2
0
        public static void DrawHitPoly()
        {
            if (HitVertices == null)
            {
                return;
            }

            if (PickResult.PhysicsObj?.IsDestroyed ?? false)
            {
                ClearSelection();
                return;
            }

            var rs = new RasterizerState();

            rs.CullMode = Microsoft.Xna.Framework.Graphics.CullMode.None;
            rs.FillMode = FillMode.WireFrame;
            GraphicsDevice.RasterizerState = rs;

            if (SphereTransforms == null && CylinderTransforms == null && PhysicsVertices == null)
            {
                Effect.CurrentTechnique = Effect.Techniques["Picker"];

                foreach (var pass in Effect.CurrentTechnique.Passes)
                {
                    pass.Apply();
                    GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, HitVertices, 0, HitVertices.Length, HitIndices, 0, HitIndices.Length / 2);
                }
            }
            else
            {
                if (SphereTransforms != null)
                {
                    foreach (var sphereTransform in SphereTransforms)
                    {
                        SpherePrimitive.Draw(sphereTransform, Camera.ViewMatrix, Camera.ProjectionMatrix, Color.Orange);
                    }
                }

                if (CylinderTransforms != null)
                {
                    foreach (var cylinderTransform in CylinderTransforms)
                    {
                        CylinderPrimitive.Draw(cylinderTransform, Camera.ViewMatrix, Camera.ProjectionMatrix, Color.Orange);
                    }
                }

                if (PhysicsVertices != null)
                {
                    Effect.CurrentTechnique = Effect.Techniques["Picker"];

                    foreach (var pass in Effect.CurrentTechnique.Passes)
                    {
                        pass.Apply();
                        GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, PhysicsVertices, 0, PhysicsVertices.Length, PhysicsIndices, 0, PhysicsIndices.Length / 2);
                    }
                }
            }

            if (RenderLinks != null)
            {
                if (!RenderLinks.Head.WorldObject.PhysicsObj.IsDestroyed)
                {
                    RenderLinks.Draw();
                }
                else
                {
                    RenderLinks.Dispose();
                    RenderLinks = null;
                }
            }
        }
示例#3
0
 public override void Draw(GameTime gameTime, Matrix world, Camera camera, Vector3 light1Position, Vector3 light2Position)
 {
     world = GetWorldMatrix(world);
     base.Draw(gameTime, world, camera, light1Position, light2Position);
     _cylinder.Draw(world, Color, camera, light1Position, light2Position, Texture, Options);
 }