I'm having trouble with vertices position in my scene. I have 2 different nodes (and meshes) and I want to change the position of a single vertex on both nodes to make then ocupy the same place in the global 3D space. The problem is, the vertex position in the mesh buffer is local based on the node position (I'm supposing that) and I can't find a way to get the average point between the vertices to move them there.
bool getVertexPos
(
scene::ISceneNode* node,
const core::vector3df& 3dPos, // in world space
core::vector3df& vertexPos // in local/model space
)
{
core::matrix4 matrix = node->getAbsoluteTransformation();
core::matrix4 inverse;
if (!matrix.getInverse(inverse))
return false
printf("Inverse matrix of node found\n");
inverse.transformVect(vertexPos, 3dPos);
return true;
}
and after that, how do I find the average point between the two vertices and the average point local position on each mesh?
I guess the "two vertices" mentioned mean the single 3d point in world space and and "average point local position" means vertex point in the mesh buffer.
The function above should give you the respectively vertex point in the mesh buffer for different nodes.
This is what I'm trying to do:
each hex is a node, the red dots are the vertices I have. I'm trying to find the green dot (the average position vector between the two red ones), but I need the average vector in local position in both nodes (so I can move the red vertices to the same (global) position as the green one, this way both vertices would occupy the same global point in the 3D space [though having different local positions])
This is what I'm trying to do:
each hex is a node, the red dots are the vertices I have. I'm trying to find the green dot (the average position vector between the two red ones), but I need the average vector in local position in both nodes (so I can move the red vertices to the same (global) position as the green one, this way both vertices would occupy the same global point in the 3D space [though having different local positions])
If you want to move the hexagon nodes in gray color together, then
But I guess you don't need the inverse, but the normal transformation matrix. Because you want to go from local to world space, check the positions there, and derive a translation offset which you can add to one of the nodes via setPosition.
core::vector3d green = (red1 + red2) * 0.5f;
core::vector3d red1ToGreenVector = green - red1;
...
Regards
smso
The problem with that is this:
The position of the red vertex #2 inside the node #1 is the orange dot (since its position is local), so doing (red1+red2)/2 will give me the light green point, not the dark green one... that's why I think I need to do the math in the global space and then come translate it back to the local space.
hybrid wrote:But I guess you don't need the inverse, but the normal transformation matrix. Because you want to go from local to world space, check the positions there, and derive a translation offset which you can add to one of the nodes via setPosition.
so I use the normal transformation matrix to find the position in the global space? how do I translate it back to local after that?
Why would you want to translate this back? You only have to add the calculated offset to one of the meshes. Or, if you want to merge both meshes on the green point, to both meshes.