Esempio n. 1
0
        /// <summary>
        /// Sets position, scale and rotation of tree obj to match given pTargetTree
        /// </summary>
        private static void SetRefTreeObjTransform(ref CRefTree pRefTree, CTree pTargetTree, int pAngleOffset)
        {
            Vector3 arrayCenter = CProjectData.GetArrayCenter();
            float   minHeight   = CProjectData.GetMinHeight();

            //float treeHeight = pTargetTree.peak.maxHeight.Y - (float)groundHeight;
            float treeHeight  = pTargetTree.GetTreeHeight();
            float heightRatio = treeHeight / pRefTree.GetTreeHeight();

            pRefTree.Obj.Scale = heightRatio * Vector3.One;

            //align position to tree
            pRefTree.Obj.Position    = pTargetTree.peak.Center;
            pRefTree.Obj.Position.Z -= pRefTree.GetTreeHeight() * heightRatio;

            //move obj so it is at 0,0,0
            pRefTree.Obj.Position -= arrayCenter;
            pRefTree.Obj.Position -= Vector3.UnitZ * minHeight;

            pRefTree.Obj.Rotation = new Vector3(0, -pAngleOffset, 0);

            //in OBJ format Y = height
            CUtils.SwapYZ(ref pRefTree.Obj.Position);
        }