Browse Source

Modified the grid.

weinand 9 years ago
parent
commit
4517cb2a35

+ 1 - 1
Source/Atomic/Graphics/Camera.h

@@ -31,7 +31,7 @@ namespace Atomic
 {
 
 static const float DEFAULT_NEARCLIP = 0.1f;
-static const float DEFAULT_FARCLIP = 1000.0f;
+static const float DEFAULT_FARCLIP = 200.0f;
 static const float DEFAULT_CAMERA_FOV = 45.0f;
 static const float DEFAULT_ORTHOSIZE = 20.0f;
 

+ 7 - 11
Source/Atomic/Graphics/DebugRenderer.cpp

@@ -56,7 +56,7 @@ DebugRenderer::DebugRenderer(Context* context) :
     position1_(0, 0, 0),
     position2_(0, 0, 0),
     position3_(0, 0, 0),
-    numGridLines_(81),
+    numGridLines_(200),
     scale_(0),
     lineLength_(0),
     offset_(0),
@@ -356,7 +356,7 @@ void DebugRenderer::AddTriangleMesh(const void* vertexData, unsigned vertexSize,
     }
 }
 
-void DebugRenderer::CreateXAxisLines(unsigned gridColor, unsigned subdivisionColor, bool depthTest, int x, int y, int z)
+void DebugRenderer::CreateXAxisLines(unsigned gridColor, bool depthTest, int x, int y, int z)
 {
     for (int i = 0; i < numGridLines_; i++)
     {
@@ -372,7 +372,7 @@ void DebugRenderer::CreateXAxisLines(unsigned gridColor, unsigned subdivisionCol
 
 }
 
-void DebugRenderer::CreateZAxisLines(unsigned gridColor, unsigned subdivisionColor, bool depthTest, int x, int y, int z)
+void DebugRenderer::CreateZAxisLines(unsigned gridColor, bool depthTest, int x, int y, int z)
 {
     for (int j = 0; j < numGridLines_; j++)
     {
@@ -387,15 +387,11 @@ void DebugRenderer::CreateZAxisLines(unsigned gridColor, unsigned subdivisionCol
     }
 }
 
-void DebugRenderer::CreateGrid(const Color& grid, const Color& subdivision, bool depthTest, Vector3 position)
+void DebugRenderer::CreateGrid(const Color& grid, bool depthTest, Vector3 position)
 {
     unsigned gridColor = grid.ToUInt();
-    unsigned subdivisionColor = subdivision.ToUInt();
 
-    int x = position.x_;
-    int z = position.z_;
-
-    scale_ = (position.y_ / position.y_) * scaleIncrement_;
+    scale_ = position.y_ / scaleIncrement_;
 
     if (position.y_ < scaleIncrement_)
         scale_ = 1;
@@ -403,8 +399,8 @@ void DebugRenderer::CreateGrid(const Color& grid, const Color& subdivision, bool
     lineLength_ = (numGridLines_ / 2) * scale_;
     offset_ = (numGridLines_ / 2) * scale_;
 
-    CreateXAxisLines(gridColor, subdivisionColor, depthTest, x, 0, z);
-    CreateZAxisLines(gridColor, subdivisionColor, depthTest, x, 0, z);
+    CreateXAxisLines(gridColor, depthTest, 0, 0, 0);
+    CreateZAxisLines(gridColor, depthTest, 0, 0, 0);
 }
 
 void DebugRenderer::Render()

+ 3 - 3
Source/Atomic/Graphics/DebugRenderer.h

@@ -136,11 +136,11 @@ public:
             unsigned indexCount, const Matrix3x4& transform, const Color& color, bool depthTest = true);
 
     /// Create positive and negative X axis lines
-    void CreateXAxisLines(unsigned gridColor, unsigned subdivisionColor, bool depthTest, int x, int y, int z);
+    void CreateXAxisLines(unsigned gridColor, bool depthTest, int x, int y, int z);
     /// Create positive and negative Z axis lines
-    void CreateZAxisLines(unsigned gridColor, unsigned subdivisionColor, bool depthTest, int x, int y, int z);
+    void CreateZAxisLines(unsigned gridColor, bool depthTest, int x, int y, int z);
     /// Creates a grid on all axis
-    void CreateGrid(const Color& grid, const Color& subdivision, bool depthTest, Vector3 position);
+    void CreateGrid(const Color& grid, bool depthTest, Vector3 position);
 
     /// Update vertex buffer and render all debug lines. The viewport and rendertarget should be set before.
     void Render();

+ 27 - 1
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.cpp

@@ -520,6 +520,8 @@ bool SceneView3D::OnEvent(const TBWidgetEvent &ev)
 
 void SceneView3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
 {
+    int FARCLIP_INCREMENT = 8;
+
     // parent is the contentRoot for our tab, when tab isn't active it will not be visible
     if (!GetParent() || GetParent()->GetVisibility() != UI_WIDGET_VISIBILITY_VISIBLE)
     {
@@ -539,7 +541,31 @@ void SceneView3D::HandleUpdate(StringHash eventType, VariantMap& eventData)
     ToggleGrid();
 
     if (gridEnabled_)
-        debugRenderer_->CreateGrid(Color::GRAY, Color::RED, false, cameraNode_->GetPosition());
+    {
+        int cameraYPos = cameraNode_->GetPosition().y_;
+        int farClip = camera_->GetFarClip();
+
+        if (cameraYPos == newCameraYPos_)
+        {
+            farClip = camera_->GetFarClip();
+        }
+        else
+        {
+            if (cameraYPos > newCameraYPos_)
+            {
+                farClip += FARCLIP_INCREMENT;
+                camera_->SetFarClip(farClip);
+            }
+            else
+            {
+                farClip -= FARCLIP_INCREMENT;
+                camera_->SetFarClip(farClip);
+            }
+        }
+        newCameraYPos_ = cameraYPos;
+
+        debugRenderer_->CreateGrid(Color::GRAY, true, cameraNode_->GetPosition());
+    }
 
     if (preloadResourceScene_.NotNull())
     {

+ 2 - 0
Source/AtomicEditor/Editors/SceneEditor3D/SceneView3D.h

@@ -97,6 +97,8 @@ private:
 
     WeakPtr<SceneEditor3D> sceneEditor_;
 
+    int newCameraYPos_;
+
     float yaw_;
     float pitch_;