Is there any way to apply affine transforms with unity classes. I didn't manage to find anything in the documentation. What I need to do: I am using GuiManager2, and I need a "minimap". I will need textures that orbit (rotate) in 2D space around a center point. Since i'll have 20+ objects that need this, I am trying to figure out the most performance effective way to determine the Vector2 for each object. In a previous objective c project I used this function: Code (csharp): + (void)rotatePoint:(VBasePoint*)point :(CGPoint)origin :(CGFloat)angle { CGAffineTransform translate = CGAffineTransformMakeTranslation(origin.x,origin.y); CGAffineTransform rotate = CGAffineTransformMakeRotation(angle); CGAffineTransform concat = CGAffineTransformConcat(CGAffineTransformConcat( CGAffineTransformInvert(translate), rotate), translate); CGPoint newPoint = CGPointApplyAffineTransform(*point.location, concat); point->x = newPoint.x; point->y = newPoint.y; }
As far as I know Unity doesn't have a built-in tool for creating affine matrices. You could use a 4x4 matrix for this if you want. Better yet you could just use Vector3s and confine their rotation to the plane you are working in. Vector3 p; p = Quaternion.EulerAngles(0, 0, 45) * p; This will rotate the vector P by 45 degrees in the Z axis. So if your center of rotation is at (10,10,0) and you want to rotate point (5,5,0) about this pivot, you would define P as the vector created from (point - pivot). And after you rotate the vector P you get your new point by doing (P + pivot)
Hey. Thanks for the info, it does work. In case anyone else is interested, here is a code snippet from what I am working on. The only change is that I used the 'Euler' function, since 'EulerAngles' is depricted: Code (csharp): private void ManageMonsterIcons() { float angle = 360f / monsterIcons.Count; Vector3 center = new Vector3(Screen.width * 0.5f, 0, Screen.height * 0.5f); Vector3 offset = center - new Vector3(0f, 0f, -100f); Vector3 dif = offset - center; for (int i=0; i<monsterIcons.Count; i++) { GUIQuadObj icon = (GUIQuadObj)monsterIcons[i]; float myAngle = angle * i; Vector3 p = Quaternion.Euler(0f, myAngle, 0f) * dif; p += center; icon.Location = new Vector2(p.x, p.z); icon.Visible = true; } }
Hi, If I have a vector3 (say A) based off another vector (say B), is it possible to find A if I happen to change B. I hope it is possible through affine transformation but I am not sure as of how to apply them.