Ogre-non-mainstream Calculation of relative local coordinates

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.