![]() ![]() (Hacking this in on my smartphone so no warranties but if there is trouble I can check it as soon as I'm with a PC again. ![]() Should result in what you wanted to achieve. worldAnchorReference.CenterOnObject(RedSphere) Now you call it passing one of the children like e.g. finally, actually perform the scale/translation Vector3 C = A - B // diff from object pivot to desired pivot/originįloat RS = newScale.x / // relative scale factor Private void ScaleAround(GameObject target, Vector3 pivot, Vector3 newScale) takes care of the correct position translation as well This scales an object around a certain pivot and Transform.rotation = Quaternion.Inverse(targetRotation) Now rotate around 0,0,0 so that the rotation of the target gets normalized has scale 1,1,1 and still is on position 0,0,0 Now everything should be scaled so that the target ScaleAround(gameObject, Vector3.zero, newScale) Var newScale = Vector3.one * 1/targetScale.x After this action the target should be on 0,0,0 set yourself to inverted target position ![]() Transform.rotation = Quaternion.Idendity translation, rotation, scale, shear etc. Var targetScale = targetTransform.localScale A transformation matrix can perform arbitrary linear 3D transformations (i.e. ![]() Var targetRot = targetTransform.localRotation The localPosition and localRotation are relative to the parent Maybe something like public void CenterOnObject(GameObject targetCenter) I guess you want to allways center and normalize a certain child object. How exactly you move the world anchor is your thing. Now all that is left is to transform the WorldAnchorObject -> it will move, scale and rotate anything else and keeps the relative transforms intact. Position/rotate/scale the Spheres (this will now happen relative to WorldAnchorObject) Make sure the WorldAnchorObject has position: 0,0,0 Wrap your objects into the following hierarchy WorldAnchorObject There might be other solutions but here is what I would do transforming the positionbefore-Vector)? It needs to be applied to a (very) large number of objects every frame, thus it needs to be (fairly) optimized. Is there a way to do this without doing the full calculation on every Vector (i.e. What I'm looking for is a Matrix that can do this (and include rotation, such that Origin2 is rotated to the rotation Origin1 was in before the transformation, and all other objects are moved to their correct positions). Vector3 positionAfter = (positionBefore * scaleFactor) + Vector3 positionBefore = testPosition.TestPosition - origin.TestPosition This will of course not work when rotation is applied to any of the 2 origins. The values for each sphere: Origin1 (Red Sphere)Ĭurrently I'm simply taking the Vector between the 2 origins, scaling that to the difference between the two origins, then applying that on top of the new position of the original (first) origin. To visualize the problem, I've made a small GIF (I currently have a working version in 3D, without using a Matrix, and without any rotation): What I'm looking for, is a change of frames, in which the new frame has a different origin, rotation, AND scale, with regards to the original one. I have looked at using Unity's built-in Matrix4x4.TRS()-method, but this seems useless, as it only applies the Translation, Rotation & Scale to a defined point. What this means is that the origin of the new frame is rotated, translated, and scaled to match the origin of the old frame, then this operation is applied to all other objects (including the old origin).įor this, I need a generalized, 3-dimensional (thus 4x4) Transformation-Matrix. Using UnityEngine using System.For a project in Unit圓D I'm trying to transform all objects in the world by changing frames. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |