@@ -24,7 +24,8 @@ enum UserMode
2424 {
2525 Idle ,
2626 Edit ,
27- Create
27+ Create ,
28+ Move
2829 }
2930 enum CreateMode
3031 {
@@ -42,10 +43,12 @@ enum CreateMode
4243 int _ioTimeline ;
4344 bool _ioIsLoop ;
4445 bool _ioIsReverse ;
46+ private Camera _camera ;
4547 bool _dialogFilePicker = false ;
4648 bool _dialogCompatibility = false ;
4749
4850 Vector2i _mouseOriginalState ;
51+ Vector3i _cameraOriginalState ;
4952
5053 SortedDictionary < int , List < Shape > > _timeline ;
5154
@@ -81,11 +84,14 @@ protected override void OnLoad()
8184 _selector = new Selector ( ) ;
8285
8386 _mouseOriginalState = new Vector2i ( 0 , 0 ) ;
87+ _cameraOriginalState = new Vector3i ( 0 , 0 , 0 ) ;
8488
8589 _timeline = new SortedDictionary < int , List < Shape > > ( ) ;
8690
8791 _ImGuiController = new ImGuiController ( ClientSize . X , ClientSize . Y ) ;
8892
93+ _camera = new Camera ( Vector3 . UnitZ * 3 , Size . X / ( float ) Size . Y ) ;
94+
8995 _ioIsLoop = false ;
9096 _ioIsReverse = false ;
9197
@@ -99,6 +105,8 @@ protected override void OnResize(ResizeEventArgs e)
99105 GL . Viewport ( 0 , 0 , ClientSize . X , ClientSize . Y ) ;
100106
101107 _ImGuiController . WindowResized ( ClientSize . X , ClientSize . Y ) ;
108+
109+ _camera . AspectRatio = Size . X / ( float ) Size . Y ; // TODO: Why not ClientSize
102110 }
103111 /// <summary>
104112 /// Triggered at a fixed interval. (Logic, etc.)
@@ -142,6 +150,16 @@ protected override void OnRenderFrame(FrameEventArgs e)
142150 // _selectedShape.ImplementObject(); // Reset VAOS for selected shape
143151 }
144152
153+ if ( KeyboardState . IsKeyPressed ( Keys . Right ) )
154+ {
155+ _camera . Position += Vector3 . Normalize ( Vector3 . Cross ( _camera . Front , _camera . Up ) ) * 2 ;
156+ }
157+
158+ //if (KeyboardState.IsKeyDown(Keys.Space))
159+ // _userMode = UserMode.Move;
160+ //else if (KeyboardState.WasKeyDown(Keys.Space) && KeyboardState.IsKeyDown(Keys.Space) == false)
161+ // _userMode = UserMode.Idle;
162+
145163 if ( KeyboardState . IsKeyDown ( Keys . Escape ) )
146164 ResetSelection ( ) ;
147165
@@ -168,15 +186,14 @@ protected override void OnRenderFrame(FrameEventArgs e)
168186 _selectedShape = shape ;
169187 }
170188 }
171-
189+ // Change to ButtonPressed instead of was and is
172190 if ( MouseState . WasButtonDown ( MouseButton . Left ) == false && MouseState . IsButtonDown ( MouseButton . Left ) == true ) // First left click
173191 OnLeftMouseDown ( ) ;
174192 else if ( MouseState . WasButtonDown ( MouseButton . Left ) == true && MouseState . IsButtonDown ( MouseButton . Left ) == true ) // Long left click
175193 OnLeftMouseEnter ( ) ;
176194 else if ( MouseState . WasButtonDown ( MouseButton . Left ) == true && MouseState . IsButtonDown ( MouseButton . Left ) == false ) // Release left click
177195 OnLeftMouseUp ( ) ;
178196
179-
180197 //GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
181198 foreach ( Shape shape in _shapes )
182199 {
@@ -186,7 +203,7 @@ protected override void OnRenderFrame(FrameEventArgs e)
186203
187204 //shape.ImplementObject(); // Reset VAOs
188205 //shape.ImplementObject();
189- shape . Draw ( ClientSize ) ;
206+ shape . Draw ( ClientSize , _camera ) ;
190207 }
191208
192209 if ( _selectedShape != null )
@@ -240,10 +257,11 @@ protected override void OnRenderFrame(FrameEventArgs e)
240257 switch ( _userMode )
241258 {
242259 case UserMode . Edit :
243- _selector . Draw ( ClientSize ) ; // Only draw selector on edit mode
260+ _selector . Draw ( ClientSize , _camera ) ; // Only draw selector on edit mode
244261 break ;
245262 case UserMode . Create :
246263 break ;
264+ case UserMode . Move :
247265 case UserMode . Idle :
248266 default :
249267 break ;
@@ -381,6 +399,18 @@ public void OnLeftMouseDown()
381399 }
382400 break ;
383401 case UserMode . Create :
402+ case UserMode . Move :
403+ //if (ImGui.GetIO().WantCaptureMouse == false) // If it's not ImGui click
404+ //{
405+ // _mouseOriginalState.X = (int)MouseState.X;
406+ // _mouseOriginalState.Y = (int)MouseState.Y;
407+
408+ // _cameraOriginalState.X = (int)_camera.Position.X;
409+ // _cameraOriginalState.Y = (int)_camera.Position.Y;
410+ // _cameraOriginalState.Z = (int)_camera.Position.Z;
411+
412+ //}
413+ //break;
384414 default :
385415 break ;
386416 }
@@ -464,6 +494,9 @@ public void OnLeftMouseEnter() // TODO: Rename this
464494 }
465495 }
466496 break ;
497+ case UserMode . Move :
498+ //_camera.Position = new Vector3(_cameraOriginalState.X + (-MouseState.X / Size.X) - (-_mouseOriginalState.X / Size.X), _cameraOriginalState.Y + (MouseState.Y / Size.Y) - (_mouseOriginalState.Y / Size.Y), _camera.Position.Z);
499+ break ;
467500 case UserMode . Idle :
468501 default :
469502 break ;
@@ -561,6 +594,13 @@ public void ShowUIDebug()
561594 }
562595 ImGui . End ( ) ;
563596 }
597+
598+ protected override void OnMouseWheel ( MouseWheelEventArgs e )
599+ {
600+ base . OnMouseWheel ( e ) ;
601+ //Console.WriteLine(_camera.Position.Z);
602+ _camera . Position = new Vector3 ( _camera . Position . X , _camera . Position . Y , _camera . Position . Z + ( 1f * - e . OffsetY ) ) ; // TODO: Smooth the scroll when close
603+ }
564604 public int LinearInterpolate ( int x , int x1 , int x2 , int y1 , int y2 )
565605 {
566606 float y ;
0 commit comments