Example #1
0
    void PointEdit()
    {
        RaycastHit hit;

        if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out hit, 5))
        {
            Chunk    chunk        = world.GetChunk(hit.point);
            HexCoord hexUnrounded = chunk.PosToHex(hit.point);
            HexCell  hexCenter    = hexUnrounded.ToHexCell();
            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    for (int k = -1; k <= 1; k++)
                    {
                        HexCell hex              = new HexCell(hexCenter.x + i, hexCenter.y + j, hexCenter.z + k);
                        Vector3 point            = chunk.HexToPos(hex);
                        Vector3 c                = 2 * point - hexUnrounded.ToVector3();
                        float   distanceStrength = 10 / (Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2));
                        Vector3 changeNormal     = 10 * new Vector3(-2 * c.x / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2)),
                                                                    -2 * c.y / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2)),
                                                                    -2 * c.z / (Mathf.Pow(Mathf.Pow(c.x, 2) + Mathf.Pow(c.y, 2) + Mathf.Pow(c.z, 2), 2)));
                        chunk.EditPointValue(hex, distanceStrength);
                        chunk.EditPointNormal(hex, changeNormal);
                        gameObject.GetComponent <LoadChunks>().AddToUpdateList(chunk.chunkCoords);
                    }
                }
            }
        }
    }