Suppose I have an object which is defined as an array of vector points, and by default it’s looking down the +x axis. If I want to make the object face a unit vector, say, (0,1), how would I do so? I’d assume its similar for 3D space?
EDIT: I don’t think trigonometric functions are necessary for this, so please don’t use angles and/or arctangents.
It’s considerably easier for 2D. In 2D, object rotation can just be expressed as a single angle. Use your orientation vector to call an arctangent routine to get the angle, and then rotate your object by that angle.
EDIT: No arctangents? OK, well, you want the X-axis of points in the object to become some vector
(u, v). In that case, the y-axis is always expressible as(-v, u), which will also be a unit vector if(u, v)was a unit vector.So just do this: if you have a point
(x, y)relative to your object, the position relative to the world should be(object.xCenter, object.yCenter) + x(u, v) + y(-v, u) = (object.xCenter + u*x - v*y, object.yCenter + v*x + u*y).Example: object located at (5,5). It has a point relative to it at (2, 2) when facing in the x axis direction. If you now wish to orient it at (sqrt(2)/2, sqrt(2)/2) (unit length version of (1, 1)), the point, relative to the world, is (5, 5 + 2*sqrt(2)).