Beispiel #1
0
        public override void LoadPage(PageInfo page)
        {
            //Calculate x/z indexes for the grid array
            page.XIndex -= (int)System.Math.Floor(mGridBounds.Left / mPageSize);
            page.ZIndex -= (int)System.Math.Floor(mGridBounds.Top / mPageSize);

            //Check if the requested page is in bounds
            if (page.XIndex < 0 || page.ZIndex < 0 || page.XIndex >= mPageGridX || page.ZIndex >= mPageGridZ)
            {
                return;
            }

            //For each tree type...
            foreach (KeyValuePair <Entity, List <List <TreeDef> > > it in mPageGridList)
            {
                //Get the appropriate tree list for the specified page
                List <List <TreeDef> > pageGrid = it.Value;
                List <TreeDef>         treeList = GetGridPage(pageGrid, page.XIndex, page.ZIndex);
                Entity entity = it.Key;

                //Load the listed trees into the page
                foreach (TreeDef o in treeList)
                {
                    //Get position
                    Vector3 pos = Vector3.Zero;
                    pos.x = page.Bounds.Left + ((float)o.XPos / 65535) * mPageSize;
                    pos.z = page.Bounds.Top + ((float)o.ZPos / 65535) * mPageSize;

                    //Calculate terrain height at pos.x / pos.z to get pos.y
                    if (mHeightFunction != null)
                    {
                        pos.y = mHeightFunction.GetHeightAt(pos.x, pos.z, mHeightFunctionUserData);
                    }
                    else
                    {
                        pos.y = 0.0f;
                    }

                    //Get rotation
                    Degree     angle = new Degree((Real)o.Rotation * (360.0f / 255));
                    Quaternion rot   = Quaternion.FromAngleAxis((float)angle.InRadians, Vector3.UnitY);

                    //Get scale
                    Vector3 scale = Vector3.Zero;
                    scale.y = (float)(o.Scale * (mMaximumScale / 255) + mMinimumScale);
                    scale.x = scale.y;
                    scale.z = scale.y;

                    //Get color
                    ColorEx col = ColorEx.White;
                    if (mColorMap != null)
                    {
                        col = mColorMap.GetColorAtUnpacked(pos.x, pos.z);
                    }

                    AddEntity(entity, pos, rot, scale, col);
                }
            }
        }