예제 #1
0
        static Vector2?GetPointInPlane(Context.Branch branch, Camera camera, Vector3 sphereToCamera)
        {
            Vector3 direction;
            float   denominator;

            if (sphereToCamera.sqrMagnitude == 0f)
            {
                // Camera is at the center of the object.
                direction   = branch.up;
                denominator = 1f;
            }
            else
            {
                direction   = sphereToCamera.normalized;
                denominator = Vector3.Dot(branch.up, direction);

                if (denominator <= 0f)
                {
                    // Camera is in opposite hemisphere.
                    return(null);
                }
            }

            Vector3 pointOnPlane = direction / denominator;
            Vector2 pointInPlane = new Vector2(Vector3.Dot(branch.forward, pointOnPlane), Vector3.Dot(branch.right, pointOnPlane));

            if (pointInPlane.x < -1f || 1f < pointInPlane.x || pointInPlane.y < -1f || 1f < pointInPlane.y)
            {
                return(null);
            }

            return(pointInPlane);
        }
예제 #2
0
파일: Node.cs 프로젝트: woutervh-/planets
        public static Node CreateRoot(Context.Constants constants, Context.Depth depth, Context.Branch branch)
        {
            GameObject gameObject = new GameObject("Chunk");

            gameObject.transform.SetParent(branch.gameObject.transform, false);
            MeshFilter   meshFilter   = gameObject.AddComponent <MeshFilter>();
            MeshRenderer meshRenderer = gameObject.AddComponent <MeshRenderer>();

            meshRenderer.enabled        = false;
            meshRenderer.sharedMaterial = constants.material;

            int[]   path = new int[0];
            int[]   neighborBranches;
            int[][] neighborPaths;
            GetNeighborPaths(path, branch.index, out neighborBranches, out neighborPaths);

            return(new Node
            {
                parent = null,
                children = null,
                path = path,
                neighborBranches = neighborBranches,
                neighborPaths = neighborPaths,
                branch = branch,
                depth = depth,
                offset = Vector2.zero,
                gameObject = gameObject,
                mesh = null,
                meshFilter = meshFilter,
                meshRenderer = meshRenderer,
                meshRequest = null,
                meshRequestCancellation = null
            });
        }