File: TTT.h

package info (click to toggle)
pymol 3.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 74,084 kB
  • sloc: cpp: 482,660; python: 89,328; ansic: 29,512; javascript: 6,792; sh: 84; makefile: 25
file content (182 lines) | stat: -rw-r--r-- 4,251 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#pragma once

#include <glm/vec3.hpp>
#include <glm/mat4x4.hpp>
#include <glm/gtc/quaternion.hpp>

struct CViewElem;

namespace pymol
{
class TTT
{
  glm::vec3 m_pretranslation{}; // e.g. inverted origin
  glm::quat m_rotation{1.0f, 0.0f, 0.0f, 0.0f};
  glm::vec3 m_posttranslation{};

public:
  TTT() = default;

  /**
   * Constructs a TTT Matrix from components
   * @param pre origin point
   * @param rot rotation quaternion
   * @param post translation vector
   */
  TTT(glm::vec3 pre, glm::quat rot, glm::vec3 post);

  /**
   * Gets translation-before-rotation vector
   * @return pretranslation vector
   */
  glm::vec3 getPreTranslation() const;

  /**
   * Gets translation-after-rotation vector
   * @return pretranslation vector
   */
  glm::vec3 getPostTranslation() const;

  /**
   * Gets rotation matrix
   * @return rotation matrix
   */
  glm::quat getRotation() const;

  /**
   * Retrives the homogenous version of the TTT matrix (Column Major)
   * @return homogenous 4x4 matrix
   * @note replaces convertTTTfC44f (column major of convertTTTfR44f)
   */
  glm::mat4 getHomogenousMatrix() const;

  /**
   * Matrix multiplies two TTT matrices
   * @return result of TTT matrix multiplication
   * @note replaces combineTTT44f44f
   */
  TTT operator*(const TTT& other) const;

  /**
   * Resets TTT to identity
   * @note replaces identity44f
   */
  void reset();

  /**
   * Translates TTT
   * @param vec translation vector
   */
  void translate(const glm::vec3& vec);

  /**
   * Translates TTT
   * @param vec translation vector
   */
  void translate(const float* vec);

  /**
   * Set TTT origin
   * @param ori origin point
   */
  void originate(const glm::vec3& vec);

  /**
   * Set TTT origin
   * @param ori origin point
   */
  void originate(const float* vec);

  /**
   * Rotate TTT
   * @param axis normalized axis
   * @param angRad angle to rotate by (as radians)
   */
  void rotate(float angRad, const glm::vec3& axis);

  /**
   * Sets translation
   * @param trans new translation vector
   */
  void setTranslation(const glm::vec3& trans);

  /**
   * Transforms a position
   * @param mat TTT matrix used to transform
   * @param pos position to transform
   * @return transformed position
   * @note replaces transformTTT44f3f
   */
  glm::vec3 transform(const glm::vec3& pos);

  /**
   * Transforms a position
   * @param vec position to be transformed
   * @param[out] pos_out transformed position
   * @note replaces transformTTT44f3f
   */
  void transform(const float* pos, float* pos_out);

  /**
   * Transforms a direction/vector
   * @return transformed direction/vector
   * @note replaces transform_normalTTT44f3f
   */
  glm::vec3 transform_vector(const glm::vec3& vec);

  /**
   * Transforms a direction/vector
   * @param mat TTT matrix used to transform
   * @param vec vector to transform
   * @param[out] vec_out direction/vector
   * @note replaces transform_normalTTT44f3f
   */
  void transform_vector(const float* vec, float* vec_out);

  /**
   * Retrieves legacy TTT Matrix for serialization, etc...
   * @param mat TTT
   * @return legacy TTT matrix (Row Major)
   */
  static glm::mat4 as_pymol_2_legacy(const TTT& mat);

  /**
   * Constructs TTT from legacy TTT Matrix for serialization, etc...
   * @param ttt legacy TTT matrix (Row-major)
   * @return TTT
   */
  static TTT from_pymol_2_legacy(const float* ttt);

  /**
   * Constructs View elem from TTT
   * @param ttt TTT
   * @return View elem
   */
  static CViewElem to_view_elem(const TTT& ttt);

  /**
   * Constructs TTT from View elem
   * @param ttt TTT
   * @return TTT
   */
  static TTT from_view_elem(const CViewElem& ttt);

  /**
   * Gets TTT Matrix with a rotation about an axis from an origin
   * @param angRad rotation angle (as radians)
   * @param dir direction to rotate around
   * @param origin origin of rotation
   * @note replaces get_rotation_about3f3fTTTf
   */
  static TTT rotation_about_with_origin(
      float angRad, const glm::vec3& dir, const glm::vec3& origin);
};

/**
 * Performs a lerp between two TTT Matrices
 * @note internal quaternion is sphercially interpolated
 * @return interpolated TTT matrix
 */
TTT lerp(const TTT& a, const TTT& b, float t);

} // namespace pymol