@@ -63,6 +63,8 @@ Mesh *Handles::s_Rectangle = nullptr;
63
63
Mesh *Handles::s_Box = nullptr ;
64
64
Mesh *Handles::s_Bone = nullptr ;
65
65
66
+ Texture *Handles::s_Corner = nullptr ;
67
+
66
68
enum {
67
69
AXIS,
68
70
SCALE,
@@ -107,6 +109,10 @@ void Handles::init() {
107
109
}
108
110
}
109
111
112
+ if (s_Corner == nullptr ) {
113
+ s_Corner = Engine::loadResource<Texture>(" .embedded/corner.png" );
114
+ }
115
+
110
116
if (s_Lines == nullptr ) {
111
117
s_Lines = Engine::objectCreate<Mesh>(" Lines" );
112
118
s_Lines->makeDynamic ();
@@ -667,6 +673,7 @@ float Handles::rotationTool(const Vector3 &position, const Quaternion &rotation,
667
673
}
668
674
669
675
Vector3 Handles::scaleTool (const Vector3 &position, const Quaternion &rotation, bool locked) {
676
+ Vector3 result;
670
677
if (ICommandBuffer::isInited ()) {
671
678
Camera *camera = Camera::current ();
672
679
if (camera) {
@@ -787,51 +794,150 @@ Vector3 Handles::scaleTool(const Vector3 &position, const Quaternion &rotation,
787
794
}
788
795
s_Color = s_Normal;
789
796
}
797
+
798
+ Plane plane;
799
+ plane.point = position;
800
+ plane.normal = camera->actor ()->transform ()->quaternion () * Vector3 (0 .0f , 0 .0f , 1 .0f );
801
+ if (s_Axes == AXIS_X) {
802
+ plane.normal = Vector3 (0 .0f , plane.normal .y , plane.normal .z );
803
+ } else if (s_Axes == AXIS_Z) {
804
+ plane.normal = Vector3 (plane.normal .x , plane.normal .y , 0 .0f );
805
+ } else if (s_Axes == (AXIS_X | AXIS_Z)) {
806
+ plane.normal = Vector3 (0 .0f , 1 .0f , 0 .0f );
807
+ } else if (s_Axes == (AXIS_X | AXIS_Y)) {
808
+ plane.normal = Vector3 (0 .0f , 0 .0f , 1 .0f );
809
+ } else if (s_Axes == (AXIS_Z | AXIS_Y)) {
810
+ plane.normal = Vector3 (1 .0f , 0 .0f , 0 .0f );
811
+ } else if (s_Axes == AXIS_Y || s_Axes == (AXIS_X | AXIS_Y | AXIS_Z)) {
812
+ plane.normal = Vector3 (plane.normal .x , 0 .0f , plane.normal .z );
813
+ }
814
+ plane.normal .normalize ();
815
+ plane.d = plane.normal .dot (plane.point );
816
+
817
+ Ray ray = camera->castRay (s_Mouse.x , s_Mouse.y );
818
+ Vector3 point;
819
+ ray.intersect (plane, &point, true );
820
+ if (s_Axes & AXIS_X) {
821
+ result.x = point.x ;
822
+ }
823
+ if (s_Axes & AXIS_Y) {
824
+ result.y = point.y ;
825
+ }
826
+ if (s_Axes & AXIS_Z) {
827
+ result.z = point.z ;
828
+ }
790
829
}
791
- return Vector3 (s_Mouse, 1.0 ) * 500 ;
830
+ return result ;
792
831
}
793
832
794
- void Handles::rectTool (const Vector3 &position, const Vector2 &size, const Quaternion &rotation, bool locked) {
833
+ Vector3 Handles::rectTool (const Vector3 &position, const Vector3 &box, int &axis, bool locked) {
834
+ Vector3 result;
795
835
if (ICommandBuffer::isInited ()) {
796
- Matrix4 model (position, rotation, Vector3 (1 .0f ));
797
-
798
- Vector3 tr (size.x * 0 .5f , size.y * 0 .5f , 0 .0f );
799
- Vector3 tl (size.x *-0 .5f , size.y * 0 .5f , 0 .0f );
800
- Vector3 br (size.x * 0 .5f , size.y *-0 .5f , 0 .0f );
801
- Vector3 bl (size.x *-0 .5f , size.y *-0 .5f , 0 .0f );
802
-
803
- drawRectangle (position, rotation, size.x , size.y );
804
-
805
- if (!locked) {
806
- float sence = Handles::s_Sense * 0 .25f ;
807
-
808
- Handles::s_Axes = 0 ;
809
- if (HandleTools::distanceToPoint (model, tr) <= sence) {
810
- Handles::s_Axes = Handles::POINT_T | Handles::POINT_R;
811
- } else if (HandleTools::distanceToPoint (model, tl) <= sence) {
812
- Handles::s_Axes = Handles::POINT_T | Handles::POINT_L;
813
- } else if (HandleTools::distanceToPoint (model, br) <= sence) {
814
- Handles::s_Axes = Handles::POINT_B | Handles::POINT_R;
815
- } else if (HandleTools::distanceToPoint (model, bl) <= sence) {
816
- Handles::s_Axes = Handles::POINT_B | Handles::POINT_L;
817
- } else if (HandleTools::distanceToPath (model, {tr, tl}) <= sence) {
818
- Handles::s_Axes = Handles::POINT_T;
819
- } else if (HandleTools::distanceToPath (model, {br, bl}) <= sence) {
820
- Handles::s_Axes = Handles::POINT_B;
821
- } else if (HandleTools::distanceToPath (model, {tr, br}) <= sence) {
822
- Handles::s_Axes = Handles::POINT_R;
823
- } else if (HandleTools::distanceToPath (model, {tl, bl}) <= sence) {
824
- Handles::s_Axes = Handles::POINT_L;
836
+ Camera *camera = Camera::current ();
837
+
838
+ if (camera) {
839
+ axis = Handles::AXIS_Z;
840
+
841
+ Plane plane;
842
+ plane.normal = Vector3 (0 .0f , 0 .0f , 1 .0f );
843
+
844
+ Vector2 size (box.x , box.y );
845
+
846
+ Quaternion q;
847
+
848
+ Vector3 normal = camera->actor ()->transform ()->quaternion () * plane.normal ;
849
+ normal .normalize ();
850
+ if (abs (normal .x ) > abs (normal .z )) {
851
+ axis = Handles::AXIS_X;
852
+ plane.normal = Vector3 (1 .0f , 0 .0f , 0 .0f );
853
+ size = Vector2 (box.z , box.y );
854
+ q = Quaternion (Vector3 (0 .0f , 90 .0f , 0 .0f ));
855
+ }
856
+ if (abs (normal .y ) > abs (normal .x ) && abs (normal .y ) > abs (normal .x )) {
857
+ axis = Handles::AXIS_Y;
858
+ plane.normal = Vector3 (0 .0f , 1 .0f , 0 .0f );
859
+ size = Vector2 (box.x , box.z );
860
+ q = Quaternion (Vector3 (90 .0f , 0 .0f , 0 .0f ));
861
+ }
862
+
863
+ plane.point = position;
864
+ plane.d = plane.normal .dot (plane.point );
865
+
866
+
867
+ Matrix4 model (position, q, Vector3 (1 .0f ));
868
+
869
+ Vector3 tr (size.x * 0 .5f , size.y * 0 .5f , 0 .0f );
870
+ Vector3 tl (size.x *-0 .5f , size.y * 0 .5f , 0 .0f );
871
+ Vector3 br (size.x * 0 .5f , size.y *-0 .5f , 0 .0f );
872
+ Vector3 bl (size.x *-0 .5f , size.y *-0 .5f , 0 .0f );
873
+
874
+ drawRectangle (position, q, size.x , size.y );
875
+
876
+ Transform *t = camera->actor ()->transform ();
877
+ normal = position - t->position ();
878
+ float scale = 1 .0f ;
879
+ if (!camera->orthographic ()) {
880
+ scale = normal .length ();
825
881
} else {
826
- Camera *camera = Camera::current ();
827
- if (camera) {
882
+ scale = camera->orthoSize ();
883
+ }
884
+ scale *= (CONTROL_SIZE / s_Screen.y );
885
+
886
+ drawBillboard (model * tr, Vector2 (scale * 0 .05f ), s_Corner);
887
+ drawBillboard (model * tl, Vector2 (scale * 0 .05f ), s_Corner);
888
+ drawBillboard (model * br, Vector2 (scale * 0 .05f ), s_Corner);
889
+ drawBillboard (model * bl, Vector2 (scale * 0 .05f ), s_Corner);
890
+
891
+ if (!locked) {
892
+ float sence = Handles::s_Sense * 0 .25f ;
893
+
894
+ Handles::s_Axes = 0 ;
895
+ if (HandleTools::distanceToPoint (model, tr) <= sence) {
896
+ Handles::s_Axes = Handles::POINT_T | Handles::POINT_R;
897
+ } else if (HandleTools::distanceToPoint (model, tl) <= sence) {
898
+ Handles::s_Axes = Handles::POINT_T | Handles::POINT_L;
899
+ } else if (HandleTools::distanceToPoint (model, br) <= sence) {
900
+ Handles::s_Axes = Handles::POINT_B | Handles::POINT_R;
901
+ } else if (HandleTools::distanceToPoint (model, bl) <= sence) {
902
+ Handles::s_Axes = Handles::POINT_B | Handles::POINT_L;
903
+ } else if (HandleTools::distanceToPath (model, {tr, tl}) <= sence) {
904
+ Handles::s_Axes = Handles::POINT_T;
905
+ } else if (HandleTools::distanceToPath (model, {br, bl}) <= sence) {
906
+ Handles::s_Axes = Handles::POINT_B;
907
+ } else if (HandleTools::distanceToPath (model, {tr, br}) <= sence) {
908
+ Handles::s_Axes = Handles::POINT_R;
909
+ } else if (HandleTools::distanceToPath (model, {tl, bl}) <= sence) {
910
+ Handles::s_Axes = Handles::POINT_L;
911
+ } else {
828
912
Ray ray = camera->castRay (Handles::s_Mouse.x , Handles::s_Mouse.y );
829
913
if (ray.intersect (model * tr, model * tl, model * bl, nullptr , true ) ||
830
914
ray.intersect (model * bl, model * br, model * tr, nullptr , true )) {
831
915
Handles::s_Axes = Handles::POINT_B | Handles::POINT_T | Handles::POINT_L | Handles::POINT_R;
832
916
}
833
917
}
834
918
}
919
+
920
+ Ray ray = camera->castRay (Handles::s_Mouse.x , Handles::s_Mouse.y );
921
+ Vector3 point;
922
+
923
+ ray.intersect (plane, &point, true );
924
+ if (Handles::s_Axes & Handles::POINT_L || Handles::s_Axes & Handles::POINT_R) {
925
+ switch (axis) {
926
+ case Handles::AXIS_X: result.z = point.z ; break ;
927
+ case Handles::AXIS_Y: result.x = point.x ; break ;
928
+ case Handles::AXIS_Z: result.x = point.x ; break ;
929
+ default : break ;
930
+ }
931
+ }
932
+ if (Handles::s_Axes & Handles::POINT_T || Handles::s_Axes & Handles::POINT_B) {
933
+ switch (axis) {
934
+ case Handles::AXIS_X: result.y = point.y ; break ;
935
+ case Handles::AXIS_Y: result.z = point.z ; break ;
936
+ case Handles::AXIS_Z: result.y = point.y ; break ;
937
+ default : break ;
938
+ }
939
+ }
835
940
}
836
941
}
942
+ return result;
837
943
}
0 commit comments