Download

Rotate a vector using another vector as pivot

I’m working in dynamic houses that creates the interior (furniture, doors, etc) when the player is near. Each item has a position vector relative to the house location, and a relative rotator.

If the house is not rotated, the item.location = house.location + item.relativelocation. For the rotator the same, no problem.

What I’m triying is to get the item location when the house is rotated in any angle. So I have house.location, house.rotation and item.relativelocation. How calculate the new item.location depending of the house location and rotation?

I have found a solution:

item.location = house.location + (vector(rotator(item.relativelocation) + house.rotation)*vsize(item.relativelocation) );

but don’t seems too accurate, depending of the rotation there are a small displacement.

I use this formula:

item.location = house.location + (item.relativeLocation >> house.rotation);

That does the same thing, but maybe with fewer steps, there’s less room for floating point errors.

Works perfectly and it’s more simple, thanks!