SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLTransformNode.h
Go to the documentation of this file.
1 /**
2  * \file SLTransformNode.h
3  * \authors Jan Dellsperger
4  * \date July 2016
5  * \authors Jan Dellsperger
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9 */
10 
11 #ifndef SL_TRANSFORMATION_NODE_H
12 #define SL_TRANSFORMATION_NODE_H
13 
14 #include <SLSceneView.h>
15 
16 //-----------------------------------------------------------------------------
18 {
23 };
24 //-----------------------------------------------------------------------------
25 //! Class that holds all visible gizmo node during mouse transforms
26 /*!
27  * An SLTransformNode is added to the scenegraph during edit mode. Depending
28  on the transform type (translation, rotation or scaling) arrows or disks and
29  circles get shown or hidden. The transform node gets added and removed on the
30  fly. So the assets have to be delete in the destructor.
31  */
32 class SLTransformNode : public SLNode
33 {
34 public:
37  SLstring shaderDir);
38  ~SLTransformNode() override;
39 
40  virtual SLbool onMouseDown(SLMouseButton button,
41  SLint x,
42  SLint y,
43  SLKey mod) override;
44  virtual SLbool onMouseUp(SLMouseButton button,
45  SLint x,
46  SLint y,
47  SLKey mod) override;
48  virtual SLbool onMouseMove(SLMouseButton button,
49  SLint x,
50  SLint y,
51  SLKey mod) override;
52 
53  virtual void editMode(SLNodeEditMode editMode);
54 
55  SLNode* targetNode() { return _targetNode; }
57 
58 private:
59  SLSceneView* _sv = nullptr;
60  SLNode* _targetNode = nullptr;
61 
63 
64  SLMaterial* _matR = nullptr;
65  SLMaterial* _matG = nullptr;
66  SLMaterial* _matB = nullptr;
67  SLMaterial* _matY = nullptr;
68  SLMaterial* _matRT = nullptr;
69  SLMaterial* _matGT = nullptr;
70  SLMaterial* _matBT = nullptr;
71  SLMaterial* _matYT = nullptr;
72  SLMesh* _axisR = nullptr;
73  SLMesh* _axisG = nullptr;
74  SLMesh* _axisB = nullptr;
75  SLMesh* _lineR = nullptr;
76  SLMesh* _lineG = nullptr;
77  SLMesh* _lineB = nullptr;
78  SLMesh* _circR = nullptr;
79  SLMesh* _circG = nullptr;
80  SLMesh* _circB = nullptr;
81  SLMesh* _circY = nullptr;
82  SLMesh* _diskR = nullptr;
83  SLMesh* _diskG = nullptr;
84  SLMesh* _diskB = nullptr;
85  SLMesh* _diskY = nullptr;
86 
88  float _gizmoScale;
90  SLNode* _selectedGizmo = nullptr;
91 
92  // Translation stuff
93  SLNode* _transGizmos = nullptr;
94  SLNode* _transLineX = nullptr;
95  SLNode* _transLineY = nullptr;
96  SLNode* _transLineZ = nullptr;
97 
98  // Scale stuff
99  SLNode* _scaleGizmos = nullptr;
100  SLNode* _scaleDisk = nullptr;
101  SLNode* _scaleCirc = nullptr;
102 
103  // Rotation stuff
104  SLNode* _rotGizmos = nullptr;
105  SLNode* _rotCircX = nullptr;
106  SLNode* _rotDiskX = nullptr;
107  SLNode* _rotCircY = nullptr;
108  SLNode* _rotDiskY = nullptr;
109  SLNode* _rotCircZ = nullptr;
110  SLNode* _rotDiskZ = nullptr;
111 
112  // Node that contains all gizmos
113  SLNode* _gizmosNode = nullptr;
114 
115  bool getClosestPointsBetweenRays(const SLVec3f& ray1O,
116  const SLVec3f& ray1Dir,
117  const SLVec3f& ray2O,
118  const SLVec3f& ray2Dir,
119  SLVec3f& ray1P,
120  float& t1,
121  SLVec3f& ray2P,
122  float& t2);
123  bool getClosestPointOnAxis(const SLVec3f& pickRayO,
124  const SLVec3f& pickRayDir,
125  const SLVec3f& axisRayO,
126  const SLVec3f& axisRayDir,
127  SLVec3f& axisPoint);
128  bool rayDiscIntersect(const SLVec3f& rayO,
129  const SLVec3f& rayDir,
130  const SLVec3f& discO,
131  const SLVec3f& discN,
132  const float& distR,
133  float& t);
134  bool rayPlaneIntersect(const SLVec3f& rayO,
135  const SLVec3f& rayDir,
136  const SLVec3f& discO,
137  const SLVec3f& discN,
138  float& t);
139 
140  bool isCCW(const SLVec2f& a, const SLVec2f& b, const SLVec2f& c);
141  void setDrawBitRecursive(SLuint bit, SLNode* node, bool value);
142  void lookAt(SLNode* node, SLCamera* camera);
143 };
144 //-----------------------------------------------------------------------------
145 #endif
unsigned int SLuint
Definition: SL.h:171
bool SLbool
Definition: SL.h:175
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
SLMouseButton
Mouse button codes.
Definition: SLEnums.h:98
SLKey
Keyboard key codes enumeration.
Definition: SLEnums.h:16
SLNodeEditMode
@ NodeEditMode_Translate
@ NodeEditMode_Scale
@ NodeEditMode_None
@ NodeEditMode_Rotate
Active or visible camera node class.
Definition: SLCamera.h:54
Defines a standard CG material with textures and a shader program.
Definition: SLMaterial.h:56
An SLMesh object is a triangulated mesh, drawn with one draw call.
Definition: SLMesh.h:134
SLNode represents a node in a hierarchical scene graph.
Definition: SLNode.h:147
SceneView class represents a dynamic real time 3D view onto the scene.
Definition: SLSceneView.h:69
Class that holds all visible gizmo node during mouse transforms.
virtual SLbool onMouseUp(SLMouseButton button, SLint x, SLint y, SLKey mod) override
onMouseUp event handler during editing interaction
bool getClosestPointsBetweenRays(const SLVec3f &ray1O, const SLVec3f &ray1Dir, const SLVec3f &ray2O, const SLVec3f &ray2Dir, SLVec3f &ray1P, float &t1, SLVec3f &ray2P, float &t2)
SLSceneView * _sv
bool getClosestPointOnAxis(const SLVec3f &pickRayO, const SLVec3f &pickRayDir, const SLVec3f &axisRayO, const SLVec3f &axisRayDir, SLVec3f &axisPoint)
SLNode * _transLineZ
virtual SLbool onMouseDown(SLMouseButton button, SLint x, SLint y, SLKey mod) override
onMouseDown event handler during editing interaction
SLNode * targetNode()
SLNodeEditMode _editMode
SLTransformNode(SLSceneView *sv, SLNode *targetNode, SLstring shaderDir)
Construct a new SLTransformNode::SLTransformNode object *.
SLNode * _targetNode
SLNode * _transLineY
virtual SLbool onMouseMove(SLMouseButton button, SLint x, SLint y, SLKey mod) override
onMouseMove event handler during editing interaction
bool rayPlaneIntersect(const SLVec3f &rayO, const SLVec3f &rayDir, const SLVec3f &discO, const SLVec3f &discN, float &t)
SLMaterial * _matB
SLMaterial * _matBT
~SLTransformNode() override
SLNode * _transLineX
SLNodeEditMode editMode()
SLMaterial * _matRT
void setDrawBitRecursive(SLuint bit, SLNode *node, bool value)
SLNode * _transGizmos
SLMaterial * _matYT
SLMaterial * _matY
bool rayDiscIntersect(const SLVec3f &rayO, const SLVec3f &rayDir, const SLVec3f &discO, const SLVec3f &discN, const float &distR, float &t)
SLNode * _selectedGizmo
SLMaterial * _matGT
bool isCCW(const SLVec2f &a, const SLVec2f &b, const SLVec2f &c)
SLNode * _scaleGizmos
SLMaterial * _matR
void lookAt(SLNode *node, SLCamera *camera)
SLVec3f _hitCoordinate
SLMaterial * _matG
T mod(T a, T b)
Definition: Utils.h:250