コード例 #1
0
ファイル: TerrainField3.cs プロジェクト: abarabone/a
    public void adjustHeights(SimpleTerrainOperator op)
    {
        var m = new FieldManipulator(min, max, op.fieldUnitR, op.fieldLength);

        var hs = m.getHeights(op.td);

        var tofs = new Vector3(op.terrainPosition.x, op.terrainPositionHeight, op.terrainPosition.y);

        for (var iy = 0; iy < m.len.y; iy++)
        {
            for (var ix = 0; ix < m.len.x; ix++)
            {
                var pos = m.getIterationPosition3d(ix, iy, op.fieldUnit) + tofs;

                var start = pos + Vector3.up * 512.0f;
                var end   = pos + Vector3.down * 512.0f;

                var ray = new Ray(start, end - start);
                var res = new RaycastHit();
                if (mc.Raycast(ray, out res, 1024.0f))
                {
                    hs[iy, ix] = (res.point.y - op.terrainPositionHeight) * op.fieldUnitHeightR;
                }
            }
        }

        m.setHeights(op.td, hs);
    }
コード例 #2
0
ファイル: TerrainField3.cs プロジェクト: abarabone/a
    public void adjustHeights(SimpleTerrainOperator op)
    {
        var sqrradiusR = 1.0f / sqrradius;

        var impactSqrradiusR = impact * sqrradiusR;

        var edgeFactor = sradius.x * (1.0f / 20.0f) * sqrradiusR;


        for (var iy = 0; iy < hm.len.y; iy++)
        {
            for (var ix = 0; ix < hm.len.x; ix++)
            // 地形ローカル空間で処理
            {
                var height = hs[iy, ix] * op.fieldUnitHeight;

                var pos = hm.getIterationPosition3d(ix, iy, op.fieldUnit, height);

                var spos = new Vector2(pos.x, pos.z);

                if (false && height > centerHeight)
                {
                    var sqrsdist = (spos - scenter).sqrMagnitude;

                    if (sqrsdist <= sqrradius)
                    {
                        var hith = centerHeight - (sqrradius - sqrsdist) * impactSqrradiusR;

                        hs[iy, ix] = Mathf.Lerp(hith, height, sqrsdist * sqrradiusR) * op.fieldUnitHeightR;
                    }
                }
                else
                {
                    if ((pos - center).sqrMagnitude <= sqrradius)
                    {
                        var sqrsdist = (spos - scenter).sqrMagnitude;

                        var hith = centerHeight - (sqrradius - sqrsdist) * impactSqrradiusR;

                        hs[iy, ix] = (hith < height? hith + sqrsdist * edgeFactor : height) * op.fieldUnitHeightR;
                    }
                }
            }
        }

        hm.setHeights(op.td, hs);
    }