Exemple #1
0
 public Vertex(Convex c, Vertex v)
 {
     Convex = c;
     Pos = v.Pos;
     VertIndices = new List<int>(v.VertIndices);
     EdgeIndices = new List<int>(v.EdgeIndices);
 }
Exemple #2
0
 public Vertex(Convex c, Vertex v)
 {
     Convex      = c;
     Pos         = v.Pos;
     VertIndices = new List <int>(v.VertIndices);
     EdgeIndices = new List <int>(v.EdgeIndices);
 }
        public void ConvexTestRandom()
        {
            var points = Enumerable.Repeat(0, 200).Select(_ => (f3)UR.insideUnitSphere).ToList();
            var convex = new Convex(points);

            convex.ExpandLoop();

            int itr = 0;

            while (itr < int.MaxValue)
            {
                itr++;
                var f = convex.Expand();
                if (!f)
                {
                    break;
                }
            }

            foreach (var n in convex.nodes)
            {
                Assert.IsTrue(n.neighbors.Count == 3);
            }

            foreach (var p in points)
            {
                Assert.IsTrue(convex.Contains(p));
            }
        }
Exemple #4
0
 public override void renderImage(RenderInfo info)
 {
     if (LeftNode != null)
     {
         Convex c = new Convex(Vector.Zero, 0, new VectorSet(
                                   LeftNode.Position,
                                   Position,
                                   new Vector(Position.X, Floor),
                                   new Vector(LeftNode.Position.X, Floor)));
         Color waterColor = new Color(.3f, .05f, .5f, .6f);
         c.renderWhenReady(info.GraphicsDevice, info.Transform, new RenderHints().setColor(waterColor).setPrimitiveType(PrimitiveType.TriangleStrip));
         //	GameManager.Log.debug("Hello from renderer");
     }
     //
 }
Exemple #5
0
            public static void Split2d(Convex convex, Point3D point0, int edge0, Point3D point1, int edge1, ref Convex newcvxa, ref Convex newcvxb)
            {
                newcvxa = new Convex();
                newcvxb = new Convex();

                Face facea = new Face(newcvxa);
                Face faceb = new Face(newcvxb);

                newcvxa.Faces.Add(facea);
                newcvxb.Faces.Add(faceb);

                int edgecount = convex.Edges.Count;

                List <int> usedindicesa = new List <int>();
                List <int> usedindicesb = new List <int>();


                newcvxa.Vertices.Add(new Vertex(newcvxa, point0));
                for (int i = edge0; i != edge1; i = (i + 1) % edgecount)
                {
                    usedindicesa.Add(convex.Edges[i].VertIndices[1]);
                    newcvxa.Vertices.Add(new Vertex(newcvxa, convex.GetEdgeVert(i, 1)));
                }
                newcvxa.Vertices.Add(new Vertex(newcvxa, point1));

                newcvxb.Vertices.Add(new Vertex(newcvxb, point1));
                for (int i = edge1; i != edge0; i = (i + 1) % edgecount)
                {
                    usedindicesb.Add(convex.Edges[i].VertIndices[1]);
                    newcvxb.Vertices.Add(new Vertex(newcvxb, convex.GetEdgeVert(i, 1)));
                }
                newcvxb.Vertices.Add(new Vertex(newcvxb, point0));

                facea.VertIndices = new int[newcvxa.Vertices.Count];
                faceb.VertIndices = new int[newcvxb.Vertices.Count];

                for (int i = 0; i < facea.VertIndices.Length; i++)
                {
                    facea.VertIndices[i] = i;
                }
                for (int i = 0; i < faceb.VertIndices.Length; i++)
                {
                    faceb.VertIndices[i] = i;
                }

                newcvxa.BuildFromVertsAndFaces();
                newcvxb.BuildFromVertsAndFaces();
            }
        public void ConvexTestStatic()
        {
            List <f3> sample1 = new List <f3> {
                new f3(0, 0, 0),
                new f3(1, 0, 0),
                new f3(0, 1, 0),
                new f3(0, 0, 1),
            };
            var c = new Convex(sample1);

            Assert.IsTrue(c.Contains(new f3(0.1f, 0.1f, 0.1f)));
            Assert.IsTrue(c.Contains(new f3(0, 0, 0)));
            Assert.IsTrue(c.Contains(new f3(1, 0, 0)));
            Assert.IsTrue(c.Contains(new f3(0, 1, 0)));
            Assert.IsTrue(c.Contains(new f3(0, 0, 1)));
            Assert.IsFalse(c.Contains(new f3(2.0f, 0.1f, 0.1f)));
        }
Exemple #7
0
            public override void Create()
            {
                Convex cvx = new Convex();

                cvx.Is3d = false;

                cvx.Vertices.Add(new Vertex(cvx, -Size.X * 0.5, -Size.Y * 0.5));
                cvx.Vertices.Add(new Vertex(cvx, -Size.X * 0.5, Size.Y * 0.5));
                cvx.Vertices.Add(new Vertex(cvx, Size.X * 0.5, Size.Y * 0.5));
                cvx.Vertices.Add(new Vertex(cvx, Size.X * 0.5, -Size.Y * 0.5));

                cvx.Faces.Add(new Face(cvx, 0, 1, 2, 3));

                cvx.BuildFromVertsAndFaces();

                Convexes.Add(cvx);
            }
Exemple #8
0
            public Convex Copy()
            {
                Convex cvx = new Convex();

                foreach (Vertex v in Vertices)
                {
                    cvx.Vertices.Add(new Vertex(cvx, v));
                }
                foreach (Edge v in Edges)
                {
                    cvx.Edges.Add(new Edge(cvx, v));
                }
                foreach (Face v in Faces)
                {
                    cvx.Faces.Add(new Face(cvx, v));
                }
                return(cvx);
            }
Exemple #9
0
        public Convex[] BuildConvex()
        {
            var num    = ConvexNum;
            var result = new Convex[num];
            var pc     = new IntPtr[num];

            for (UInt32 i = 0; i < num; i++)
            {
                result[i] = new Convex();
                pc[i]     = result[i].CoreObject;
            }
            unsafe
            {
                fixed(IntPtr *ppConvex = &pc[0])
                {
                    SDK_SimGeom_BuildConvex(CoreObject, ppConvex, num);
                }
            }
            return(result);
        }
Exemple #10
0
 public static bool DoConvexesOverlap2d(Convex a, Convex b)
 {
     foreach (Edge e in b.Edges)
     {
         Vector3D norm       = b.GetEdgeNormal2d(e);
         Vector3D edgeoffset = (Vector3D)b.GetEdgeVertPos(e, 0);
         double   mind       = 999999999;
         foreach (Vertex v in a.Vertices)
         {
             Vector3D vertoffset = (Vector3D)v.Pos;
             double   d          = Vector3D.DotProduct(vertoffset, norm) - Vector3D.DotProduct(edgeoffset, norm);
             mind = d < mind ? d : mind;
         }
         if (mind >= 0)
         {
             return(false);
         }
     }
     foreach (Edge e in a.Edges)
     {
         Vector3D norm       = a.GetEdgeNormal2d(e);
         Vector3D edgeoffset = (Vector3D)a.GetEdgeVertPos(e, 0);
         double   mind       = 999999999;
         foreach (Vertex v in b.Vertices)
         {
             Vector3D vertoffset = (Vector3D)v.Pos;
             double   d          = Vector3D.DotProduct(vertoffset, norm) - Vector3D.DotProduct(edgeoffset, norm);
             mind = d < mind ? d : mind;
         }
         if (mind >= 0)
         {
             return(false);
         }
     }
     return(true);
 }
Exemple #11
0
 public Edge(Convex c, int a, int b)
 {
     Convex         = c;
     VertIndices[0] = a;
     VertIndices[1] = b;
 }
Exemple #12
0
            public static bool CalculateClippedConvexes2d(Convex a, Convex b, List <Convex> a_only, ref Convex overlap)
            {
                if (!DoConvexesOverlap2d(a, b))
                {
                    a_only.Add(a);
                    overlap = null;
                    return(false);
                }

                overlap = a.Copy();

                Point3D hp0, hp1;
                int     hedge0, hedge1;
                double  ht0, ht1;

                hp0    = new Point3D();
                hp1    = new Point3D();
                hedge0 = hedge1 = -1;
                ht0    = ht1 = 0;

                bool any_split = false;

                foreach (Edge bedge in b.Edges)
                {
                    Point3D  raystart = b.Vertices[bedge.VertIndices[0]].Pos;
                    Vector3D raydir   = b.Vertices[bedge.VertIndices[1]].Pos - raystart;

                    if (!CSGScene.NextStage("Test convex"))
                    {
                        break;
                    }

                    if (CSGScene.IsCurrentStage())
                    {
                        if (CSGScene.DebugLines != null)
                        {
                            overlap.DebugDraw();
                            CSGScene.DebugLines.AddLine(raystart - raydir * 10, raystart + raydir * 10);
                        }
                    }

                    if (overlap.RayIntersect2d(raystart, raydir, ref hp0, ref hedge0, ref ht0, ref hp1, ref hedge1, ref ht1))
                    {
                        if (!CSGScene.NextStage("Splitting convex"))
                        {
                            break;
                        }

                        if (CSGScene.IsCurrentStage())
                        {
                            if (CSGScene.DebugLines != null)
                            {
                                CSGScene.DebugLines.AddLine(raystart - raydir * 10, raystart + raydir * 10);
                            }
                        }

                        //CSGScene.DebugLines.AddCross(hp0, 1);
                        //CSGScene.DebugLines.AddCross(hp1, 1);
                        //CSGScene.DebugLines.AddLine(hp0, hp1);
                        Convex newa, newb;
                        newa = newb = null;
                        Split2d(overlap, hp0, hedge0, hp1, hedge1, ref newa, ref newb);

                        Vector3D rayorth = new Vector3D(-raydir.Y, raydir.X, 0);
                        if (Vector3D.DotProduct(rayorth, newa.GetCentre() - raystart) < 0)
                        {
                            a_only.Add(newb);
                            overlap = newa;
                        }
                        else if (Vector3D.DotProduct(rayorth, newb.GetCentre() - raystart) < 0)
                        {
                            a_only.Add(newa);
                            overlap = newb;
                        }
                        else
                        {
                            throw new System.ApplicationException("Double degerate or something!");
                        }
                        any_split = true;

                        if (CSGScene.IsCurrentStage())
                        {
                            if (CSGScene.DebugLines != null)
                            {
                                foreach (Convex newaonly in a_only)
                                {
                                    newaonly.DebugDraw();
                                }
                                overlap.DebugDraw();
                            }
                        }
                    }
                }

                if (!any_split)
                {
                    a_only.Add(overlap);
                    overlap = null;
                }
                return(any_split);
            }
Exemple #13
0
 public Vertex(Convex c, double x, double y, double z)
 {
     Convex = c;
     Pos = new Point3D(x, y, z);
 }
Exemple #14
0
 public Face(Convex c, params int[] verts)
 {
     Convex = c;
     VertIndices = verts;
 }
