File indexing completed on 2026-04-09 07:49:39
0001 #pragma once
0002 #include <glm/glm.hpp>
0003 #include <glm/gtc/type_ptr.hpp>
0004 #include "NP.hh"
0005
0006 struct SGLM_View
0007 {
0008 glm::tvec4<float> EYE ;
0009 glm::tvec4<float> LOOK ;
0010 glm::tvec4<float> UP ;
0011 glm::tvec4<unsigned> CTRL ;
0012
0013 glm::quat getQuat() const ;
0014 std::string desc() const ;
0015
0016 template<typename T>
0017 static std::string FormatArray(const T* tt, int num, int precision );
0018 };
0019
0020 inline glm::quat SGLM_View::getQuat() const
0021 {
0022 return glm::quat_cast(glm::lookAt(glm::vec3(EYE), glm::vec3(LOOK), glm::vec3(UP)));
0023 }
0024
0025
0026 inline std::string SGLM_View::desc() const
0027 {
0028 std::stringstream ss ;
0029 ss
0030 << " EYE " << FormatArray<float>( glm::value_ptr(EYE), 4, 3 )
0031 << " LOOK " << FormatArray<float>( glm::value_ptr(LOOK), 4, 3 )
0032 << " UP " << FormatArray<float>( glm::value_ptr(UP), 4, 3 )
0033 << " CTRL " << FormatArray<unsigned>( glm::value_ptr(CTRL), 4, -1 )
0034 ;
0035 std::string str = ss.str();
0036 return str ;
0037 }
0038
0039
0040 template<typename T>
0041 std::string SGLM_View::FormatArray(const T* tt, int num, int precision )
0042 {
0043 std::stringstream ss;
0044 for(int i=0; i < num; i++) {
0045 ss << " " << std::setw(10);
0046 if(precision >= 0) ss << std::fixed << std::setprecision(precision);
0047 ss << tt[i];
0048 }
0049 return ss.str();
0050 }
0051
0052