Non-member conversion functions; Casting different types, e.g. DirectX vector to OpenGL vector

前端 未结 3 1568
礼貌的吻别
礼貌的吻别 2020-12-20 12:33

I am currently working on a game \"engine\" that needs to move values between a 3D engine, a physics engine and a scripting language. Since I need to apply vectors from the

3条回答
  •  天命终不由人
    2020-12-20 13:03

    I would suggest writing them as a pair of free functions (i.e. don't worry about making them 'operators'):

    vector3d vector3dFromBt(const btVector3& src) {
        // convert and return
    }
    
    btVector3 btVectorFrom3d(const vector3d& src) {
        // convert and return
    }
    
    void f(void)
    {
      vector3d one;   
    // ...populate...   
      btVector3 two(btVectorFrom3d(one));    
    // ...
      vector3d three(vector3dFromBt(two));
    }
    

提交回复
热议问题