Beispiel #1
0
    //TODO: Split into different files

    private void OnMouseUp()
    {
        Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);

        RaycastHit hit;

        if (Physics.Raycast(ray, out hit))
        {
            Transform objectHit = hit.transform;

            //Instantiate ( this.Cube, hit.point, Quaternion.identity );
            var point = hit.point;
            Debug.Log(point.y + ", " + (point.y - 0.2f * point.y));
            if (point.y > 1.4 && point.y < 1.93)
            {
                point.y -= 0.1f * point.y;
            }
            if (point.y > 1.93)
            {
                point.y -= 0.18f * point.y;
            }
            Vector3 p = new Vector3(point.x, point.y, point.z);


            SphericalCoord cs = CoordHelper.TransformToSphericalCoord(p, this.transform.position);

            Vector2 uv = CoordHelper.SphericalToUV(cs);

            ReadFromMap(uv);
        }
    }
Beispiel #2
0
    void FixedUpdate()
    {
        string s = "";

        s += string.Format("TRANSFORM (SPACE):            {0}\n", TargetObject.position);
        SphericalCoord sphereCoord = CoordHelper.TransformToSphericalCoord(TargetObject.position, ParentObject.position);

        s += string.Format("SPHERICAL COORDINATES:   {0}\n", sphereCoord.ToString());
        Vector2 uvCoord = CoordHelper.SphericalToUV(sphereCoord);

        s        += string.Format("UV COORDINATES:                    {0}\n", uvCoord.ToString());
        text.text = s;
    }
    void Update()
    {
        string s = "";

        s += string.Format("Transform: {0}\n", TargetObject.position);

        SphericalCoord sphereCoord = CoordHelper.TransformToSphericalCoord(TargetObject.position, ParentObject.position);

        s += string.Format("Spherical Coordinates: {0}\n", sphereCoord.ToString());

        Vector2 uvCoord = CoordHelper.SphericalToUV(sphereCoord);

        s += string.Format("Texture UV: {0}\n", uvCoord.ToString());

        text.text = s;
    }
Beispiel #4
0
    public void SwitchToTerrain()
    {
        if (isTerrain)
        {
            Debug.LogError("Already in terrain mode.");
            return;
        }

        // We are in space mode, but have to switch to terrain mode.
        isTerrain = true;

        // What are the coordinates of the ship relative to the planetoid
        SphericalCoord sphereCoord = CoordHelper.TransformToSphericalCoord(TheShip.position, ThePlanetoid.transform.position);
        string         s           = string.Format("Landing ship at coordinates: {0}\n", sphereCoord.ToString());

        Debug.Log(s);

        ThePlanetoid.SetActive(false);
        TheTerrain.SetActive(true);

        // NOTE: This will freeze the game for a few seconds depending on processor speed.
        // Consider solutions like CoRoutines or Threading.
        TheTerrain.GetComponent <DynamicTerrainMaster>().BuildFromLandingSpot(sphereCoord);

        // Now that the terrain exists, move the ship to be in the same reference system.
        // Rotate the ship -90 around the X axis
        TheShip.transform.RotateAround(Vector3.zero, Vector3.right, -90);

        Vector3 pos          = TheShip.transform.position;
        float   planetRadius = ThePlanetoid.transform.localScale.x / 2f; // Pick any one axis of the scale

        // Subtract the radius of the planetoid
        pos = pos.normalized * (pos.magnitude - planetRadius);

        // In space, 1 unit = 1km. On ground, 1 unit = 1m. So mult scales/distance by 1000.
        TheShip.transform.position = pos * 1000f;
        Vector3 scale = TheShip.transform.localScale * 1000f;

        TheShip.transform.localScale = scale;
    }