Exemple #1
0
        /// <summary>
        /// Traverses the specified graph path</summary>
        /// <param name="graphPath">The graph path</param>
        /// <param name="action">The render action</param>
        /// <param name="camera">The camera</param>
        /// <param name="list">The list</param>
        /// <returns></returns>
        public override TraverseState Traverse(Stack<SceneNode> graphPath, IRenderAction action, Camera camera, ICollection<TraverseNode> list)
        {
            // Get the "top matrix" before we push a new matrix on to it, just in case we need
            //  it for the bounding box test.
            Matrix4F parentToWorld = action.TopMatrix;

            // Push matrix onto the matrix stack even if we're not visible because this class
            //  implements the marker interface ISetsLocalTransform.
            action.PushMatrix(m_node.Transform, true);

            // If node is invisible then cull
            if (!m_node.Visible)
                return TraverseState.Cull;

            TraverseState dResult = action.TraverseState;
            if (dResult == TraverseState.None)
            {
                // Test if bounding sphere is contained in frustum
                if (s_enableVFCull)
                {
                    // Construct bounding box
                    Box box = new Box();
                    box.Extend(m_node.BoundingBox);

                    // Transform the bounding box into view space
                    Matrix4F localToView = Matrix4F.Multiply(parentToWorld, camera.ViewMatrix);
                    box.Transform(localToView);

                    if (!camera.Frustum.Contains(box))
                        dResult = TraverseState.Cull;
                }
            }
            return dResult;
        }
Exemple #2
0
        private void TestToStringWithCulture(CultureInfo culture)
        {
            CultureInfo originalCulture = Thread.CurrentThread.CurrentCulture;
            Thread.CurrentThread.CurrentCulture = culture;
            try
            {
                string listSeparator = culture.TextInfo.ListSeparator;
                string decimalSeparator = culture.NumberFormat.NumberDecimalSeparator;
                var corner1 = new Vec3F(1.1f, 2.2f, 3.3f);
                var corner2 = new Vec3F(4.4f, 5.5f, 6.6f);
                var o = new Box(corner1, corner2);

                string s = o.ToString(null, null);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("G", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);

                s = o.ToString("R", culture);
                TestToStringResults(o, s, listSeparator, decimalSeparator);
            }
            finally
            {
                Thread.CurrentThread.CurrentCulture = originalCulture;
            }
        }
Exemple #3
0
        /// <summary>
        /// Calculates the bounding box for the instance</summary>
        /// <returns>Bounding box</returns>
        public Box CalculateBoundingBox()
        {
            Box box = new Box();

            foreach (IBoundable boundable in DomNode.Children.AsIEnumerable<IBoundable>())
                box.Extend(boundable.BoundingBox);

            return box;
        }
Exemple #4
0
        /// <summary>
        /// Calculates the bounding box for the instance</summary>
        /// <returns>Bounding box</returns>
        public Box CalculateBoundingBox()
        {
            Box box = new Box();

            foreach (IBoundable boundable in DomNode.Children.AsIEnumerable<IBoundable>())
                box.Extend(boundable.BoundingBox);

            //m_box.Transform(Transform); //Look at the schema -- "lodgroupType" does not have a transformation
            return box;
        }
Exemple #5
0
        /// <summary>
        /// Calculates bounding box of node's children</summary>
        /// <returns>Bounding box of children</returns>
        public Box CalculateBoundingBox()
        {
            var box = new Box();
            foreach (IBoundable boundable in DomNode.Children.AsIEnumerable<IBoundable>())
                box.Extend(boundable.BoundingBox);

            box.Transform(Transform);
            DomNodeUtil.SetBox(DomNode, Schema.nodeType.boundingBoxAttribute, box);

            return box;
        }
Exemple #6
0
 private void TestToStringResults(Box o, string s, string listSeparator, string decimalSeparator)
 {
     string[] results = s.Split(new[] { listSeparator }, StringSplitOptions.RemoveEmptyEntries);
     Assert.AreEqual(results.Length, 6);
     foreach (string oneFloatString in results)
         Assert.True(oneFloatString.Contains(decimalSeparator));
     Assert.AreEqual(float.Parse(results[0]), o.Min.X);
     Assert.AreEqual(float.Parse(results[1]), o.Min.Y);
     Assert.AreEqual(float.Parse(results[2]), o.Min.Z);
     Assert.AreEqual(float.Parse(results[3]), o.Max.X);
     Assert.AreEqual(float.Parse(results[4]), o.Max.Y);
     Assert.AreEqual(float.Parse(results[5]), o.Max.Z);
 }
