コード例 #1
0
    public float GetGenerationWeight(Planet.SubdivisionData data)
    {
        var weight = GetSizeOnScreen(data);

        lastGenerationWeight = weight;
        return(weight);
    }
コード例 #2
0
    private float GetSizeOnScreen(Planet.SubdivisionData data)
    {
        var myPos            = rangePosToCalculateScreenSizeOn.CenterPos + planet.transform.position;
        var distanceToCamera = Vector3.Distance(myPos, data.pos);

        // TODO: this is world space, doesnt take into consideration rotation, not good,
        // but we dont care about rotation, we want to have correct detail even if we are looking at chunk from side?
        var sphere           = rangePosToCalculateScreenSizeOn.ToBoundingSphere();
        var radiusWorldSpace = sphere.radius;
        var fov = data.fieldOfView;
        var cot = 1.0f / Mathf.Tan(fov / 2f * Mathf.Deg2Rad);
        var radiusCameraSpace = radiusWorldSpace * cot / distanceToCamera;

        return(radiusCameraSpace);
    }