From 2f60e8694a88d5d470391316052399428209aeeb Mon Sep 17 00:00:00 2001 From: Rudolf Polzer Date: Fri, 7 Oct 2011 14:06:03 +0200 Subject: [PATCH] make dialogs for all "Xact" spheres/cones/cylinders --- radiant/patch.cpp | 42 +++++++++++++++++++++--------------------- radiant/patchmanip.cpp | 20 +++++++++++--------- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/radiant/patch.cpp b/radiant/patch.cpp index 9ecb6499..5b2622bb 100644 --- a/radiant/patch.cpp +++ b/radiant/patch.cpp @@ -1402,8 +1402,8 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: } else if (eType == eXactCylinder) { - int n = 6; // n = number of segments - setDims(2 * n + 1, 3); + int n = (width - 1) / 2; // n = number of segments + setDims(width, height); // vPos[0] = vector3_subtracted(aabb.origin, aabb.extents); // vPos[1] = aabb.origin; @@ -1411,16 +1411,16 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: int i, j; float f = 1 / cos(M_PI / n); - for(i = 0; i < 2*n+1; ++i) + for(i = 0; i < width; ++i) { - float angle = (M_PI * i) / n; + float angle = (M_PI * i) / n; // 0 to 2pi float x = vPos[1][0] + (vPos[2][0] - vPos[1][0]) * cos(angle) * ((i&1) ? f : 1.0f); float y = vPos[1][1] + (vPos[2][1] - vPos[1][1]) * sin(angle) * ((i&1) ? f : 1.0f); - for(j = 0; j < 3; ++j) + for(j = 0; j < height; ++j) { - float z = vPos[j][2]; + float z = vPos[0][2] + (vPos[2][2] - vPos[0][2]) * (j / (float)(height - 1)); PatchControl *v; - v = &m_ctrl.data()[j*(2*n+1)+i]; + v = &m_ctrl.data()[j*width+i]; v->m_vertex[0] = x; v->m_vertex[1] = y; v->m_vertex[2] = z; @@ -1429,8 +1429,8 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: } else if (eType == eXactCone) { - int n = 6; // n = number of segments - setDims(2 * n + 1, 3); + int n = (width - 1) / 2; // n = number of segments + setDims(width, height); // vPos[0] = vector3_subtracted(aabb.origin, aabb.extents); // vPos[1] = aabb.origin; @@ -1438,16 +1438,16 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: int i, j; float f = 1 / cos(M_PI / n); - for(i = 0; i < 2*n+1; ++i) + for(i = 0; i < width; ++i) { float angle = (M_PI * i) / n; - for(j = 0; j < 3; ++j) + for(j = 0; j < height; ++j) { - float x = vPos[1][0] + ((2-j)/2.0f) * (vPos[2][0] - vPos[1][0]) * cos(angle) * ((i&1) ? f : 1.0f); - float y = vPos[1][1] + ((2-j)/2.0f) * (vPos[2][1] - vPos[1][1]) * sin(angle) * ((i&1) ? f : 1.0f); - float z = vPos[j][2]; + float x = vPos[1][0] + (1.0f - (j / (float)(height - 1))) * (vPos[2][0] - vPos[1][0]) * cos(angle) * ((i&1) ? f : 1.0f); + float y = vPos[1][1] + (1.0f - (j / (float)(height - 1))) * (vPos[2][1] - vPos[1][1]) * sin(angle) * ((i&1) ? f : 1.0f); + float z = vPos[0][2] + (vPos[2][2] - vPos[0][2]) * (j / (float)(height - 1)); PatchControl *v; - v = &m_ctrl.data()[j*(2*n+1)+i]; + v = &m_ctrl.data()[j*width+i]; v->m_vertex[0] = x; v->m_vertex[1] = y; v->m_vertex[2] = z; @@ -1456,9 +1456,9 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: } else if (eType == eXactSphere) { - int n = 6; // n = number of segments - int m = 3; // m = number of segments - setDims(2 * n + 1, 2 * m + 1); + int n = (width - 1) / 2; // n = number of segments (yaw) + int m = (height - 1) / 2; // m = number of segments (pitch) + setDims(width, height); // vPos[0] = vector3_subtracted(aabb.origin, aabb.extents); // vPos[1] = aabb.origin; @@ -1467,17 +1467,17 @@ void Patch::ConstructPrefab(const AABB& aabb, EPatchPrefab eType, int axis, std: int i, j; float f = 1 / cos(M_PI / n); float g = 1 / cos(M_PI / (2*m)); - for(i = 0; i < 2*n+1; ++i) + for(i = 0; i < width; ++i) { float angle = (M_PI * i) / n; - for(j = 0; j < 2*m+1; ++j) + for(j = 0; j < height; ++j) { float angle2 = (M_PI * j) / (2*m); float x = vPos[1][0] + (vPos[2][0] - vPos[1][0]) * sin(angle2) * ((j&1) ? g : 1.0f) * cos(angle) * ((i&1) ? f : 1.0f); float y = vPos[1][1] + (vPos[2][1] - vPos[1][1]) * sin(angle2) * ((j&1) ? g : 1.0f) * sin(angle) * ((i&1) ? f : 1.0f); float z = vPos[1][2] + (vPos[2][2] - vPos[1][2]) * -cos(angle2) * ((j&1) ? g : 1.0f); PatchControl *v; - v = &m_ctrl.data()[j*(2*n+1)+i]; + v = &m_ctrl.data()[j*width+i]; v->m_vertex[0] = x; v->m_vertex[1] = y; v->m_vertex[2] = z; diff --git a/radiant/patchmanip.cpp b/radiant/patchmanip.cpp index 144c1799..6829fee7 100644 --- a/radiant/patchmanip.cpp +++ b/radiant/patchmanip.cpp @@ -432,25 +432,27 @@ AABB PatchCreator_getBounds() return AABB(Vector3(0, 0, 0), Vector3(64, 64, 64)); } +void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols); + void Patch_XactCylinder() { UndoableCommand undo("patchCreateXactCylinder"); - Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eXactCylinder, GlobalXYWnd_getCurrentViewType()); + DoNewPatchDlg(eXactCylinder, 3, 7, 3, 13, 0, 0); } void Patch_XactSphere() { UndoableCommand undo("patchCreateXactSphere"); - Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eXactSphere, GlobalXYWnd_getCurrentViewType()); + DoNewPatchDlg(eXactSphere, 5, 7, 7, 13, 0, 0); } void Patch_XactCone() { UndoableCommand undo("patchCreateXactCone"); - Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eXactCone, GlobalXYWnd_getCurrentViewType()); + DoNewPatchDlg(eXactCone, 3, 7, 3, 13, 0, 0); } void Patch_Cylinder() @@ -517,13 +519,11 @@ void Patch_Cone() Scene_PatchConstructPrefab(GlobalSceneGraph(), PatchCreator_getBounds(), TextureBrowser_GetSelectedShader(GlobalTextureBrowser()), eCone, GlobalXYWnd_getCurrentViewType()); } -void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, int maxcols); - void Patch_Plane() { UndoableCommand undo("patchCreatePlane"); - DoNewPatchDlg(ePlane, 3, 3, 0, 0); + DoNewPatchDlg(ePlane, 3, 3, 3, 3, 0, 0); } void Patch_InsertInsertColumn() @@ -894,7 +894,7 @@ void Patch_constructMenu(GtkMenu* menu) #include "gtkutil/dialog.h" #include "gtkutil/widget.h" -void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, int maxcols) +void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int defrows, int defcols, int maxrows, int maxcols) { ModalDialog dialog; GtkComboBox* width; @@ -946,6 +946,7 @@ void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, i D_ITEM(27); D_ITEM(29); D_ITEM(31); // MAX_PATCH_SIZE is 32, so we should be able to do 31... +#undef D_ITEM gtk_widget_show(GTK_WIDGET(combo)); gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 0, 1, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), @@ -971,6 +972,7 @@ void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, i D_ITEM(27); D_ITEM(29); D_ITEM(31); // MAX_PATCH_SIZE is 32, so we should be able to do 31... +#undef D_ITEM gtk_widget_show(GTK_WIDGET(combo)); gtk_table_attach(table, GTK_WIDGET(combo), 1, 2, 1, 2, (GtkAttachOptions) (GTK_EXPAND | GTK_FILL), @@ -999,8 +1001,8 @@ void DoNewPatchDlg(EPatchPrefab prefab, int minrows, int mincols, int maxrows, i } // Initialize dialog - gtk_combo_box_set_active(width, 0); - gtk_combo_box_set_active(height, 0); + gtk_combo_box_set_active(width, (defcols - mincols) / 2); + gtk_combo_box_set_active(height, (defrows - minrows) / 2); if(modal_dialog_show(window, dialog) == eIDOK) { -- 2.39.2