move entity in orientated local grid

Problems building or running the engine, queries about how to use features etc.
Post Reply
Lax
Hobgoblin
Posts: 583
Joined: Mon Aug 06, 2007 12:53 pm
Location: Saarland, Germany
x 50

move entity in orientated local grid

Post by Lax »

Hi folks,

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;
This works as long the entity is not rotated. The entity snaps from grid to grid by its size.
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;
Now when the entity's is orentated 90 degree around y:
|----|
|....|
|....|
|___|

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;
Now the entity will snap even for 45 degree correctly, but the movement is wrong, as the axes are swapped. So when I move the entity in x-direction, it will move in z-direction. When I move in z-direction it will move in x-direction and so on.

Has anybody an idea how to solve this issue?
I searched everywhere but nothing found.

Thanks in advance
Lax

http://www.lukas-kalinowski.com/Homepage/?page_id=1631
Please support Second Earth Technic Base built of Lego bricks for Lego ideas: https://ideas.lego.com/projects/81b9bd1 ... b97b79be62

Post Reply