OROCHI
 
Loading...
Searching...
No Matches
GxHandle.h
Go to the documentation of this file.
1//===========================================================================
11//===========================================================================
12#pragma once
13
14#if GX_DEVELOP
15
16GX_CORE_NAMESPACE_BEGIN()
17
18//===========================================================================
20//===========================================================================
21class GxHandle : public GxClassBase
22{
23 //-------------------------------------------------------------
25 //-------------------------------------------------------------
27public:
28 // RTTI定義
29 GX_RTTI_ABSTRACT_CLASS(GxHandle, GxClassBase)
30 // GxClassBase継承クラス用禁止宣言
31 GX_PROHIBIT_CLASS_BASE( GxHandle )
32
33 // new, delete定義
34 GX_OPERATOR_NEW_DELETE_USE_ARRAY(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
35
36
37 enum class HANDLE_MODE
38 {
39 STATE,
40 TRANSLATE,
41 ROTATE,
42 SCALE,
43 MAX,
44 };
45#if GX_DEVELOP
47 GX_ENUM_TABLE_MAX(HANDLE_MODE)
48#endif //GX_DEVELOP
49
51 enum HANDLE_TYPE_FLAG
52 {
53 HANDLE_TYPE_STATE = 0,
54 HANDLE_TYPE_TRANSLATE = 0x01 << 0,
55 HANDLE_TYPE_ROTATE = 0x01 << 1,
56 HANDLE_TYPE_SCALE = 0x01 << 2,
57
58 HANDLE_TYPE_ALL = HANDLE_TYPE_TRANSLATE | HANDLE_TYPE_ROTATE | HANDLE_TYPE_SCALE,
59 };
60
62 enum class HANDLE_RESULT
63 {
64 EXIT,
65 WAIT,
66 MANIPULATE,
67 };
68
69 static const GxVector3 BOX_EXTENT;
70 static const f32 AXIS_LENGTH;
71
72 //===========================================================================
74 //===========================================================================
75 class GxUiBase : public GxClassBase
76 {
77 //-------------------------------------------------------------
79 //-------------------------------------------------------------
81 public:
82 // RTTI定義
83 GX_RTTI_ABSTRACT_CLASS(GxUiBase, GxClassBase)
84 // new, delete定義
85 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
86 // GxClassBase継承クラス用禁止宣言
88
89
90 enum class STATE
91 {
92 WAITING,
93 MANIPULATING,
94 MAX,
95 };
96#if GX_DEVELOP
98 GX_ENUM_TABLE_MAX(STATE)
99#endif //GX_DEVELOP
100
102 enum class AXIS_TYPE
103 {
104 X = 0,
105 Y,
106 _2D_MAX,
107 Z = _2D_MAX,
108 _3D_MAX,
109 ALL = _3D_MAX,
110 SELECT_MAX,
111 EYE = SELECT_MAX,
112 NONE,
113 MAX,
114 };
115#if GX_DEVELOP
117 GX_ENUM_TABLE_MAX(AXIS_TYPE)
118#endif //GX_DEVELOP
119
120 static const GxColor COLOR_AXIS_X_HIGHLIGHT;
121 static const GxColor COLOR_AXIS_Y_HIGHLIGHT;
122 static const GxColor COLOR_AXIS_Z_HIGHLIGHT;
123 static const GxColor COLOR_AXIS_ALL;
124 static const GxColor COLOR_AXIS_ALL_HIGHLIGHT;
125 static const GxColor COLOR_AXIS_SELECTED;
126 static const GxColor COLOR_AXIS_EYE;
127 static const GxColor COLOR_AXIS_EYE_HIGHLIGHT;
128 static const GxColor COLOR_AXIS_OLD;
129
130 static const GxPrimitiveMaterial MATERIAL[2];
131
133 //-------------------------------------------------------------
135 //-------------------------------------------------------------
137
139 GxUiBase(GxHandle* pHandle);
140
142 ~GxUiBase(void) override;
143
145 //-------------------------------------------------------------
147 //-------------------------------------------------------------
149 public:
151 virtual GxHandle::HANDLE_RESULT update(void);
152
154 virtual void render(void);
155
157 constexpr void resetState(void) { _state = STATE::WAITING; _manipulatingAxis = AXIS_TYPE::NONE; }
158
160 virtual void addPropertyTable(GxPropertyTable& propertyTable);
161
162 protected:
165 GX_FORCE_INLINE GxMatrixAffine getParentWorldMatrix(void) const { return _pParentWorldMatrixAffine ? *_pParentWorldMatrixAffine : (_pParentWorldMatrix ? GxMatrixAffine(*_pParentWorldMatrix) : GxMatrixAffine::IDENTITY); }
166
167 public:
169 GxMatrixAffine getWorldMatrix(void) const;
170 protected:
171
173 GxVector3 getHandlingPlaneNormal(const GxMatrixAffine& matrix) const;
174
176 //-------------------------------------------------------------
178 //-------------------------------------------------------------
180 public:
182 virtual void setParam43(GxVector3* pOffset, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrixAffine* pParentWorldMatrix, GxUnit2DBase* pUnit2D);
184 virtual void setParam44(GxVector3* pOffset, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrix44* pParentWorldMatrix, GxUnit2DBase* pUnit2D);
186 constexpr GxVector3* getControlOffset(void) const { return _pOffset; }
188 constexpr GxQuaternion* getControlQuaternion(void) const { return _pQuaternion; }
190 constexpr GxVector3* getControlScale(void) const { return _pScale; }
192 GX_FORCE_INLINE b32 isOnMouse(void) const { return _axisUnderMouse != AXIS_TYPE::NONE; }
193
195 constexpr void setAxisDrawLength(const f32 length) { _axisDrawLength = length; }
196
198 b32 isHitRect( const GxVector2& size, const GxVector2& centerPosition, f32 rotate, const GxVector2& mousePosition ) const;
199
200 protected:
203 constexpr void setState(STATE state) { _state = state; }
206 constexpr STATE getState(void) const { return _state; }
209 constexpr void setManipulatingAxis(AXIS_TYPE axis) { _manipulatingAxis = axis; }
212 constexpr AXIS_TYPE getManipulatingAxis(void) { return _manipulatingAxis; }
215 GX_FORCE_INLINE b32 is3D(void) const { return !_pHandle->_is2D; }
216
218 //-------------------------------------------------------------
220 //-------------------------------------------------------------
222 protected:
223 GxVector3* _pOffset;
224 GxQuaternion* _pQuaternion;
225 GxVector3* _pScale;
226 GxUnit2DBase* _pUnit2D;
227 // 以下の2つは排他とする
228 const GxMatrixAffine* _pParentWorldMatrixAffine;
229 const GxMatrix44* _pParentWorldMatrix;
230
231 AXIS_TYPE _axisUnderMouse;
232 f32 _axisDrawLength;
233
234 private:
235 STATE _state;
236 AXIS_TYPE _manipulatingAxis;
237 GxHandle* _pHandle;
238
240 };
241
242private:
243 //===========================================================================
246 //===========================================================================
247 class GxUiTranslate : public GxUiBase
248 {
249 //-------------------------------------------------------------
251 //-------------------------------------------------------------
253 public:
254 // RTTI定義
255 GX_RTTI_ABSTRACT_CLASS(GxUiTranslate, GxUiBase)
256 // GxClassBase継承クラス用禁止宣言
257 GX_PROHIBIT_CLASS_BASE(GxUiTranslate)
258
259
260 static const GxVector3 DEFAULT_STEP;
262 static const GxVector3 DEFAULT_SNAP;
264 static const f32 RAY_CHECK_LENGTH;
265
267 //-------------------------------------------------------------
269 //-------------------------------------------------------------
271
273 GxUiTranslate(GxHandle* pHandle);
274
276 ~GxUiTranslate(void) override;
277
279 //-------------------------------------------------------------
281 //-------------------------------------------------------------
283 public:
285 GxHandle::HANDLE_RESULT update(void) override;
286
288 void render(void) override;
289
291 void addPropertyTable(GxPropertyTable& propertyTable) override;
292
294 GX_FORCE_INLINE GxVector3 getOffset(void) const { return _addVector; }
295
297 GX_FORCE_INLINE void setLocal(b32 isLocal) { _localFlag = isLocal; }
298
299 protected:
301 AXIS_TYPE getAxisUnderMouse(void);
302
304 void eventTraceBackGroundOn(void);
306 void eventTraceBackGroundOff(void);
308 void eventPositionInitializeZero(void);
310 void eventHitBackGroundPlusX(void);
312 void eventHitBackGroundMinusX(void);
314 void eventHitBackGroundPlusY(void);
316 void eventHitBackGroundMinusY(void);
318 void eventHitBackGroundPlusZ(void);
320 void eventHitBackGroundMinusZ(void);
321
323 //-------------------------------------------------------------
325 //-------------------------------------------------------------
327 private:
328 GxVector3 _dragWorldPosition;
329 GxVector3 _handlingPlaneNormal;
330 GxVector3 _dragOffset;
331 GxVector3 _addVector;
332
333 b32 _isHitBackGround;
334
335 b32 _isUseStep;
336 GxVector3 _step;
337 b32 _isUseSnap;
338 GxVector3 _snap;
339
340 b32 _localFlag;
341
343 };
344
345 //===========================================================================
347 //===========================================================================
348 class GxUiRotate : public GxUiBase
349 {
350 //-------------------------------------------------------------
352 //-------------------------------------------------------------
354 public:
355 // RTTI定義
356 GX_RTTI_ABSTRACT_CLASS(GxUiRotate, GxUiBase)
357 // GxClassBase継承クラス用禁止宣言
358 GX_PROHIBIT_CLASS_BASE(GxUiRotate)
359
360
361 static const f32 RADIUS_RATIO_AXIS_EYE;
363 static const f32 RADIUS_RATIO_AXIS_ALL;
365 static constexpr u32 CIRCLE_DIVIDE = 20;
366
368 //-------------------------------------------------------------
370 //-------------------------------------------------------------
372
374 GxUiRotate(GxHandle* pHandle);
375
377 ~GxUiRotate(void) override;
378
380 //-------------------------------------------------------------
382 //-------------------------------------------------------------
384 public:
386 static GxGuiBase* createGui(GxProperty& property, GxTypedObject* pOwner, const GxRtti& rtti, u32 index = 0);
387
389 GxHandle::HANDLE_RESULT update(void) override;
390
392 void render(void) override;
393
395 GX_FORCE_INLINE GxQuaternion getOffset(void) const { return _addQuaternion; }
396
397 protected:
399 // note:未完成
400 AXIS_TYPE getAxisUnderMouse(void);
401
403 b32 checkHitCircleSegment(const GxVector3& rayStart, const GxVector3& rayEnd, const GxVector3& center, const GxVector3& axis, const f32 radius, GxVector3& hitPosition);
404
406 void updateAxis(void);
407
409 void addPropertyTable(GxPropertyTable& propertyTable) override;
410
412 void eventRotateInitializeIdentity(void);
413
414 private:
416 // note:長いのでサブルーチン化した
417 // note:未完成
418 GxVector3 getDirectionCenterToMouse(const AXIS_TYPE type);
419
421 //-------------------------------------------------------------
423 //-------------------------------------------------------------
425 public:
427 void setParam43(GxVector3* pOffset, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrixAffine* pParentWorldMatrix, GxUnit2DBase* pUnit2D) override;
429 void setParam44(GxVector3* pOffset, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrix44* pParentWorldMatrix, GxUnit2DBase* pUnit2D) override;
430
432 void setSelectAxis(b32 isSelectAxis, AXIS_TYPE type);
433
435 //-------------------------------------------------------------
437 //-------------------------------------------------------------
439 private:
440 GxVector3 _mouseWorldPosition;
441 GxVector3 _dragDirection;
442 GxVector3 _currentDirection;
443 GxQuaternion _dragQuaternion;
444 GxVector3 _axis[static_cast<u32>(AXIS_TYPE::MAX)];
445 f32 _incrementRadian;
446 GxQuaternion _addQuaternion;
447
448 b32 _isUseStep;
449 f32 _step;
450 b32 _isUseSnap;
451 f32 _snap;
452
453 b32 _isSelectAxis;
454 AXIS_TYPE _selectAxis;
455
457 };
458
459 //===========================================================================
461 //===========================================================================
462 class GxUiScale : public GxUiBase
463 {
464 //-------------------------------------------------------------
466 //-------------------------------------------------------------
468 public:
469 // RTTI定義
470 GX_RTTI_ABSTRACT_CLASS(GxUiScale, GxUiBase)
471 // GxClassBase継承クラス用禁止宣言
472 GX_PROHIBIT_CLASS_BASE(GxUiScale)
473
474
475 static const f32 SCALE_MIN;
477 static const f32 SCALE_MAX;
478
480 //-------------------------------------------------------------
482 //-------------------------------------------------------------
484
486 GxUiScale(GxHandle* pHandle);
487
489 ~GxUiScale(void) override;
490
492 //-------------------------------------------------------------
494 //-------------------------------------------------------------
496 public:
498 GxHandle::HANDLE_RESULT update(void) override;
499
501 void render(void) override;
502
504 GX_FORCE_INLINE GxVector3 getOffset(void) const { return _addVector; }
505
507 //-------------------------------------------------------------
509 //-------------------------------------------------------------
511 protected:
513 // 中央(-1.0) <-->ハンドル位置(0.0) <--> 1.0...
514 f32 getGuiAxisNormalized(const GxPoint2& mousePosition, AXIS_TYPE axisType, f32 value);
515
517 AXIS_TYPE getAxisUnderMouse(void);
518
520 //-------------------------------------------------------------
522 //-------------------------------------------------------------
524 private:
525 GxVector3 _dragWorldPosition;
526 GxVector3 _handlingPlaneNormal;
527 GxVector3 _dragScale;
528 GxVector3 _dragGuiAdd;
529 GxVector3 _addVector;
530 b32 _isUseStep;
531 f32 _step;
532 b32 _isUseSnap;
533 f32 _snap;
534
536 };
537
539 //-------------------------------------------------------------
541 //-------------------------------------------------------------
543public:
545 GxHandle(void);
546
548 void initialize( const u32 handleTypeFlag );
549
551 ~GxHandle(void) override {}
552
554 //-------------------------------------------------------------
556 //-------------------------------------------------------------
558
560 HANDLE_RESULT update( void );
561
563 void render( void );
564
565protected:
567 void stretchSize(void);
569 void shrinkSize(void);
570
572 //-------------------------------------------------------------
574 //-------------------------------------------------------------
576public:
578 void setIsEnable( b32 isEnable );
580 GX_FORCE_INLINE void set2D( void ) { _is2D = true; }
581
583 void setParam(GxVector3* pPosition, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrixAffine* pParentWorldMatrix = nullptr, GxUnit2DBase* pUnit2D = nullptr);
585 void setParam(GxVector3* pPosition, GxQuaternion* pQuaternion, GxVector3* pScale, const GxMatrix44* pParentWorldMatrix, GxUnit2DBase* pUnit2D = nullptr);
586
588 void setMode( HANDLE_MODE mode );
590 void setLocalTranslate(b32 isLocal);
591
592 //< 操作できる回転軸を設定
593 void setSelRotateAxis(b32 isSelAxis, GxUiBase::AXIS_TYPE type);
594
596 GxMatrixAffine getWorldMatrix( void );
597
599 GX_FORCE_INLINE b32 isEnable( void ) const { return _isEnable; }
601 constexpr HANDLE_MODE getMode( void ) const { return _mode; }
603 GxVector3* getControlOffset( void );
605 GxQuaternion* getControlQuaternion( void );
607 GxVector3* getControlScale( void );
609 void createMenu( const GxPoint2& position );
611 b32 isOnMouse( void ) const;
612
614 static f32 getFloor( f32 value, const f32 step );
616 static GxMatrixAffine getUnScale(const GxMatrixAffine& inMatix);
617
619 void setAxisDrawLength( const f32 length );
621 GX_FORCE_INLINE f32 getAxisDrawLength( void ) const { return _axisDrawLength; }
622
624 GxVector3 getOffsetTranslate(void) const;
626 GxQuaternion getOffsetRotate(void) const;
628 GxVector3 getOffsetScale(void) const;
629
631 //-------------------------------------------------------------
633 //-------------------------------------------------------------
635private:
636 b32 _isEnable;
637 b32 _isDisp;
638 b32 _is2D;
639 HANDLE_MODE _mode;
640 HANDLE_MODE _baseMode;
641 GxUiBase* _pHandleUi[static_cast<s32>(HANDLE_MODE::MAX)];
642 GxUiBase _handleUiState;
643 GxUiTranslate _handleUiTranslate;
644 GxUiRotate _handleUiRotate;
645 GxUiScale _handleUiScale;
646
647 static f32 _axisDrawLength;
648
650};
651
652//===========================================================================
655//===========================================================================
656class GxHandleConfig : public GxClassBase
657{
658 //-----------------------------------------------------------
660 //-----------------------------------------------------------
662public:
663 // RTTI定義
664 GX_RTTI_CLASS(GxHandleConfig, GxClassBase)
665 // new, delete定義
666 GX_OPERATOR_NEW_DELETE(GxAllocatorList::ALLOCATOR_TYPE::DEVELOP)
667
668
669 //-----------------------------------------------------------
671 //-----------------------------------------------------------
673
675 GxHandleConfig(void);
676
678 //-----------------------------------------------------------
680 //-----------------------------------------------------------
682
684 void loadJson(const GxJson::GxJsonNode& jsonNode);
685 // コピー
686 GxHandleConfig& operator = (const GxHandleConfig& value);
687 // 参照を設定
688 GX_FORCE_INLINE void set(GxHandleConfig& value) { *this = value; }
689 // デフォルトにリセット
690 void setDefault(void);
691
693 //-----------------------------------------------------------
695 //-----------------------------------------------------------
697
698 f32 _translateStep;
699 f32 _translateShiftStep;
700 f32 _rotateStep;
701 f32 _rotateShiftStep;
702 f32 _scaleStep;
703 f32 _scaleShiftStep;
704
706};
707
708GX_CORE_NAMESPACE_END()
709
710#endif // GX_DEVELOP
#define GX_PROHIBIT_CLASS_BASE(__CLASS__)
GxClassBase継承の禁止宣言
Definition GxBase.h:240
@ MAX
定義数
void GxTypedObject
その他
Definition GxDefine.h:213
@ NONE
何もしない
@ IDENTITY
基礎値で初期化
@ X
X.
@ Z
Z.
@ Y
Y.
@ _3D_MAX
汎用的な3Dビューの最大
オブジェクト基底クラス
Definition GxBase.h:88
constexpr GxClassBaseRoot & operator=(const GxClassBaseRoot &)
代入演算子
Definition GxBase.h:64
JSON解析用ノード
Definition GxJson.h:108
プロパティクラス
Definition GxProperty.h:48
プロパティテーブルクラス
Definition GxProperty.h:1641
実行時型情報クラス
Definition GxRtti.h:154
2D基礎ユニットクラス
Definition GxUnit2DBase.h:24
Definition GxColor.h:21
4×4行列(行優先)
Definition GxMatrix.h:607
アフィン変換行列(行優先)
Definition GxMatrix.h:330
座標
Definition GxStruct.h:867
プリミティブマテリアル
Definition GxPrimitive.h:103
クォータニオン
Definition GxQuaternion.h:19
2次元ベクトル
Definition GxVector.h:34
3次元ベクトル
Definition GxVector.h:245
32bitブーリアン
Definition GxDefine.h:173