public static InterpConstantSpeed ( Vector3 pts, float t ) : Vector3 | ||
pts | Vector3 | |
t | float | |
리턴 | Vector3 |
public static Vector3 InterpConstantSpeed(Path pts, float t, Easing.EaseType easeType = Easing.EaseType.linear) { t = Easing.ease(easeType, t); if (pts.Length == 0) { return(Vector3.zero); } else if (pts.Length == 1) { return(pts[0]); } else if (pts.Length == 2) { return(Vector3.Lerp(pts[0], pts[1], t)); } else if (pts.Length == 3) { return(QuadBez.Interp(pts[0], pts[2], pts[1], t)); } else if (pts.Length == 4) { return(CubicBez.Interp(pts[0], pts[3], pts[1], pts[2], t)); } else { return(CRSpline.InterpConstantSpeed(Wrap(pts), t)); } }
public static Vector3 InterpConstantSpeed(Path pts, float t, EasingType ease = EasingType.Linear, bool easeIn = true, bool easeOut = true) { t = Ease(t, ease, easeIn, easeOut); if (pts.Length == 0) { return(Vector3.zero); } else if (pts.Length == 1) { return(pts[0]); } else if (pts.Length == 2) { return(Vector3.Lerp(pts[0], pts[1], t)); } else if (pts.Length == 3) { return(QuadBez.Interp(pts[0], pts[2], pts[1], t)); } else if (pts.Length == 4) { return(CubicBez.Interp(pts[0], pts[3], pts[1], pts[2], t)); } else { return(CRSpline.InterpConstantSpeed(Wrap(pts), t)); } }
Object PutOnPath(Transform obj, float pathPercentage, Vector3 offset) { pathPercentage = Mathf.Min(Mathf.Max(0.0f, pathPercentage), 0.999f); Quaternion rotation = new Quaternion(); rotation.SetLookRotation(CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage) - CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage * 0.99f)); return(Instantiate(obj, CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage) + offset, rotation)); }
void SetOnPath(Transform obj, float pathPercentage, Vector3 offset) { pathPercentage = Mathf.Min(Mathf.Max(0.0f, pathPercentage), 0.999f); Quaternion rotation = new Quaternion(); rotation.SetLookRotation(CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage) - CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage * 0.99f)); obj.position = CRSpline.InterpConstantSpeed(thePath.ToArray(), pathPercentage) + offset; obj.rotation = rotation; }
// Use this for initialization void Start() { Vector3[] path = { new Vector3(976.656f, 1160.348f, 57.45f), new Vector3(20.833f, 972.301f, 430.565f), new Vector3(-930.696f, 0.0f, 176.947f), new Vector3(-383.768f, 0.0f, -489.477f), new Vector3(-158.563f, 335.323f, 75.834f), new Vector3(714.683f, 274.965f, -402.153f), new Vector3(-140.179f, 0.0f, -843.371f), new Vector3(737.663f, -176.377f, -1022.617f), new Vector3(883.723f, -33.156f, -685.02f), new Vector3(1559.897f, 118.9f, -608.974f), new Vector3(1541.968f, 0.0f, 158.764f), new Vector3(549.226f, 0.0f, -80.431f), new Vector3(-282.656f, -344.386f, -719.279f) }; path = path.Select(x => x * 0.2f).ToArray(); thePath = Interpolate.NewCatmullRom(path, 1000, false); this.transform.parent.transform.position = path[0]; Transform theBdnf; theBdnf = (Transform)PutOnPath(BDNF, firstBDNFPath, Vector3.up * BDNFHeight); theBdnf.gameObject.SendMessage("SetPictureTaker", PictureTaker); theBdnf.gameObject.SendMessage("SetMessageCaught", Badge09); theBdnf = (Transform)PutOnPath(BDNF, lastBDNFPath, Vector3.up * BDNFHeight); theBdnf.gameObject.SendMessage("SetPictureTaker", PictureTaker); theBdnf.gameObject.SendMessage("SetMessageCaught", Badge09); var spread = (lastBDNFPath - firstBDNFPath) / BDNFAmount; for (int i = 1; i <= BDNFAmount - 2; i++) { theBdnf = (Transform)PutOnPath(BDNF, firstBDNFPath + spread * i + (Random.value - 0.5f) * spread * 0.7f, Vector3.up * BDNFHeight); theBdnf.gameObject.SendMessage("SetPictureTaker", PictureTaker); theBdnf.gameObject.SendMessage("SetMessageCaught", Badge09); } for (float i = ringBeginning; i <= 0.99f; i += ringSeparation) { var splinePos = CRSpline.InterpConstantSpeed(thePath.ToArray(), i); ringPositions.Add(splinePos); ringAngles.Add(splinePos - CRSpline.InterpConstantSpeed(thePath.ToArray(), i * 0.99f)); } for (int i = 0; i < rings.Length; i++) { rings[i] = (Transform)PutOnPathCache(tubeRing, i, Vector3.zero, ringPositions, ringAngles); rings[i].Rotate(90, 0, 0); ringOffsets[i] = i * ringSeparation + ringBeginning; ribosomes[i] = (Transform)PutOnPathCache(ribosome, i, ribosomeDist * new Vector3(Random.value, Random.value, Random.value), ringPositions, ringAngles); } currentCache = rings.Length; //MoveBall(); }
void MoveBall() { if (pathCompletion < 1.0f) { var toMove = CRSpline.InterpConstantSpeed(thePath.ToArray(), pathCompletion) - this.transform.parent.transform.position; Quaternion rotation = new Quaternion(); if (toMove.magnitude > 0.0f) { rotation.SetLookRotation(toMove); this.transform.parent.transform.localRotation = rotation; } this.transform.parent.transform.position += toMove; } else { TriggerEnd(); } }