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); }
public FieldAdjusterForRoadMesh(MeshCollider mc, SimpleTerrainOperator op) { min = new Vector2(mc.bounds.min.x, mc.bounds.min.z) - op.terrainPosition; max = new Vector2(mc.bounds.max.x, mc.bounds.max.z) - op.terrainPosition; this.mc = mc; tofs = new Vector3(op.terrainPosition.x, op.terrainPositionHeight, op.terrainPosition.y); }
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); }
public void adjustHeights(SimpleTerrainOperator op) { }
public FieldAdjusterForExplosionShpere(Vector3 center, float radius, float impact, SimpleTerrainOperator op) { sqrradius = radius * radius; sradius = new Vector2(radius, radius); scenter = new Vector2(center.x, center.z) - op.terrainPosition; centerHeight = center.y - op.terrainPositionHeight; this.center = new Vector3(scenter.x, centerHeight, scenter.y); min = scenter - sradius; max = scenter + sradius; this.impact = impact; hm = new FieldManipulator(min, max, op.fieldUnitR, op.fieldLength); hs = hm.getHeights(op.td); }