During 3D programming, the local coordinates of a point relative to another point are often calculated. the common practice is to use a matrix or other operations. A very simple method is proposed here, which does not involve matrices. The idea is also relatively simple and the code is simpler. efficiency may not be inferior. code:
/* Getlocalposition: calculates the local coordinates of pothernode relative to prefnode */ogre: vector3 getlocalposition (Ogre: scenenode * prefnode,
Ogre: scenenode * pothernode) {// directly obtain the world coordinate vector3 worldpos = pothernode-> getworldposition () of the second node; // create a node on the first node
// Let ogre specify a name for us to avoid duplication
Ogre: scenenode * tpnode = prefnode-> createchildscenenode (); // make the world coordinates the same as the world coordinates of the second node tpnode-> translate (worldpos, ogre: node:: ts_world); // obtain the coordinate vector3 result = tpnode-> getposition (); prefnode-> getcreator () of the temporary node relative to the parent node () -> destroyscenenode (tpnode-> getname (); return result ;}
I personally think this method is correct from a theoretical point of view. If someone sees it, I hope I can give some comments and point out errors.
Efficiency is not considered for the moment ....
In development, I want to use it like this without a matrix or quaternary element.
By: Hong gunwei