Exemple #15
0
 public Face(Convex c, Face e)
 {
     Convex      = c;
     VertIndices = e.VertIndices.ToArray();
     EdgeIndices = e.EdgeIndices.ToArray();
 }
        public void renderAll(List <GameObject> gobs, List <InstanceDescriptor> insts)
        {
            //get width and height of window
            int bbWidth  = GraphicsDevice.PresentationParameters.BackBufferWidth;
            int bbHeight = GraphicsDevice.PresentationParameters.BackBufferHeight;

            //initialize bloom component
            if (bloomComponent == null)
            {
                bloomComponent = new BloomComponent(GraphicsDevice, WhiskeyControl.Content);
                bloomComponent.loadContent();
                bloomComponent.Settings = BloomSettings.PresetSettings[0];
            }
            if (lightBloomComponent == null)
            {
                lightBloomComponent = new BloomComponent(GraphicsDevice, WhiskeyControl.Content);
                lightBloomComponent.loadContent();
                lightBloomComponent.Settings = BloomSettings.PresetSettings[5];
            }

            //load bloom settings
            if (Level.BloomSettings != null)
            {
                bloomComponent.Settings = Level.BloomSettings;
            }

            if (Level.LightBloomSettings != null)
            {
                lightBloomComponent.Settings = Level.LightBloomSettings;
            }


            //ensure render targets are correctly sized
            hudTarget          = checkRenderTarget(hudTarget, bbWidth, bbHeight);
            lightMapTarget     = checkRenderTarget(lightMapTarget, bbWidth, bbHeight);
            sceneTarget        = checkRenderTarget(sceneTarget, bbWidth, bbHeight);
            hudObjectsTarget   = checkRenderTarget(hudObjectsTarget, 1280, 720);
            layerScreenShader  = checkRenderTarget(layerScreenShader, bbWidth, bbHeight);
            currentLayerTarget = checkRenderTarget(currentLayerTarget, bbWidth, bbHeight);
            //get game objects, and ui gameobjects
            List <GameObject> uiGameObjects = new List <GameObject>();
            List <GameObject> gobsToRender  = new List <GameObject>();

            gobs.ForEach(g => uiGameObjects.Add(g));
            insts.Where(g => !g.HudObject).ToList().ForEach(g => gobsToRender.Add(g));

            //DRAW HUD
            renderHud();
            //draw light radius
            gobsToRender.ForEach(g => {
                if (g.Light.Visible)
                {
                    Convex convex = new Convex(g.Position, 0, VectorSet.Dodecahedren * (g.Light.Radius / 2));
                    convex.render(GraphicsDevice, CameraTransform, new RenderHints().setColor(Level.BackgroundColor.Inverted));
                }
            });


            //DRAW GAME OBJECTS


            // bloomComponent.BeginDraw();

            render(gobsToRender);

            bloomComponent.BeginDraw();
            GraphicsDevice.Clear(Level.BackgroundColor);

            spriteBatch.Begin();
            spriteBatch.Draw(layerScreenShader, Vector.Zero, XnaColor.White);
            spriteBatch.End();

            bloomComponent.draw();


            //DRAW LIGHTMAP
            renderLightMap(gobs, insts.Where(g => !g.HudObject).ToList());

            //DRAW SCENE WITH LIGHTMAP
            GraphicsDevice.SetRenderTarget(null);
            GraphicsDevice.Textures[1] = lightMapTarget;
            Vector4 ambience = ((XnaColor)Level.AmbientLight).ToVector4();

            lightEffect.Parameters["ambience"].SetValue(ambience);
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, Level.PreviewLighting ? lightEffect : null);
            spriteBatch.Draw(bloomComponent.OutputTarget, Vector.Zero, XnaColor.White);
            spriteBatch.End();

            //DRAW HUD
            spriteBatch.Begin();
            spriteBatch.Draw(hudTarget, Vector.Zero, XnaColor.White);
            spriteBatch.End();
        }
