public void AdjustTerrainHeight() { TerrainHeightMap heightMap = TerrainMeta.HeightMap; TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap; float single6 = 1f; float randomScale = this.RandomScale; float outerPadding = this.OuterPadding; float innerPadding = this.InnerPadding; float outerFade = this.OuterFade; float innerFade = this.InnerFade; float terrainOffset = this.TerrainOffset * TerrainMeta.OneOverSize.y; float width = this.Width * 0.5f; Vector3 startPoint = this.Path.GetStartPoint(); Vector3 endPoint = this.Path.GetEndPoint(); Vector3 startTangent = this.Path.GetStartTangent(); Vector3 vector32 = PathList.rot90 * startTangent; Vector3 vector33 = startPoint - (vector32 * (width + outerPadding + outerFade)); Vector3 vector34 = startPoint + (vector32 * (width + outerPadding + outerFade)); float length = this.Path.Length + single6; for (float i = 0f; i < length; i += single6) { Vector3 vector35 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i)); float single7 = (startPoint - vector35).Magnitude2D(); float single8 = (endPoint - vector35).Magnitude2D(); float single9 = Mathf.InverseLerp(0f, width, Mathf.Min(single7, single8)); float single10 = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector35.x, vector35.z, 2, 0.005f, 1f, 2f, 0.5f)); Vector3 vector36 = this.Path.GetTangent(i).XZ3D(); startTangent = vector36.normalized; vector32 = PathList.rot90 * startTangent; Ray ray = new Ray(vector35, startTangent); Vector3 vector37 = vector35 - (vector32 * (single10 + outerPadding + outerFade)); Vector3 vector38 = vector35 + (vector32 * (single10 + outerPadding + outerFade)); float single11 = TerrainMeta.NormalizeY(vector35.y); heightMap.ForEach(vector33, vector34, vector37, vector38, (int x, int z) => { float single = heightMap.Coordinate(x); float single1 = heightMap.Coordinate(z); if ((topologyMap.GetTopology(single, single1) & this.Topology) != 0) { return; } Vector3 vector3 = TerrainMeta.Denormalize(new Vector3(single, single11, single1)); Vector3 vector31 = ray.ClosestPoint(vector3); float single2 = (vector3 - vector31).Magnitude2D(); float single3 = Mathf.InverseLerp(single10 + outerPadding + outerFade, single10 + outerPadding, single2); float single4 = Mathf.InverseLerp(single10 - innerPadding, single10 - innerPadding - innerFade, single2); float single5 = TerrainMeta.NormalizeY(vector31.y); single3 = Mathf.SmoothStep(0f, 1f, single3); single4 = Mathf.SmoothStep(0f, 1f, single4); heightMap.SetHeight(x, z, single5 + terrainOffset * single4, single9 * single3); }); vector33 = vector37; vector34 = vector38; } }
public void AdjustTerrainTopology() { if (this.Topology == 0) { return; } TerrainTopologyMap topologyMap = TerrainMeta.TopologyMap; float single3 = 1f; float randomScale = this.RandomScale; float outerPadding = this.OuterPadding; float innerPadding = this.InnerPadding; float width = this.Width * 0.5f; Vector3 startPoint = this.Path.GetStartPoint(); Vector3 endPoint = this.Path.GetEndPoint(); Vector3 startTangent = this.Path.GetStartTangent(); Vector3 vector31 = PathList.rot90 * startTangent; Vector3 vector32 = startPoint - (vector31 * (width + outerPadding)); Vector3 vector33 = startPoint + (vector31 * (width + outerPadding)); float length = this.Path.Length + single3; for (float i = 0f; i < length; i += single3) { Vector3 vector34 = (this.Spline ? this.Path.GetPointCubicHermite(i) : this.Path.GetPoint(i)); float single4 = (startPoint - vector34).Magnitude2D(); float single5 = (endPoint - vector34).Magnitude2D(); float single6 = Mathf.InverseLerp(0f, width, Mathf.Min(single4, single5)); float single7 = Mathf.Lerp(width, width * randomScale, Noise.Billow(vector34.x, vector34.z, 2, 0.005f, 1f, 2f, 0.5f)); Vector3 vector35 = this.Path.GetTangent(i).XZ3D(); startTangent = vector35.normalized; vector31 = PathList.rot90 * startTangent; Ray ray = new Ray(vector34, startTangent); Vector3 vector36 = vector34 - (vector31 * (single7 + outerPadding)); Vector3 vector37 = vector34 + (vector31 * (single7 + outerPadding)); float single8 = TerrainMeta.NormalizeY(vector34.y); topologyMap.ForEach(vector32, vector33, vector36, vector37, (int x, int z) => { float single = topologyMap.Coordinate(x); float single1 = topologyMap.Coordinate(z); Vector3 vector3 = TerrainMeta.Denormalize(new Vector3(single, single8, single1)); float single2 = (vector3 - ray.ClosestPoint(vector3)).Magnitude2D(); if (Mathf.InverseLerp(single7 + outerPadding, single7 - innerPadding, single2) * single6 > 0.3f) { topologyMap.SetTopology(x, z, this.Topology); } }); vector32 = vector36; vector33 = vector37; } }
public Vector3 PositionOnRay(Vector3 position) { RaycastHit raycastHit; Ray ray = new Ray(this.PointStart, this.attackNormal); if (this.ProjectilePrefab == null) { return(ray.ClosestPoint(position)); } Sphere sphere = new Sphere(position, this.ProjectilePrefab.thickness); if (!sphere.Trace(ray, out raycastHit, Single.PositiveInfinity)) { return(position); } return(raycastHit.point); }
public static float ClosestDistance(this Ray ray, Vector3 position) { return(ray.ClosestPoint(position).magnitude); }
public void BackBufferControl_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (didCopy && (W32.Control.ModifierKeys & W32.Keys.Shift) != W32.Keys.Shift) didCopy = false; int lastSelection = selection; dragging = false; if (!enabledDragging) return; if (e.Button != MB.Left || P.CurrNode == null) { selection = -1; return; } Matrix m = P.CurrNode.Matrix; Vector3 po = P.CurrNode.Position; Quaternion q = P.CurrNode.Rotation; if (P.CoordSystem == eECoordinateSystem.eECoordinateSystem_Independent) { m = Matrix.Translation(po); q = Quaternion.Identity; } Vector3 d = ManagedWorld.NodeLibrary.Camera.Unproject(e.X, e.Y, ManagedSettings.FarDepth - 1, P.BackBuffer); Ray r1 = new Ray(ManagedWorld.NodeLibrary.Camera.Position_ABS, Vector3.Normalize(d - ManagedWorld.NodeLibrary.Camera.Position_ABS)); if (selection == -1) { Vector3 axisx = Vector3.Transform(Vector3.UnitX * scale, q).ToVec3(); Vector3 axisy = Vector3.Transform(Vector3.UnitY * scale, q).ToVec3(); Vector3 axisz = Vector3.Transform(Vector3.UnitZ * scale, q).ToVec3(); Vector2 o = ManagedWorld.NodeLibrary.Camera.Project(Vector3.Transform(Vector3.Zero, m).ToVec3(), P.BackBuffer); Vector2 p1 = ManagedWorld.NodeLibrary.Camera.Project(axisx + po, P.BackBuffer); Vector2 p2 = ManagedWorld.NodeLibrary.Camera.Project(axisy + po, P.BackBuffer); Vector2 p3 = ManagedWorld.NodeLibrary.Camera.Project(axisz + po, P.BackBuffer); Vector2 p2_xz = ManagedWorld.NodeLibrary.Camera.Project(po + axisx * s + axisz * s, P.BackBuffer); Vector2 p2_yz = ManagedWorld.NodeLibrary.Camera.Project(po + axisy * s + axisz * s, P.BackBuffer); Vector2 p2_yx = ManagedWorld.NodeLibrary.Camera.Project(po + axisx * s + axisy * s, P.BackBuffer); bool x = isNear(o, p1, e.X, e.Y); bool y = isNear(o, p2, e.X, e.Y); bool z = isNear(o, p3, e.X, e.Y); bool[] bb = CheckAreas(Vector3.Transform(Vector3.Zero, m).ToVec3(), axisx, axisy, axisz, new Vector3(e.X, e.Y, 0), r1); if (bb[0] || bb[1] || bb[2]) x = y = z = false; int SAT = Convert.ToInt32(x) + Convert.ToInt32(y) + Convert.ToInt32(z) + Convert.ToInt32(bb[0]) + Convert.ToInt32(bb[1]) + Convert.ToInt32(bb[2]); if(SAT == 0 || SAT > 1) return; if (x) selection = 0; if (y) selection = 1; if (z) selection = 2; if (bb[0]) selection = 3; if (bb[1]) selection = 4; if (bb[2]) selection = 5; } if (selection < 3) { Vector3 v = new Vector3(); if (selection == 0) v = Vector3.UnitX; if (selection == 1) v = Vector3.UnitY; if (selection == 2) v = Vector3.UnitZ; v = Vector3.Transform(v, q).ToVec3(); Ray r2 = new Ray(po, v); Vector3? hit = r2.ClosestPoint(r1); float s0 = (hit.Value - P.CurrNode.Position).Length(); float fk = calcDist(P.CurrNode.Position, v); if (!hit.HasValue || s0 > scale) { //selection = -1; return; } if (lastSelection == -1 && s0 > fk) { dragging = true; return; } float t = (hit.Value[selection] - r2.Position[selection]) / r2.Direction[selection]; if ((W32.Control.ModifierKeys & W32.Keys.Shift) == W32.Keys.Shift && !didCopy) { didCopy = true; P.CurrNode = (ILrentObject)P.CurrNode.Clone(P.GetCopyFile(P.CurrNode.File), P.Device); } if (s0 < fk) P.CurrNode.Position = hit.Value; else P.CurrNode.Position += r2.Direction * fk * (float)Math.Sign(t); dragging = true; } else { Vector3 n = new Vector3(); if (selection == 3) n = Vector3.UnitY; if (selection == 4) n = Vector3.UnitX; if (selection == 5) n = Vector3.UnitZ; n = Vector3.Transform(n, q).ToVec3(); Plane p = new Plane(po, n); float? fq = r1.Intersects(p); if (!fq.HasValue) return; Vector3 hit = r1.Position + r1.Direction * fq.Value; P.CurrNode.Position = hit; dragging = true; } }