IEnumerator Fall(float delay, CurvySpline spline) { print("now falling"); yield return(new WaitForSeconds(delay)); Vector3 targetPosition = new Vector3(transform.position.x, lastPos.y + 50.0f, transform.position.z); //AxKDebugLines.AddFancySphere (targetPosition, 1.0f, Color.blue, 0.0f); //AxKDebugLines.AddFancySphere (lastPos, 1.0f, Color.red, 0.0f); //AxKDebugLines.AddFancySphere ( new Vector3(lastPos.x, lastPos.y + 5.0f, lastPos.z) , 1.0f, Color.green, 0.0f); //AxKDebugLines.AddFancySphere (transform.position, 1.0f, Color.magenta, 0.0f); print("now rising above"); while (transform.position.y < targetPosition.y - 1.0f) { transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((targetPosition - transform.position).normalized, new Vector3(0, 1, 0)), Time.deltaTime); } print("now landing to spline"); Vector3 splineForward = spline.GetTangent(t); while (transform.position.y > lastPos.y + 10.0f) { transform.position = Vector3.Lerp(transform.position, lastPos, Time.deltaTime); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(splineForward), Time.deltaTime); } print("now done"); Camera.main.GetComponent <CameraController_three> ().falling = false; }
/// <summary> /// Gets the normalized tangent for a certain TF /// </summary> /// <param name="tf">TF value identifying position in the group (0..1)</param> /// <returns>a tangent vector</returns> public override Vector3 GetTangent(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return((spl) ? spl.GetTangent(localTF) : Vector3.zero); }
/// <summary> /// Gets the normalized tangent for a certain TF /// </summary> /// <param name="tf">TF value identifying position in the group (0..1)</param> /// <returns>a tangent vector</returns> public override UnityEngine.Vector3 GetTangent(float tf) { float localTF; CurvySpline spl = TFToSpline(tf, out localTF); return(spl.GetTangent(localTF)); }
void DoFindPoint() { if (!mSpline.IsInitialized || SourcePoint.IsNone) { return; } if (StoreTF.IsNone && StorePosition.IsNone && StoreUpVector.IsNone && StoreRotation.IsNone && StoreTangent.IsNone) { return; } Vector3 pos = (Space == Space.Self) ? SourcePoint.Value : mSpline.transform.InverseTransformPoint(SourcePoint.Value); float _tf = mSpline.GetNearestPointTF(pos); if (StoreTF.IsNone == false) { StoreTF.Value = _tf; } if (StorePosition.IsNone == false) { StorePosition.Value = (Space == Space.Self) ? mSpline.Interpolate(_tf) : mSpline.transform.TransformPoint(mSpline.Interpolate(_tf)); } if (StoreTangent.IsNone == false) { StoreTangent.Value = (Space == Space.Self) ? mSpline.GetTangent(_tf) : mSpline.transform.TransformDirection(mSpline.GetTangent(_tf)); } if (StoreUpVector.IsNone == false) { StoreUpVector.Value = (Space == Space.Self) ? mSpline.GetOrientationUpFast(_tf) : mSpline.transform.TransformDirection(mSpline.GetOrientationUpFast(_tf)); } if (StoreRotation.IsNone == false) { if (Space == Space.Self) { StoreRotation.Value = (StoreUpVector.IsNone) ? mSpline.GetOrientationFast(_tf) : Quaternion.LookRotation(mSpline.GetTangent(_tf), StoreUpVector.Value); } else { StoreRotation.Value = Quaternion.LookRotation(mSpline.transform.TransformDirection(mSpline.GetTangent(_tf)), mSpline.transform.TransformDirection(mSpline.GetOrientationUpFast(_tf))); } } }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline) { if (!init && spline.IsInitialized) { init = true; } if (!init) { return; } if (!Camera.main.GetComponent <CameraController_three> ().CUbool&& !wasdDone) { //player.GetComponentInChildren<MakeMesh> (true).enabled = true; MakeTextGO("TO MOVE HOLD DOWN WASD"); //0-17 before "W" wasdDone = true; } if (Input.GetKeyDown(KeyCode.W) && !wPressed) { SwapCharGO(' ', 14); // replace W with a space wPressed = true; } if (Input.GetKeyDown(KeyCode.A) && !aPressed) { SwapCharGO(' ', 15); aPressed = true; } if (Input.GetKeyDown(KeyCode.S) && !sPressed) { SwapCharGO(' ', 16); sPressed = true; } if (Input.GetKeyDown(KeyCode.D) && !dPressed) { SwapCharGO(' ', 17); dPressed = true; } // conditionals for which words to show if (wPressed && sPressed && aPressed && dPressed && !wasdCleared) { Clear(); wasdCleared = true; } if (player.GetComponent <ThirdPersonCharacter> ().SeenGun() && !qDone && wasdCleared) //must evade intro wide with gun in view { MakeTextGO("PRESS Q TO PICKUP"); qDone = true; } if (player.GetComponent <ThirdPersonCharacter> ().m_pickup == true && !mouseAimDone) { MakeTextGO("PRESS LEFT MOUSE DOWN TO AIM"); mouseAimDone = true; } if (player.GetComponent <ThirdPersonCharacter> ().m_doneAim == true && !mouseFireDone) { MakeTextGO("RELEASE LEFT MOUSE TO FIRE"); mouseFireDone = true; //StartCoroutine (Fade (4.0f)); //do on fireFlag below } if (player.GetComponent <ThirdPersonCharacter> ().m_fireFlag == true & !fireCleared) { Clear(); fireCleared = true; } float t = spline.GetNearestPointTF(player.transform.position); //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta); Vector3 splineUp = spline.GetRotatedUpFast(t, 0); Vector3 splineForward = spline.GetTangent(t); Vector3 splineRight = Vector3.Cross(splineUp, splineForward); //Vector3 rise = splineRight * offset.x + splineUp * offset.y + splineForward * offset.z; Vector3 lookPosition = Camera.main.transform.position; //Vector3 targetPosition = player.transform.position + player.transform.right * 0.8f * textLength / 4 + player.transform.up * 4.0f - player.transform.forward * 3.0f; Vector3 targetPosition = spline.Interpolate(t) + splineRight * 0.8f * textLength / 3 + splineUp * 4.0f - splineForward * 3.0f; //AxKDebugLines.AddSphere (lookPosition, .1f, Color.red); //AxKDebugLines.AddSphere (targetPosition, .1f, Color.blue); transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth); }
protected CGData GetSplineData(CurvySpline spline, bool fullPath, CGDataRequestRasterization raster, CGDataRequestMetaCGOptions options) { if (spline == null || spline.Count == 0) return null; List<ControlPointOption> optionsSegs = new List<ControlPointOption>(); int materialID = 0; float maxStep = float.MaxValue; var data = (fullPath) ? new CGPath() : new CGShape(); // calc start & end point (distance) float startDist; float endDist; getRange(spline, raster, out startDist, out endDist); float stepDist = (endDist - startDist) / (raster.Resolution - 1); data.Length = endDist - startDist; // initialize with start TF float tf = spline.DistanceToTF(startDist); float startTF = tf; float endTF = (endDist > spline.Length && spline.Closed) ? spline.DistanceToTF(endDist - spline.Length) + 1 : spline.DistanceToTF(endDist); // Set properties data.SourceIsManaged = IsManagedResource(spline); data.Closed = spline.Closed; data.Seamless = spline.Closed && raster.Length == 1; if (data.Length == 0) return data; // Scan input spline and fetch a list of control points that provide special options (Hard Edge, MaterialID etc...) if (options) optionsSegs = CGUtility.GetControlPointsWithOptions(options, spline, startDist, endDist, raster.Mode == CGDataRequestRasterization.ModeEnum.Optimized, out materialID, out maxStep); // Setup vars List<SamplePointUData> extendedUVData = new List<SamplePointUData>(); List<Vector3> pos = new List<Vector3>(); List<float> relF = new List<float>(); List<float> sourceF = new List<float>(); List<Vector3> tan = new List<Vector3>(); List<Vector3> up = new List<Vector3>(); float curDist = startDist; Vector3 curPos; float curF; Vector3 curTan = Vector3.zero; Vector3 curUp = Vector3.zero; List<int> softEdges = new List<int>(); int dead = 100000; raster.Resolution = Mathf.Max(raster.Resolution, 2); switch (raster.Mode) { case CGDataRequestRasterization.ModeEnum.Even: #region --- Even --- // we advance the spline using a fixed distance bool dupe = false; // we have at least one Material Group SamplePointsMaterialGroup grp = new SamplePointsMaterialGroup(materialID); // and at least one patch within that group SamplePointsPatch patch = new SamplePointsPatch(0); var clampMode=(data.Closed) ? CurvyClamping.Loop : CurvyClamping.Clamp; while (curDist <= endDist && --dead>0) { tf = spline.DistanceToTF(spline.ClampDistance(curDist, clampMode)); curPos = spline.Interpolate(tf); curF = (curDist-startDist) / data.Length;//curDist / endDist; if (Mathf.Approximately(1, curF)) curF = 1; pos.Add(curPos); relF.Add(curF); sourceF.Add(curDist / spline.Length); if (fullPath) // add path values { curTan = spline.GetTangent(tf,curPos); curUp = spline.GetOrientationUpFast(tf); tan.Add(curTan); up.Add(curUp); } if (dupe) // HardEdge, IncludeCP, MaterialID changes etc. need an extra vertex { pos.Add(curPos); relF.Add(curF); sourceF.Add(curDist / spline.Length); if (fullPath) { tan.Add(curTan); up.Add(curUp); } dupe = false; } // Advance curDist += stepDist; // Check next Sample Point's options. If the next point would be past a CP with options if (optionsSegs.Count > 0 && curDist >= optionsSegs[0].Distance) { if (optionsSegs[0].UVEdge || optionsSegs[0].UVShift) extendedUVData.Add(new SamplePointUData(pos.Count, optionsSegs[0].UVEdge,optionsSegs[0].FirstU, optionsSegs[0].SecondU)); // clamp point at CP and maybe duplicate the next sample point curDist = optionsSegs[0].Distance; dupe = optionsSegs[0].HardEdge || optionsSegs[0].MaterialID != grp.MaterialID || (options.CheckExtendedUV && optionsSegs[0].UVEdge); // end the current patch... if (dupe) { patch.End = pos.Count; grp.Patches.Add(patch); // if MaterialID changes, we start a new MaterialGroup if (grp.MaterialID != optionsSegs[0].MaterialID) { data.MaterialGroups.Add(grp); grp = new SamplePointsMaterialGroup(optionsSegs[0].MaterialID); } // in any case we start a new patch patch = new SamplePointsPatch(pos.Count + 1); if (!optionsSegs[0].HardEdge) softEdges.Add(pos.Count + 1); // Extended UV if (optionsSegs[0].UVEdge || optionsSegs[0].UVShift) extendedUVData.Add(new SamplePointUData(pos.Count + 1, optionsSegs[0].UVEdge, optionsSegs[0].FirstU, optionsSegs[0].SecondU)); } // and remove the CP from the options optionsSegs.RemoveAt(0); } // Ensure last sample point position is at the desired end distance if (curDist > endDist && curF < 1) // next loop curF will be 1 curDist = endDist; } if (dead<= 0) Debug.LogError("[Curvy] He's dead, Jim! Deadloop in SplineInputModuleBase.GetSplineData (Even)! Please send a bug report!"); // store the last open patch patch.End = pos.Count - 1; grp.Patches.Add(patch); // ExplicitU on last Vertex? //if (optionsSegs.Count > 0 && optionsSegs[0].UVShift) // extendedUVData.Add(new SamplePointUData(pos.Count - 1, optionsSegs[0].UVEdge, optionsSegs[0].FirstU, optionsSegs[0].SecondU)); // if path is closed and no hard edges involved, we need to smooth first normal if (data.Closed && !spline[0].GetMetadata<MetaCGOptions>(true).HardEdge) softEdges.Add(0); data.MaterialGroups.Add(grp); // fill data data.SourceF = sourceF.ToArray(); data.F = relF.ToArray(); data.Position = pos.ToArray(); if (fullPath) { ((CGPath)data).Direction = tan.ToArray(); data.Normal = up.ToArray(); } #endregion break; case CGDataRequestRasterization.ModeEnum.Optimized: #region --- Optimized --- dupe = false; // we have at least one Material Group grp = new SamplePointsMaterialGroup(materialID); // and at least one patch within that group patch = new SamplePointsPatch(0); float stepSizeTF = stepDist / spline.Length; float maxAngle = raster.AngleThreshold; float stopAt; bool atStopPoint; curPos = spline.Interpolate(tf); curTan = spline.GetTangent(tf, curPos); var addPoint = new System.Action<float>((float f) => { sourceF.Add(curDist/spline.Length); pos.Add(curPos); relF.Add((curDist -startDist) / data.Length); if (fullPath) { tan.Add(curTan); up.Add(spline.GetOrientationUpFast(f)); } }); while (tf < endTF && dead-- > 0) { addPoint(tf%1); // Advance stopAt = (optionsSegs.Count > 0) ? optionsSegs[0].TF : endTF; atStopPoint = spline.MoveByAngleExtINTERNAL(ref tf, Generator.MinDistance, maxStep, maxAngle, out curPos, out curTan, out stepDist, stopAt, data.Closed,stepSizeTF); curDist += stepDist; if (Mathf.Approximately(tf, endTF) || tf > endTF) { curDist = endDist; endTF = (data.Closed) ? DTMath.Repeat(endTF,1) : Mathf.Clamp01(endTF); curPos = spline.Interpolate(endTF); if (fullPath) curTan = spline.GetTangent(endTF, curPos); addPoint(endTF); break; } if (atStopPoint) { if (optionsSegs.Count > 0) { if (optionsSegs[0].UVEdge || optionsSegs[0].UVShift) extendedUVData.Add(new SamplePointUData(pos.Count, optionsSegs[0].UVEdge,optionsSegs[0].FirstU, optionsSegs[0].SecondU)); // clamp point at CP and maybe duplicate the next sample point curDist = optionsSegs[0].Distance; maxStep = (optionsSegs[0].MaxStepDistance); dupe = optionsSegs[0].HardEdge || optionsSegs[0].MaterialID != grp.MaterialID || (options.CheckExtendedUV && optionsSegs[0].UVEdge); if (dupe) { // end the current patch... patch.End = pos.Count; grp.Patches.Add(patch); // if MaterialID changes, we start a new MaterialGroup if (grp.MaterialID != optionsSegs[0].MaterialID) { data.MaterialGroups.Add(grp); grp = new SamplePointsMaterialGroup(optionsSegs[0].MaterialID); } // in any case we start a new patch patch = new SamplePointsPatch(pos.Count + 1); if (!optionsSegs[0].HardEdge) softEdges.Add(pos.Count + 1); // Extended UV if (optionsSegs[0].UVEdge || optionsSegs[0].UVShift) extendedUVData.Add(new SamplePointUData(pos.Count+1, optionsSegs[0].UVEdge, optionsSegs[0].FirstU, optionsSegs[0].SecondU)); addPoint(tf); } // and remove the CP from the options optionsSegs.RemoveAt(0); } else { addPoint(tf); break; } } } if (dead <= 0) Debug.LogError("[Curvy] He's dead, Jim! Deadloop in SplineInputModuleBase.GetSplineData (Optimized)! Please send a bug report!"); // store the last open patch patch.End = pos.Count - 1; grp.Patches.Add(patch); // ExplicitU on last Vertex? if (optionsSegs.Count > 0 && optionsSegs[0].UVShift) extendedUVData.Add(new SamplePointUData(pos.Count - 1, optionsSegs[0].UVEdge, optionsSegs[0].FirstU, optionsSegs[0].SecondU)); // if path is closed and no hard edges involved, we need to smooth first normal if (data.Closed && !spline[0].GetMetadata<MetaCGOptions>(true).HardEdge) softEdges.Add(0); data.MaterialGroups.Add(grp); // fill data data.SourceF = sourceF.ToArray(); data.F = relF.ToArray(); data.Position = pos.ToArray(); data.Bounds = spline.Bounds; if (fullPath) { ((CGPath)data).Direction = tan.ToArray(); data.Normal = up.ToArray(); } #endregion break; } data.Map = (float[])data.F.Clone(); if (!fullPath) { data.RecalculateNormals(softEdges); if (options && options.CheckExtendedUV) CalculateExtendedUV(spline,startTF,endTF,extendedUVData, data); } return data; }
public void UpdateATL(ThirdPersonUserControl player, CurvySpline spline) { if (!init && spline.IsInitialized) { init = true; t = spline.GetNearestPointTF(player.transform.position); minT = t - (buffer / spline.Length) / 2.0f; maxT = t + (buffer / spline.Length) / 2.0f; } if (!init) { return; } //print ("spline name = " + spline.name); float playerT = spline.GetNearestPointTF(player.transform.position); //print ("playerT = " + playerT); //AxKDebugLines.AddSphere (player.transform.position, 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (player.transform.position), 0.3f, Color.magenta); //AxKDebugLines.AddSphere (spline.Interpolate (playerT), 0.3f, Color.blue); if (playerT > maxT) { maxT = playerT; minT = maxT - (buffer / spline.Length); t = playerT; } else if (playerT < minT) { minT = playerT; maxT = minT + (buffer / spline.Length); t = playerT; } //AxKDebugLines.AddSphere (spline.Interpolate (maxT), 0.3f, Color.green); //AxKDebugLines.AddSphere (spline.Interpolate (minT), 0.3f, Color.magenta); splineUp = spline.GetRotatedUpFast(t, 0); splineForward = spline.GetTangent(t); splineRight = Vector3.Cross(splineUp, splineForward); //print ("offset = " + offset); Vector3 rise = splineUp * offset.y + splineForward * offset.z + splineRight * offset.x * Mathf.Sin(Mathf.Sqrt(Time.time)); float targetPositionT = t + offsetCam / spline.Length; Vector3 targetPosition = spline.Interpolate(targetPositionT) + rise; float lookPositionT = t - offsetLook / spline.Length; Vector3 lookPosition = spline.Interpolate(lookPositionT); targetPosition = ((targetPosition * 4f) + player.transform.position) / 5f; if (CUbool) { lookPosition = player.transform.position + player.transform.up * 2.55f; targetPosition = lookPosition + player.transform.forward * .4f; //print ("in bool"); } else if (falling) { lookPosition = player.transform.position; targetPosition = transform.position; } transform.position = Vector3.Lerp(transform.position, targetPosition, Time.deltaTime * smooth); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation((lookPosition - transform.position).normalized), Time.deltaTime * smooth); }
void DoInterpolate() { if (!mSpline.IsInitialized) { return; } System.Type metaDataType; { if (String.IsNullOrEmpty(MetaDataType.Value)) { metaDataType = null; } else { #if NETFX_CORE Type[] knownTypes = this.GetType().GetAllTypes(); #else Type[] knownTypes = TypeExt.GetLoadedTypes(); #endif metaDataType = knownTypes.FirstOrDefault(t => t.FullName == MetaDataType.Value); } } bool calc = !Input.IsNone; if (calc) { float f = (UseWorldUnits.Value) ? mSpline.DistanceToTF(Input.Value) : Input.Value; if (StorePosition.IsNone == false) { StorePosition.Value = (UseCache.Value) ? mSpline.InterpolateFast(f) : mSpline.Interpolate(f); } if (StoreTangent.IsNone == false) { StoreTangent.Value = mSpline.GetTangent(f); } if (StoreUpVector.IsNone == false) { StoreUpVector.Value = mSpline.GetOrientationUpFast(f); } if (StoreRotation.IsNone == false) { StoreRotation.Value = (StoreUpVector.IsNone) ? mSpline.GetOrientationFast(f) : Quaternion.LookRotation(mSpline.GetTangent(f), StoreUpVector.Value); } if (StoreScale.IsNone == false) { float localF; CurvySplineSegment segment = mSpline.TFToSegment(f, out localF); CurvySplineSegment nextControlPoint = segment.Spline.GetNextControlPoint(segment); if (ReferenceEquals(segment, null) == false) { StoreScale.Value = nextControlPoint ? Vector3.Lerp(segment.transform.lossyScale, nextControlPoint.transform.lossyScale, localF) : segment.transform.lossyScale; } else { StoreScale.Value = Vector3.zero; } } if (StoreTF.IsNone == false) { StoreTF.Value = f; } if (StoreDistance.IsNone == false) { StoreDistance.Value = (UseWorldUnits.Value) ? Input.Value : mSpline.TFToDistance(f); } if (metaDataType != null) { if (metaDataType.IsSubclassOf(typeof(CurvyMetadataBase)) == false) { //this if statement's branch does not exclude classes inheriting from CurvyMetadataBase but not from CurvyInterpolatableMetadataBase, but that's ok, those classes are handled below Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>"); } else { if (StoreMetadata.IsNone == false) { MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetMetadata").MakeGenericMethod(metaDataType); StoreMetadata.Value = (Object)genericMethodInfo.Invoke(mSpline, new System.Object[] { f }); } if (StoreInterpolatedMetadata.IsNone == false) { Type argumentType = GetInterpolatableMetadataGenericType(metaDataType); if (argumentType == null) { Debug.LogError("Meta data type " + metaDataType.FullName + " should be a subclass of CurvyInterpolatableMetadataBase<T>"); } else { MethodInfo genericMethodInfo = mSpline.GetType().GetMethod("GetInterpolatedMetadata").MakeGenericMethod(metaDataType, argumentType); StoreInterpolatedMetadata.SetValue(genericMethodInfo.Invoke(mSpline, new System.Object[] { f })); } } } } CurvySplineSegment seg = null; float segF = 0; if (StoreSegment.IsNone == false) { seg = getSegment(f, out segF); StoreSegment.Value = seg.gameObject; } if (StoreSegmentF.IsNone == false) { if (!seg) { seg = getSegment(f, out segF); } StoreSegmentF.Value = segF; } if (StoreSegmentDistance.IsNone == false) { if (!seg) { seg = getSegment(f, out segF); } StoreSegmentDistance.Value = seg.LocalFToDistance(segF); } } // General if (StoreLength.IsNone == false) { StoreLength.Value = mSpline.Length; } if (StoreCount.IsNone == false) { StoreCount.Value = mSpline.Count; } }