Exemple #17
0
            public override void Create()
            {
                if (Is3d)
                {
                }
                else
                {
                    //this'll be the clever algorithm. it takes advantage of the fact that we always maintain:
                    //- for any given node, none of it's child convexes overlap
                    //therefore:
                    //- no node should test it's own convexes against each other



                    //this is the simplest algorithm - we assume every convex could potentially overlap every other convex
                    //and keep iterating until no more splits occur. it works, but involves a lot of unnecessary overlap tests
                    Convexes = new List <Convex>();
                    foreach (Node n in Children)
                    {
                        Convexes.AddRange(n.Convexes.Select(a => a.Copy()));
                    }

                    //draw all initial convexes if this is the current stage
                    if (!CSGScene.NextStage("Begin union"))
                    {
                        foreach (Convex c in Convexes)
                        {
                            c.DebugDraw();
                        }
                        return;
                    }

                    //now do the iterative splitting
                    //loop until no splits done
                    bool done_split = true;
                    while (done_split)
                    {
                        //spin over every convex
                        done_split = false;
                        for (int i = 0; i < Convexes.Count; i++)
                        {
                            //go over every other convex
                            for (int j = i + 1; j < Convexes.Count; j++)
                            {
                                //get the 2 convexes to compare
                                Convex acvx = Convexes[i];
                                Convex bcvx = Convexes[j];

                                //do a clip test
                                List <Convex> otherconvexsplit = new List <Convex>();
                                Convex        overlap          = null;
                                if (Convex.CalculateClippedConvexes2d(acvx, bcvx, otherconvexsplit, ref overlap))
                                {
                                    //got a split, so remove the convex that was split (cvx a), and re-add the sections
                                    //that didn't overlap
                                    Convexes.RemoveAt(i);
                                    Convexes.AddRange(otherconvexsplit);
                                    done_split = true;

                                    //if last stage, draw the convex we were splitting and then bail
                                    if (!CSGScene.NextStage("Done a split"))
                                    {
                                        return;
                                    }
                                    break;
                                }
                            }

                            //break out (so we iterate round again) if a split happened
                            if (done_split)
                            {
                                break;
                            }
                        }
                    }
                }
            }
Exemple #18
0
 public Vertex(Convex c, Point3D pos)
 {
     Convex = c;
     Pos = pos;
 }
Exemple #19
0
        private void renderLayers()
        {
            GraphicsDevice.SetRenderTarget(layerScreenShader);
            GraphicsDevice.Clear(XnaColor.Transparent);

            foreach (Layer layer in Level.Layers)
            {
                if (!layer.Visible)
                {
                    continue;
                }


                string     shaderMode = layer.ShaderMode;
                BlendState blendState = BlendModeConverter.getState(layer.BlendMode);
                if (shaderMode != Layer.DEFAULT_SHADER_MODE && shaderMode != null)
                {
                    Effect fx = GameManager.Resources.loadEffect(shaderMode);
                    layer.setEffect(fx);
                }
                else
                {
                    layer.setEffect(null);
                }

                string postShaderMode = layer.PostShaderMode;
                if (postShaderMode != Layer.DEFAULT_SHADER_MODE && postShaderMode != null)
                {
                    layer.setPostEffect(GameManager.Resources.loadEffect(postShaderMode));
                }
                else
                {
                    layer.setPostEffect(null);
                }

                Effect layerEffect = layer.getEffect();
                Effect post        = layer.getPostEffect();

                Level.ShaderParameters.updateEffect(layerEffect);
                Level.ShaderParameters.updateEffect(post);


                GraphicsDevice.SetRenderTarget(currentLayerTarget);

                GraphicsDevice.Clear(XnaColor.Transparent);


                if (layer.ScreenShader)
                {
                    spriteBatch.Begin(SpriteSortMode.FrontToBack, blendState, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, layerEffect);
                    spriteBatch.Draw(bloomComponent.SceneTarget, Vector.Zero, XnaColor.White);
                    spriteBatch.End();
                }
                else
                {
                    spriteBatch.Begin(SpriteSortMode.FrontToBack, blendState, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, layerEffect, CameraTransform);

                    List <GameObject> allGobs = GameManager.Objects.getAllObjects();
                    Convex.begin();
                    foreach (GameObject gob in allGobs.Where(g => g.Active && !g.HudObject && g.Layer.Name.Equals(layer.Name)))
                    {
                        gob.renderImage(RenderInfo);
                    }


                    spriteBatch.End();

                    //  RenderTarget2D primTarget = checkRenderTarget(null, GraphicsDevice.PresentationParameters.BackBufferWidth, GraphicsDevice.PresentationParameters.BackBufferHeight);
                    //  GraphicsDevice.SetRenderTarget(primTarget);
                    BlendState bs = BlendState.AlphaBlend;

                    GraphicsDevice.BlendState = bs;
                    PrimitiveBatch.getInstance(GraphicsDevice).CurrentLayer = layer;
                    Convex.readyToBeDrawn.ForEach(c =>
                    {
                        c.Convex.render(c.GraphcisDevice, c.Transform, c.Hints);
                    });
                    // GraphicsDevice.SetRenderTarget(currentLayerTarget);
                    // spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, null);
                    // spriteBatch.Draw(primTarget, Vector.Zero, XnaColor.White);
                    // spriteBatch.End();
                }

                GraphicsDevice.SetRenderTarget(layerScreenShader);

                spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.NonPremultiplied, SamplerState.LinearWrap, DepthStencilState.Default, RasterizerState.CullNone, post);
                spriteBatch.Draw(currentLayerTarget, Vector.Zero, XnaColor.White);
                spriteBatch.End();
            }
        }
