From a8f8ceb422f197f7ed1b75f3ec79bb2458a2a3e7 Mon Sep 17 00:00:00 2001 From: dipterix Date: Tue, 7 Nov 2023 16:28:03 -0500 Subject: [PATCH] Updated toarray method for quaternion trying to fix the weird bug on intel osx --- src/RcppExports.cpp | 2 +- src/glQuaternion.cpp | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index 7dafa6d..34879e5 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -1061,7 +1061,7 @@ BEGIN_RCPP END_RCPP } // Quaternion__to_array -std::vector Quaternion__to_array(const SEXP& self); +SEXP Quaternion__to_array(const SEXP& self); RcppExport SEXP _ravetools_Quaternion__to_array(SEXP selfSEXP) { BEGIN_RCPP Rcpp::RObject rcpp_result_gen; diff --git a/src/glQuaternion.cpp b/src/glQuaternion.cpp index 0a183a0..4584e96 100644 --- a/src/glQuaternion.cpp +++ b/src/glQuaternion.cpp @@ -16,10 +16,10 @@ using namespace rave3d; Quaternion::Quaternion() { - this->x = 0; - this->y = 0; - this->z = 0; - this->w = 1; + this->x = 0.0; + this->y = 0.0; + this->z = 0.0; + this->w = 1.0; } // [[Rcpp::export]] @@ -80,13 +80,25 @@ void Quaternion__copy(const SEXP& self, const SEXP& quaternion) { } std::vector Quaternion::toArray() { - return {this->x, this->y, this->z, this->w}; + std::vector arr(4); + arr[0] = this->x; + arr[1] = this->y; + arr[2] = this->z; + arr[3] = this->w; + return arr; } // [[Rcpp::export]] -std::vector Quaternion__to_array(const SEXP& self) { +SEXP Quaternion__to_array(const SEXP& self) { Rcpp::XPtr ptr(self); - return ptr->toArray(); + SEXP re = PROTECT(Rf_allocVector(REALSXP, 4)); + double* ptr_re = REAL(re); + *ptr_re++ = ptr->x; + *ptr_re++ = ptr->y; + *ptr_re++ = ptr->z; + *ptr_re = ptr->w; + UNPROTECT(1); + return re; } // Quaternion& Quaternion::setFromEuler(const Euler& euler, bool update) {