I'm experimenting on how to move an entity in a grid. The grid factor is the bounding box of the entity. Image the bounding box has this size:
|----------|
|_______|
So far so good. Here is the code:
Code: Select all
Ogre::Vector3 gridFactor = entity->getLocalAabb().getSize();
Ogre::Vector3 resultPosition;
resultPosition.x = (round(entityPosition.x / (gridFactor.x))) * gridFactor.x;
resultPosition.y = (round(entityPosition.y / (gridFactor.y))) * gridFactor.y;
resultPosition.z = (round(entityPosition.z / (gridFactor.z))) * gridFactor.z;
But how to move an entity, that is orientated, in a grid?
I tried several thinks like, taking the nodes orientation into account for the grid factor:
Code: Select all
Ogre::Vector3 gridFactor = node->getOrientation() * movableObject->getLocalAabb().getSize();
resultPosition.x = (round(entityPosition.x / (gridFactor.x))) * gridFactor.x;
resultPosition.y = (round(entityPosition.y / (gridFactor.y))) * gridFactor.y;
resultPosition.z = (round(entityPosition.z / (gridFactor.z))) * gridFactor.z;
|----|
|....|
|....|
|___|
It will be snapped correctly, but when its orientated e.g. 45 degree it will not snap correctly.
So I tried orientating the final grid value according to the nodes orientation:
Code: Select all
Ogre::Vector3 gridFactor = movableObject->getLocalAabb().getSize();
resultPosition.x = (round(entityPosition.x / (gridFactor.x))) * gridFactor.x;
resultPosition.y = (round(entityPosition.y / (gridFactor.y))) * gridFactor.y;
resultPosition.z = (round(entityPosition.z / (gridFactor.z))) * gridFactor.z;
resultPosition = node->getOrientation() * resultPosition;
Has anybody an idea how to solve this issue?
I searched everywhere but nothing found.
Thanks in advance
Lax