Exemple #20
0
 public Convex Copy()
 {
     Convex cvx = new Convex();
     foreach (Vertex v in Vertices) cvx.Vertices.Add(new Vertex(cvx,v));
     foreach (Edge v in Edges) cvx.Edges.Add(new Edge(cvx,v));
     foreach (Face v in Faces) cvx.Faces.Add(new Face(cvx,v));
     return cvx;
 }
Exemple #21
0
            public static bool CalculateClippedConvexes2d(Convex a, Convex b, List<Convex> a_only, ref Convex overlap)
            {
                if (!DoConvexesOverlap2d(a, b))
                {
                    a_only.Add(a);
                    overlap = null;
                    return false;
                }

                overlap = a.Copy();

                Point3D hp0, hp1;
                int hedge0, hedge1;
                double ht0, ht1;
                hp0 = new Point3D();
                hp1 = new Point3D();
                hedge0 = hedge1 = -1;
                ht0 = ht1 = 0;

                bool any_split = false;
                foreach (Edge bedge in b.Edges)
                {
                    Point3D raystart = b.Vertices[bedge.VertIndices[0]].Pos;
                    Vector3D raydir = b.Vertices[bedge.VertIndices[1]].Pos - raystart;

                    if (!CSGScene.NextStage("Test convex"))
                        break;

                    if (CSGScene.IsCurrentStage())
                    {
                        if (CSGScene.DebugLines != null)
                        {
                            overlap.DebugDraw();
                            CSGScene.DebugLines.AddLine(raystart - raydir * 10, raystart + raydir * 10);
                        }
                    }
                    
                    if (overlap.RayIntersect2d(raystart, raydir, ref hp0, ref hedge0, ref ht0, ref hp1, ref hedge1, ref ht1))
                    {
                        if (!CSGScene.NextStage("Splitting convex"))
                            break;

                        if (CSGScene.IsCurrentStage())
                            if (CSGScene.DebugLines != null)
                                CSGScene.DebugLines.AddLine(raystart - raydir * 10, raystart + raydir * 10);

                        //CSGScene.DebugLines.AddCross(hp0, 1);
                        //CSGScene.DebugLines.AddCross(hp1, 1);
                        //CSGScene.DebugLines.AddLine(hp0, hp1);
                        Convex newa, newb;
                        newa = newb = null;
                        Split2d(overlap, hp0, hedge0, hp1, hedge1, ref newa, ref newb);

                        Vector3D rayorth = new Vector3D(-raydir.Y, raydir.X, 0);
                        if (Vector3D.DotProduct(rayorth, newa.GetCentre() - raystart) < 0)
                        {
                            a_only.Add(newb);
                            overlap = newa;
                        }
                        else if (Vector3D.DotProduct(rayorth, newb.GetCentre() - raystart) < 0)
                        {
                            a_only.Add(newa);
                            overlap = newb;
                        }
                        else
                        {
                            throw new System.ApplicationException("Double degerate or something!");
                        }
                        any_split = true;

                        if (CSGScene.IsCurrentStage())
                        {
                            if (CSGScene.DebugLines != null)
                            {
                                foreach(Convex newaonly in a_only)
                                    newaonly.DebugDraw();
                                overlap.DebugDraw();
                            }
                        }
                    }
                }

                if (!any_split)
                {
                    a_only.Add(overlap);
                    overlap = null;
                }
                return any_split;
            }
