|
|
David Vincent-Jones <geo### [at] galaxynetcom> wrote:
> I tried to use this approach but unfortunately I need a more
generalized
> solution.
> All I need.. is the angle (direction) between 2 vector locations..
> but I need to ensure that it works in any and all quadrants.
> My objects can always be rotated at origin prior to any move.
> Surely there must be an easy solution sitting somewhere.
If the vehicle is travelling on flat ground, and only rotating around
the y-axis, then the solution should indeed be fairly simple. Let's say
you've declared the vehicle pointing towards the +z direction, so its
base (wheels or whatever) touches y=0 and it is centered at x=0 and z=0.
Given any direction we can calculate the rotation using the arc-tangent:
object {Vehicle
rotate y*degrees(atan2(Direction.x, Direction.z))
translate Location}
The beauty of the atan2 function is that it works in all four quadrants,
and also works for the cases +z (0 degrees), +x (90 degrees), -z (180
degrees), and -x (-90 degrees). However, it will not work when the
Direction vector is <0, 0, 0>, so if the vehicle is stationery during
the animation you will still need to supply a Direction.
Post a reply to this message
|
|