From b50f9b36b1fe99d33016ca643c97d81ea679d3e2 Mon Sep 17 00:00:00 2001 From: Jiri Pittner Date: Thu, 28 Oct 2021 18:14:07 +0200 Subject: [PATCH] Initialization of Vec3, MAt3, and Quaternion from brace-enclosed list --- quaternion.h | 1 + t.cc | 8 ++++++++ vecmat3.h | 2 ++ 3 files changed, 11 insertions(+) diff --git a/quaternion.h b/quaternion.h index ab0333b..46a1fe3 100644 --- a/quaternion.h +++ b/quaternion.h @@ -40,6 +40,7 @@ public: T q[4]; //methods Quaternion(void) {}; + Quaternion(const T (&a)[4]) {memcpy(q,a,4*sizeof(T));}; Quaternion(const T x, const T u=0, const T v=0, const T w=0) {q[0]=x; q[1]=u; q[2]=v; q[3]=w;}; //quaternion from real(s) Quaternion(const std::complex &rhs) {q[0]=rhs.real(); q[1]=rhs.imag(); q[2]=0; q[3]=0;} //quaternion from complex explicit Quaternion(const T* x, const int shift=1) {q[0]=0; memcpy(q+shift,x,(4-shift)*sizeof(T));} //for shift=1 quaternion from xyz vector diff --git a/t.cc b/t.cc index 192f138..017e0e8 100644 --- a/t.cc +++ b/t.cc @@ -2298,8 +2298,16 @@ if(1) { NRVec v({1,2,3,4}); cout < m({{1,2,3},{4,5,6}}); cout< x({1,2,3}); +cout< y({{1,2,3},{4,5,6},{7,8,9}}); +cout < q({1,2,3,4}); +cout<