Exemple #7
0
 /// <summary>
 /// Calculates the geometry's bounding box</summary>
 /// <returns>Bounding box for geometry</returns>
 public Box CalculateBoundingBox()
 {
     Box box = new Box();
     foreach (DataSet dataSet in DataSets)
     {
         if (dataSet.Name == "position")
         {
             box.Extend(dataSet.Data);
             break;
         }
     }
     DomNodeUtil.SetBox(DomNode, Schema.meshType.boundingBoxAttribute, box);
     return box;
 }
Exemple #8
0
 /// <summary>
 /// Sets the DomNode attribute value to the given Box</summary>
 /// <param name="domNode">DomNode holding value</param>
 /// <param name="attribute">Attribute of the DomNode that contains the data</param>
 /// <param name="b">Box</param>
 public static void SetBox(DomNode domNode, AttributeInfo attribute, Box b)
 {
     float[] value = new float[6];
     value[0] = b.Min.X;
     value[1] = b.Min.Y;
     value[2] = b.Min.Z;
     value[3] = b.Max.X;
     value[4] = b.Max.Y;
     value[5] = b.Max.Z;
     domNode.SetAttribute(attribute, value);
 }
Exemple #9
0
        private Box CalculateBoundingBox()
        {
            // compute box.
            var box = new Box();
            
            foreach (InstanceGeometry instGeom in GetChildList<InstanceGeometry>(Schema.node.instance_geometryChild))
            {                
                box.Extend(instGeom.Geometry.BoundingBox);
            }

            foreach (InstanceController instCtrl in GetChildList<InstanceController>(Schema.node.instance_controllerChild))
            {                
                box.Extend(instCtrl.Geometry.BoundingBox);
            }

            foreach (Node nd in GetChildList<Node>(Schema.node.nodeChild))
            {                
                box.Extend(nd.BoundingBox);
            }

            box.Transform(Transform);
            return box;
           
        }
Exemple #10
0
 /// <summary>
 /// Extends the box to contain the given box.
 /// If this box is currently uninitialized, sets this box to be the other box.</summary>
 /// <param name="other">The given box</param>
 /// <returns>The extended box</returns>
 public Box Extend(Box other)
 {
     if (!other.IsEmpty)
     {
         Extend(other.Min);
         Extend(other.Max);
     }
     return this;
 }
Exemple #11
0
        /// <summary>
        /// Tests if frustum contains any part of the given box. The frustum and the box must be in
        /// the same space. The frustum does not have to be symmetrical and could have been transformed
        /// into object space using Frustum.Transform().</summary>
        /// <param name="box">The box</param>
        /// <returns>True iff frustum contains the given box</returns>
        public bool Contains(Box box)
        {
            Vec3F center = (box.Min + box.Max) * 0.5f;
            Vec3F center_to_max = (box.Max - box.Min) * 0.5f;

            for (int i = 0; i < 6; i++)
            {
                // Compute the distance from the plane to the center. A negative distance means that
                // the center point is on the "out" side of the plane and is thus outside the frustum.
                float center_dist = m_planes[i].SignedDistance(center);

                // Now we need the distance to the plane that the nearest corner contributes.
                // Map the plane's normal to be in the positive octant along with 'center_to_max'.
                // Note that 'center_to_max' is guaranteed to have all 3 coordinates be positive
                // (because box.Max is greater than box.Min for all 3). To transform the plane's
                // normal, we simply take the absolute value of each coordinate. This plane's normal
                // must be unit length so that the distance is correct. 'nearest_corner_dist' is
                // always non-negative. (It could be zero if the box has zero size.)
                float nearest_corner_dist =
                    center_to_max.X * Math.Abs(m_planes[i].Normal.X) +
                    center_to_max.Y * Math.Abs(m_planes[i].Normal.Y) +
                    center_to_max.Z * Math.Abs(m_planes[i].Normal.Z);

                if (center_dist + nearest_corner_dist < 0)
                {
                    return false;
                }
            }

            // This is an approximation. It is possible that the box is still outside the frustum.
            return true;
        }
Exemple #12
0
        /// <summary>
        /// Extends sphere to enclose box</summary>
        /// <param name="box">Axis-aligned box to enclose</param>
        /// <returns>Extended sphere</returns>
        public Sphere3F Extend(Box box)
        {
            Sphere3F tmp = new Sphere3F((box.Max + box.Min) / 2.0f,
                (box.Max - box.Min).Length / 2.0f);

            Extend(tmp);

            return this;
        }
Exemple #13
0
 private Box CalculateBoundingBox()
 {            
     var box = new Box();
     foreach (PrimInput input in m_inputs)
     {
         if (input.Semantic == "POSITION")
         {
             box.Extend(input.Data);
             break;
         }
     }
     return box;
 }