Exemple #22
0
 public Edge(Convex c, int a, int b)
 {
     Convex = c;
     VertIndices[0] = a;
     VertIndices[1] = b;
 }
Exemple #23
0
 public Face(Convex c, Face e)
 {
     Convex = c;
     VertIndices = e.VertIndices.ToArray();
     EdgeIndices = e.EdgeIndices.ToArray();
 }
Exemple #24
0
 public Edge(Convex c, Edge e)
 {
     Convex = c;
     e.VertIndices.CopyTo(VertIndices, 0);
     e.FaceIndices.CopyTo(FaceIndices, 0);
 }
Exemple #25
0
 public Vertex(Convex c, double x, double y, double z)
 {
     Convex = c;
     Pos    = new Point3D(x, y, z);
 }
Exemple #26
0
 public Face(Convex c, params int[] verts)
 {
     Convex      = c;
     VertIndices = verts;
 }
Exemple #27
0
 public static bool DoConvexesOverlap2d(Convex a, Convex b)
 {
     foreach (Edge e in b.Edges)
     {
         Vector3D norm = b.GetEdgeNormal2d(e);
         Vector3D edgeoffset = (Vector3D)b.GetEdgeVertPos(e, 0);
         double mind = 999999999;
         foreach (Vertex v in a.Vertices)
         {
             Vector3D vertoffset = (Vector3D)v.Pos;
             double d = Vector3D.DotProduct(vertoffset, norm) - Vector3D.DotProduct(edgeoffset, norm);
             mind = d < mind ? d : mind;
         }
         if (mind >= 0)
             return false;
     }
     foreach (Edge e in a.Edges)
     {
         Vector3D norm = a.GetEdgeNormal2d(e);
         Vector3D edgeoffset = (Vector3D)a.GetEdgeVertPos(e, 0);
         double mind = 999999999;
         foreach (Vertex v in b.Vertices)
         {
             Vector3D vertoffset = (Vector3D)v.Pos;
             double d = Vector3D.DotProduct(vertoffset, norm) - Vector3D.DotProduct(edgeoffset, norm);
             mind = d < mind ? d : mind;
         }
         if (mind >= 0)
             return false;
     }
     return true;
 }
