Untitled
unknown
plain_text
a month ago
2.2 kB
4
Indexable
Never
private void SetPositionsAndRotations(float minorRingTwistIncrement) { for (int i = 0; i < thetaDivisions; i++) { float phi = 2.0f * Mathf.PI * i / thetaDivisions; for (int j = 0; j < phiDivisions; j++) { float theta = 2.0f * Mathf.PI * j / phiDivisions; float majorRadiusTwist = _offsetAlignment.x * j / phiDivisions; // recalculate theta center point based on twist offset Vector3 twistedThetaCenter = new Vector3( majorRadius * Mathf.Cos(phi + majorRadiusTwist), majorRadius * Mathf.Sin(phi + majorRadiusTwist), 0f ); // root object's forward direction Vector3 objectForward = transform.forward; Vector3 thetaCross = Vector3.Cross(twistedThetaCenter, objectForward); float thetaTwist = theta + minorRingTwistIncrement; float x = (majorRadius + minorRadius * Mathf.Cos(thetaTwist)) * Mathf.Cos(phi + majorRadiusTwist); float y = (majorRadius + minorRadius * Mathf.Cos(thetaTwist)) * Mathf.Sin(phi + majorRadiusTwist); float z = minorRadius * Mathf.Sin(thetaTwist); Vector3 localPosition = new Vector3(x, y, z); Vector3 worldPosition = transform.TransformPoint(localPosition); // direction based on the twist offset theta center Vector3 localDirection = (twistedThetaCenter - localPosition).normalized; Vector3 worldDirection = transform.TransformDirection(localDirection); Quaternion rotationQuaternion = Quaternion.LookRotation(worldDirection, transform.TransformDirection(thetaCross)); vertices[i * phiDivisions + j] = localPosition; rotations[i * phiDivisions + j] = localDirection; rotationQuaternions[i * phiDivisions + j] = rotationQuaternion; Debug.DrawRay(worldPosition, worldDirection, Color.red); } } }
Leave a Comment