Project
Loading...
Searching...
No Matches
GPUDisplayQuaternion.cxx
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#include "GPUDisplay.h"
16
17#include <cmath>
18using namespace o2::gpu;
19
20void GPUDisplay::createQuaternionFromMatrix(float* v, const float* mat)
21{
22 if (mat[0] > mat[5] && mat[0] > mat[10]) {
23 const float S = sqrt(std::max(0.f, 1.0f + mat[0] - mat[5] - mat[10])) * 2;
24 v[0] = 0.25f * S;
25 v[1] = (mat[4] + mat[1]) / S;
26 v[2] = (mat[2] + mat[8]) / S;
27 v[3] = (mat[9] - mat[6]) / S;
28 } else if (mat[5] > mat[10]) {
29 const float S = sqrt(std::max(0.f, 1.0f + mat[5] - mat[0] - mat[10])) * 2;
30 v[1] = 0.25f * S;
31 v[0] = (mat[4] + mat[1]) / S;
32 v[2] = (mat[9] + mat[6]) / S;
33 v[3] = (mat[2] - mat[8]) / S;
34 } else {
35 float S = sqrt(std::max(0.f, 1.0f + mat[10] - mat[0] - mat[5])) * 2;
36 v[2] = 0.25f * S;
37 if (fabsf(S) < 0.001f) {
38 S = 1;
39 }
40 v[0] = (mat[2] + mat[8]) / S;
41 v[1] = (mat[9] + mat[6]) / S;
42 v[3] = (mat[4] - mat[1]) / S;
43 }
44 if (v[0] * v[0] + v[1] * v[1] + v[2] * v[2] + v[3] * v[3] < 0.0001f) {
45 v[3] = 1;
46 }
47}
const GLdouble * v
Definition glcorearb.h:832