예제 #1
0
        public void BuildBox(ModelInstance modelInstance)
        {
            Min = new Vector3(float.MaxValue, float.MaxValue, float.MaxValue);
            Max = new Vector3(float.MinValue, float.MinValue, float.MinValue);

            // build the transformation matrix
            var scale              = Matrix.CreateScale(modelInstance.Scale);
            var rotate             = Matrix.CreateFromQuaternion(new Quaternion(modelInstance.Frame.Orientation.X, modelInstance.Frame.Orientation.Y, modelInstance.Frame.Orientation.Z, modelInstance.Frame.Orientation.W));
            var cellTranslate      = Matrix.CreateTranslation(new Vector3(modelInstance.Cell.X * Landblock.CellSize, modelInstance.Cell.Y * Landblock.CellSize, 0));
            var cellTranslateInner = Matrix.CreateTranslation(new Vector3(modelInstance.Position.X, modelInstance.Position.Y, modelInstance.Position.Z));

            var transform = scale * rotate * cellTranslate * cellTranslateInner;

            foreach (var gfxObj in modelInstance.StaticMesh.GfxObjs)
            {
                foreach (var v in gfxObj.VertexArray.Vertices.Values)
                {
                    var vertex = Vector3.Transform(new Vector3(v.X, v.Y, v.Z), transform);

                    if (vertex.X < Min.X)
                    {
                        Min.X = vertex.X;
                    }
                    if (vertex.Y < Min.Y)
                    {
                        Min.Y = vertex.Y;
                    }
                    if (vertex.Z < Min.Z)
                    {
                        Min.Z = vertex.Z;
                    }

                    if (vertex.X > Max.X)
                    {
                        Max.X = vertex.X;
                    }
                    if (vertex.Y > Max.Y)
                    {
                        Max.Y = vertex.Y;
                    }
                    if (vertex.Z > Max.Z)
                    {
                        Max.Z = vertex.Z;
                    }
                }
            }

            GetSize();
        }
예제 #2
0
 public BoundingBox(ModelInstance modelInstance)
 {
     ModelInstance = modelInstance;
     BuildBox(modelInstance);
 }