SceneView3D.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Portions Copyright (c) 2008-2015 the Urho3D project.
  2. //
  3. // Copyright (c) 2014-2016 THUNDERBEAST GAMES LLC
  4. //
  5. // Permission is hereby granted, free of charge, to any person obtaining a copy
  6. // of this software and associated documentation files (the "Software"), to deal
  7. // in the Software without restriction, including without limitation the rights
  8. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. // copies of the Software, and to permit persons to whom the Software is
  10. // furnished to do so, subject to the following conditions:
  11. //
  12. // The above copyright notice and this permission notice shall be included in
  13. // all copies or substantial portions of the Software.
  14. //
  15. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  21. // THE SOFTWARE.
  22. //
  23. #pragma once
  24. #include <Atomic/Core/Object.h>
  25. #include <Atomic/UI/UISceneView.h>
  26. using namespace Atomic;
  27. namespace Atomic
  28. {
  29. class Scene;
  30. class Node;
  31. class Camera;
  32. class DebugRenderer;
  33. class Octree;
  34. }
  35. namespace AtomicEditor
  36. {
  37. class SceneEditor3D;
  38. class SceneView3D: public UISceneView
  39. {
  40. ATOMIC_OBJECT(SceneView3D, UISceneView);
  41. public:
  42. SceneView3D(Context* context, SceneEditor3D* sceneEditor);
  43. virtual ~SceneView3D();
  44. Ray GetCameraRay();
  45. bool OnEvent(const TBWidgetEvent &ev);
  46. void SetPitch(float pitch) { pitch_ = pitch; }
  47. void SetYaw(float yaw) { yaw_ = yaw; }
  48. void FrameSelection();
  49. void Enable();
  50. void Disable();
  51. bool IsEnabled() { return enabled_; }
  52. DebugRenderer* GetDebugRenderer() { return debugRenderer_; }
  53. SceneEditor3D* GetSceneEditor3D() { return sceneEditor_; }
  54. private:
  55. bool MouseInView();
  56. bool GetOrbitting();
  57. bool GetZooming();
  58. bool GetChangingCameraSpeed();
  59. void ToggleGrid();
  60. void HandleMouseMove(StringHash eventType, VariantMap& eventData);
  61. void UpdateDragNode(int mouseX, int mouseY);
  62. void HandleDragEnded(StringHash eventType, VariantMap& eventData);
  63. void HandleDragExitWidget(StringHash eventType, VariantMap& eventData);
  64. void HandleDragEnterWidget(StringHash eventType, VariantMap& eventData);
  65. void HandleUpdate(StringHash eventType, VariantMap& eventData);
  66. void HandlePostRenderUpdate(StringHash eventType, VariantMap& eventData);
  67. void HandleUIWidgetFocusEscaped(StringHash eventType, VariantMap& eventData);
  68. void HandleUIUnhandledShortcut(StringHash eventType, VariantMap& eventData);
  69. void MoveCamera(float timeStep);
  70. void CheckCameraSpeedBounds();
  71. void SnapCameraToView(int snapView);
  72. void SelectView();
  73. // stores the last known position of the perspective camera
  74. void SavePerspectiveCameraPosition();
  75. WeakPtr<SceneEditor3D> sceneEditor_;
  76. float yaw_;
  77. float pitch_;
  78. Vector3 perspectCamPosition_;
  79. float perspectiveYaw_;
  80. float perspectivePitch_;
  81. bool mouseLeftDown_;
  82. bool mouseMoved_;
  83. bool enabled_;
  84. bool gridEnabled_;
  85. // Checks whether your switching from an orthographic view
  86. bool fromOrthographic_;
  87. bool cameraMove_;
  88. float cameraMoveTime_;
  89. float cameraMoveSpeed_;
  90. Vector3 cameraMoveStart_;
  91. Vector3 cameraMoveTarget_;
  92. SharedPtr<Camera> camera_;
  93. SharedPtr<DebugRenderer> debugRenderer_;
  94. SharedPtr<Octree> octree_;
  95. BoundingBox framedBBox_;
  96. SharedPtr<Scene> preloadResourceScene_;
  97. String dragAssetGUID_;
  98. SharedPtr<Node> dragNode_;
  99. };
  100. }