在犰狳的模板元编程

问题描述 投票:0回答:1

我想在我的光线追踪项目中使用Armadillo库进行计算。我在某处读到,我可以使用自己的矢量类将它传递给Armadillo,使用模板编程,但我找不到更多的信息。我想要这个,因为我想省略使用表运算符。

TL; DR我想像GLM一样使用犰狳

arma::vec3 orig;
orig.x = 12.f;
orig.y = 13.f;

GLM中的位置:

glm::ivec3 vec;
vec.x = ...;
vec.y = ...;

我认为宏,但它不是优雅的解决方案。另外,我必须使用犰狳,所以建议使用GLM跌倒

c++ templates
1个回答
0
投票

我忘了先添加答案:我复制重载的operator []并将其更改为此格式(Col_meat.hpp文件)并对y,z,w执行相同的操作(更改索引当然)

   template<typename eT>
   template<uword fixed_n_elem>
   arma_inline
   arma_warn_unused
   eT&
   Col<eT>::fixed<fixed_n_elem>::x(void)
   {
          arma_debug_check((0 >= fixed_n_elem), "Col::x(): index out of bounds");

          return (use_extra) ? mem_local_extra[0] : Mat<eT>::mem_local[0];
   }

   template<typename eT>
   template<uword fixed_n_elem>
   arma_inline
   arma_warn_unused
   const eT&
   Col<eT>::fixed<fixed_n_elem>::x(void) const
   {
          arma_debug_check((0 >= fixed_n_elem), "Col::x(): index out of bounds");

          return (use_extra) ? mem_local_extra[0] : Mat<eT>::mem_local[0];
   }
© www.soinside.com 2019 - 2024. All rights reserved.