Skip to content

Commit

Permalink
Updated toarray method for quaternion trying to fix the weird bug on …
Browse files Browse the repository at this point in the history
…intel osx
  • Loading branch information
dipterix committed Nov 7, 2023
1 parent ebb8344 commit a8f8ceb
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ BEGIN_RCPP
END_RCPP
}
// Quaternion__to_array
std::vector<double> 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;
Expand Down
26 changes: 19 additions & 7 deletions src/glQuaternion.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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]]
Expand Down Expand Up @@ -80,13 +80,25 @@ void Quaternion__copy(const SEXP& self, const SEXP& quaternion) {
}

std::vector<double> Quaternion::toArray() {
return {this->x, this->y, this->z, this->w};
std::vector<double> arr(4);
arr[0] = this->x;
arr[1] = this->y;
arr[2] = this->z;
arr[3] = this->w;
return arr;
}

// [[Rcpp::export]]
std::vector<double> Quaternion__to_array(const SEXP& self) {
SEXP Quaternion__to_array(const SEXP& self) {
Rcpp::XPtr<Quaternion> 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) {
Expand Down

0 comments on commit a8f8ceb

Please sign in to comment.