Exemplo n.º 1
0
                /// <summary>
                /// Draws a billboard in world space facing the +Z direction of the matrix specified. Units in meters, matrix
                /// transform notwithstanding.
                /// </summary>
                public void Draw(ref CroppedBox box, MatrixD[] matrixRef)
                {
                    FlatQuad quad = new FlatQuad()
                    {
                        Point0 = box.bounds.Max,
                        Point1 = new Vector2(box.bounds.Max.X, box.bounds.Min.Y),
                        Point2 = box.bounds.Min,
                        Point3 = new Vector2(box.bounds.Min.X, box.bounds.Max.Y),
                    };

                    if (skewRatio != 0f)
                    {
                        Vector2 start = quad.Point0, end = quad.Point3,
                                offset = (end - start) * skewRatio * .5f;

                        quad.Point0  = Vector2.Lerp(start, end, skewRatio) - offset;
                        quad.Point3  = Vector2.Lerp(start, end, 1f + skewRatio) - offset;
                        quad.Point1 -= offset;
                        quad.Point2 -= offset;
                    }

                    BillBoardUtils.AddQuad(ref quad, ref materialData, matrixRef, box.mask);
                }
Exemplo n.º 2
0
                /// <summary>
                /// Queues a quad billboard for rendering
                /// </summary>
                public static void AddQuad(ref FlatQuad quad, ref BoundedQuadMaterial mat, MatrixD[] matrixRef, BoundingBox2?mask = null)
                {
                    var bbPool     = instance.bbPoolBack;
                    var bbDataBack = instance.flatTriangleList;
                    var matList    = instance.matrixBuf;
                    var matTable   = instance.matrixTable;

                    // Find matrix index in table or add it
                    int matrixID;

                    if (!matTable.TryGetValue(matrixRef, out matrixID))
                    {
                        matrixID = matList.Count;
                        matList.Add(matrixRef[0]);
                        matTable.Add(matrixRef, matrixID);
                    }

                    // Mask bounding check. Null mask if not intersecting.
                    BoundingBox2?   maskBox     = mask;
                    ContainmentType containment = ContainmentType.Contains;

                    if (maskBox != null)
                    {
                        BoundingBox2 bounds = new BoundingBox2(quad.Point2, quad.Point0);
                        maskBox.Value.Contains(ref bounds, out containment);

                        if (containment == ContainmentType.Contains)
                        {
                            maskBox = null;
                        }
                    }

                    if (containment != ContainmentType.Disjoint)
                    {
                        int indexL = bbDataBack.Count,
                            indexR = bbDataBack.Count + 1;

                        var bbL = new FlatTriangleBillboardData
                        {
                            Item1 = BlendTypeEnum.PostPP,
                            Item2 = new Vector2I(bbDataBack.Count, matrixID),
                            Item3 = mat.textureID,
                            Item4 = new MyTuple <Vector4, BoundingBox2?>(mat.bbColor, maskBox),
                            Item5 = new MyTuple <Vector2, Vector2, Vector2>
                                    (
                                new Vector2(mat.texBounds.Max.X, mat.texBounds.Min.Y), // 1
                                mat.texBounds.Max,                                     // 0
                                new Vector2(mat.texBounds.Min.X, mat.texBounds.Max.Y)  // 3
                                    ),
                            Item6 = new MyTuple <Vector2, Vector2, Vector2>
                                    (
                                quad.Point0,
                                quad.Point1,
                                quad.Point2
                                    ),
                        };
                        var bbR = new FlatTriangleBillboardData
                        {
                            Item1 = BlendTypeEnum.PostPP,
                            Item2 = new Vector2I(bbDataBack.Count + 1, matrixID),
                            Item3 = mat.textureID,
                            Item4 = new MyTuple <Vector4, BoundingBox2?>(mat.bbColor, maskBox),
                            Item5 = new MyTuple <Vector2, Vector2, Vector2>
                                    (
                                new Vector2(mat.texBounds.Max.X, mat.texBounds.Min.Y), // 1
                                new Vector2(mat.texBounds.Min.X, mat.texBounds.Max.Y), // 3
                                mat.texBounds.Min                                      // 2
                                    ),
                            Item6 = new MyTuple <Vector2, Vector2, Vector2>
                                    (
                                quad.Point0,
                                quad.Point2,
                                quad.Point3
                                    ),
                        };

                        bbDataBack.Add(bbL);
                        bbDataBack.Add(bbR);

                        if (indexR >= bbPool.Count)
                        {
                            instance.AddNewBB(indexR - (bbPool.Count - 1));
                        }

                        MyTransparentGeometry.AddBillboard(bbPool[indexL], false);
                        MyTransparentGeometry.AddBillboard(bbPool[indexR], false);
                    }
                }