Ejemplo n.º 1
0
    protected void RenewMeshPosition(Vector2 vec)
    {
        transform.Translate(vec.x * JOYSTICKRATE, 0, vec.y * JOYSTICKRATE);
        int xn = (int)Mathf.Round(transform.position.x / PLOTX);
        int zn = (int)Mathf.Round(transform.position.z / PLOTZ);

        if (xn == 0 && zn == 0)
        {
            return;
        }
        transform.Translate(-xn * PLOTX, 0, -zn * PLOTZ);
        centerx = Tool_Math.Fit(centerx - xn, shownumber / 2, MAPSIZE - shownumber / 2);
        centerz = Tool_Math.Fit(centerz - zn, shownumber / 2, MAPSIZE - shownumber / 2);
        RenewMesh();
    }
Ejemplo n.º 2
0
 protected override void RenewPoints()
 {
     Vector3[,] npoints = new Vector3[shownumber, shownumber];
     Vector3[,] nspeeds = new Vector3[shownumber, shownumber];
     for (int i = 0; i < shownumber; i++)
     {
         for (int j = 0; j < shownumber; j++)
         {
             int     x      = centerx - shownumber / 2 + i;
             int     z      = centerz - shownumber / 2 + j;
             Vector3 npoint = relatives[x, z];
             Vector3 nspeed = speeds[x, z];
             Vector3 force  = -npoint * K_ORIGIN;
             if (x == 0 || x == MAPSIZE - 1 || z == 0 || z == MAPSIZE - 1)
             {
                 continue;
             }
             int[] connected_x;
             if (z % 2 == 0)
             {
                 connected_x = new int[6] {
                     x - 1, x + 1, x, x + 1, x, x + 1
                 }
             }
             ;
             else
             {
                 connected_x = new int[6] {
                     x - 1, x + 1, x, x - 1, x, x - 1
                 }
             };
             int[] connected_z = new int[6] {
                 z, z, z + 1, z + 1, z - 1, z - 1
             };
             for (int k = 0; k < 6; k++)
             {
                 Vector3 dir = relatives[connected_x[k], connected_z[k]] - npoint;
                 force += dir * (Tool_Math.Length(dir) - restlengths[k]) * K_CONNECTED;
             }
             nspeed += force;
             float nspeedl = Tool_Math.Length(nspeed);
             if (nspeedl > SPEED_LIMIT)
             {
                 nspeed /= nspeedl / SPEED_LIMIT;
             }
             npoint       += nspeed;
             npoints[i, j] = npoint;
             nspeeds[i, j] = nspeed;
         }
     }
     for (int i = 0; i < shownumber; i++)
     {
         for (int j = 0; j < shownumber; j++)
         {
             int x = centerx - shownumber / 2 + i;
             int z = centerz - shownumber / 2 + j;
             relatives[x, z] = npoints[i, j];
             speeds[x, z]    = nspeeds[i, j];
         }
     }
     RenewMesh();
 }