]> git.xonotic.org Git - xonotic/netradiant.git/blobdiff - radiant/patch.cpp
add a comment to indicate the options
[xonotic/netradiant.git] / radiant / patch.cpp
index 719e2412d58763ce30858b2604bd0b8104f3f5f7..a9e452d91655ae90d677eb1bba04354272e36c87 100644 (file)
@@ -396,6 +396,70 @@ void Patch::Redisperse(EMatrixMajor mt)
   controlPointsChanged();
 }
 
+void Patch::Smooth(EMatrixMajor mt)
+{
+  std::size_t w, h, width, height, row_stride, col_stride;
+  bool wrap;
+  PatchControl* p1, * p2, * p3, * p2b;
+
+  undoSave();
+
+  switch(mt)
+  {
+  case COL:
+    width = (m_width-1)>>1;
+    height = m_height;
+    col_stride = 1;
+    row_stride = m_width;
+    break;
+  case ROW:
+    width = (m_height-1)>>1;
+    height = m_width;
+    col_stride = m_width;
+    row_stride = 1;
+    break;
+  default:
+    ERROR_MESSAGE("neither row-major nor column-major");
+    return;
+  }
+
+  wrap = true;
+  for(h=0;h<height;h++)
+  {
+       p1 = m_ctrl.data()+(h*row_stride);
+       p2 = p1+(2*width)*col_stride;
+       //globalErrorStream() << "compare " << p1->m_vertex << " and " << p2->m_vertex << "\n";
+       if(vector3_length_squared(vector3_subtracted(p1->m_vertex, p2->m_vertex)) > 1.0)
+       {
+         //globalErrorStream() << "too far\n";
+         wrap = false;
+         break;
+       }
+  }
+
+  for(h=0;h<height;h++)
+  {
+    p1 = m_ctrl.data()+(h*row_stride)+col_stride;
+    for(w=0;w<width-1;w++)
+    {
+      p2 = p1+col_stride;
+      p3 = p2+col_stride;
+      p2->m_vertex = vector3_mid(p1->m_vertex, p3->m_vertex);
+      p1 = p3;
+    }
+       if(wrap)
+       {
+         p1 = m_ctrl.data()+(h*row_stride)+(2*width-1)*col_stride;
+         p2 = m_ctrl.data()+(h*row_stride);
+         p2b = m_ctrl.data()+(h*row_stride)+(2*width)*col_stride;
+         p3 = m_ctrl.data()+(h*row_stride)+col_stride;
+         p2->m_vertex = p2b->m_vertex = vector3_mid(p1->m_vertex, p3->m_vertex);
+       }
+  }
+  
+  controlPointsChanged();
+}
+
 void Patch::InsertRemove(bool bInsert, bool bColumn, bool bFirst)
 {
   undoSave();
@@ -1295,7 +1359,7 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std:
         {
           pCtrl->m_vertex[0] = vPos[1][0];
           pCtrl->m_vertex[1] = vPos[1][1];
-          pCtrl->m_vertex[2] = vPos[2][2];
+          pCtrl->m_vertex[2] = vPos[0][2];
         }
       }
       {
@@ -1307,6 +1371,7 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std:
           pCtrl->m_vertex[2] = vPos[2][2];
         }
       }
+         break;
     default:
       ERROR_MESSAGE("this should be unreachable");
       return;