Exemple #28
0
            public static void Split2d(Convex convex, Point3D point0, int edge0, Point3D point1, int edge1, ref Convex newcvxa, ref Convex newcvxb)
            {
                newcvxa = new Convex();
                newcvxb = new Convex();

                Face facea = new Face(newcvxa);
                Face faceb = new Face(newcvxb);
                newcvxa.Faces.Add(facea);
                newcvxb.Faces.Add(faceb);

                int edgecount = convex.Edges.Count;

                List<int> usedindicesa = new List<int>();
                List<int> usedindicesb = new List<int>();


                newcvxa.Vertices.Add(new Vertex(newcvxa,point0));
                for (int i = edge0; i != edge1; i = (i + 1) % edgecount)
                {
                    usedindicesa.Add(convex.Edges[i].VertIndices[1]);
                    newcvxa.Vertices.Add(new Vertex(newcvxa,convex.GetEdgeVert(i, 1)));
                }
                newcvxa.Vertices.Add(new Vertex(newcvxa,point1));

                newcvxb.Vertices.Add(new Vertex(newcvxb,point1));
                for (int i = edge1; i != edge0; i = (i + 1) % edgecount)
                {
                    usedindicesb.Add(convex.Edges[i].VertIndices[1]);
                    newcvxb.Vertices.Add(new Vertex(newcvxb,convex.GetEdgeVert(i, 1)));
                }
                newcvxb.Vertices.Add(new Vertex(newcvxb,point0));

                facea.VertIndices = new int[newcvxa.Vertices.Count];
                faceb.VertIndices = new int[newcvxb.Vertices.Count];

                for (int i = 0; i < facea.VertIndices.Length; i++) 
                    facea.VertIndices[i] = i;
                for (int i = 0; i < faceb.VertIndices.Length; i++)
                    faceb.VertIndices[i] = i;

                newcvxa.BuildFromVertsAndFaces();
                newcvxb.BuildFromVertsAndFaces();
            }
Exemple #29
0
 public Vertex(Convex c, Point3D pos)
 {
     Convex = c;
     Pos    = pos;
 }
        public void renderLightMap(List <GameObject> gobs, List <InstanceDescriptor> insts)
        {
            ConvexHull.InitializeStaticMembers(GraphicsDevice);

            EffectParameter widthParameter  = lightEffect.Parameters["screenWidth"];
            EffectParameter heightParameter = lightEffect.Parameters["screenHeight"];


            setShaderValue(widthParameter, lightMapTarget.Width);
            setShaderValue(heightParameter, lightMapTarget.Height);


            GraphicsDevice.SetRenderTarget(lightMapTarget);

            GraphicsDevice.Clear(XnaColor.Transparent);

            insts.ForEach(i =>
            {
                if (i.Light.Visible)
                {
                    ClearAlphaToOne();


                    GraphicsDevice.RasterizerState = RasterizerState.CullNone;
                    GraphicsDevice.BlendState      = CustomBlendStates.MultiplyShadows;

                    //shadowing algorithm taken from http://www.catalinzima.com/xna/samples/dynamic-2d-shadows/
                    if (Level.PreviewShadowing)
                    {
                        insts.ForEach(hull =>
                        {
                            if (hull.Shadows.CastsShadows)
                            {
                                Boolean pass = hull != i;
                                if (i.Shadows.SelfShadows)
                                {
                                    pass = true;
                                }

                                if (pass)
                                {
                                    Convex convex   = hull.Bounds.Convex;
                                    convex.Origin   = hull.Position;
                                    convex.Rotation = hull.Sprite.Rotation;

                                    ConvexHull convexHull = new ConvexHull(convex, WhiskeyColor.White);
                                    convexHull.DrawShadows(i.Light, CameraTransform, hull.Shadows.IncludeLight, hull.Shadows.Solidness, hull.Shadows.Height);
                                }
                            }
                        });
                    }


                    spriteBatch.Begin(SpriteSortMode.Immediate, CustomBlendStates.MultiplyWithAlpha, SamplerState.LinearClamp, DepthStencilState.Default, RasterizerState.CullNone, null, CameraTransform);
                    i.renderLight(RenderInfo);
                    spriteBatch.End();
                }
            });
            ClearAlphaToOne();


            lightBloomComponent.BeginDraw();
            GraphicsDevice.Clear(XnaColor.Transparent);
            spriteBatch.Begin();
            spriteBatch.Draw(lightMapTarget, Vector.Zero, null, XnaColor.White);
            spriteBatch.End();
            lightBloomComponent.draw();
            lightMapTarget = lightBloomComponent.OutputTarget;
        }
Exemple #31
0
 public Edge(Convex c, Edge e)
 {
     Convex = c;
     e.VertIndices.CopyTo(VertIndices, 0);
     e.FaceIndices.CopyTo(FaceIndices,0);
 }