Added the ability to add vertices to object corners

Sat, 13 Apr 2013 02:11:54 +0300

author
Santeri Piippo <crimsondusk64@gmail.com>
date
Sat, 13 Apr 2013 02:11:54 +0300
changeset 103
b0a345196435
parent 102
cacd4681ccb4
child 104
6e29bb0e83c5

Added the ability to add vertices to object corners

common.h file | annotate | diff | comparison | revisions
gldraw.cpp file | annotate | diff | comparison | revisions
gui.cpp file | annotate | diff | comparison | revisions
gui_editactions.cpp file | annotate | diff | comparison | revisions
ldtypes.cpp file | annotate | diff | comparison | revisions
ldtypes.h file | annotate | diff | comparison | revisions
main.cpp file | annotate | diff | comparison | revisions
--- a/common.h	Fri Apr 12 02:54:25 2013 +0300
+++ b/common.h	Sat Apr 13 02:11:54 2013 +0300
@@ -126,7 +126,6 @@
 // -----------------------------------------------------------------------------
 // Vertex at (0, 0, 0)
 extern const vertex g_Origin;
-extern bool g_bApplicationReady;
 
 // -----------------------------------------------------------------------------
 // Pointer to the OpenFile which is currently being edited by the user.
@@ -144,6 +143,10 @@
 // Pointer to the main application.
 extern QApplication* g_qMainApp;
 
+// -----------------------------------------------------------------------------
+// Identity matrix
+extern const matrix g_mIdentity;
+
 typedef unsigned int uint;
 typedef unsigned long ulong;
 
--- a/gldraw.cpp	Fri Apr 12 02:54:25 2013 +0300
+++ b/gldraw.cpp	Sat Apr 13 02:11:54 2013 +0300
@@ -296,6 +296,40 @@
 		}
 		break;
 	
+#if 0
+	TODO: find a proper way to draw vertices without having them be affected by zoom.
+	case OBJ_Vertex:
+		{
+			LDVertex* pVert = static_cast<LDVertex*> (obj);
+			LDTriangle* pPoly;
+			vertex* vPos = &(pVert->vPosition);
+			const double fPolyScale = max (fZoom, 1.0);
+			
+#define BIPYRAMID_COORD(N) ((((i + N) % 4) >= 2 ? 1 : -1) * 0.3f * fPolyScale)
+			
+			for (int i = 0; i < 8; ++i) {
+				pPoly = new LDTriangle;
+				pPoly->vaCoords[0] = {vPos->x, vPos->y + ((i >= 4 ? 1 : -1) * 0.4f * fPolyScale), vPos->z};
+				pPoly->vaCoords[1] = {
+					vPos->x + BIPYRAMID_COORD (0),
+					vPos->y,
+					vPos->z + BIPYRAMID_COORD (1)
+				};
+				
+				pPoly->vaCoords[2] = {
+					vPos->x + BIPYRAMID_COORD (1),
+					vPos->y,
+					vPos->z + BIPYRAMID_COORD (2)
+				};
+				
+				pPoly->dColor = pVert->dColor;
+				compileOneObject (pPoly);
+				delete pPoly;
+			}
+		}
+		break;
+#endif // 0
+	
 	default:
 		break;
 	}
--- a/gui.cpp	Fri Apr 12 02:54:25 2013 +0300
+++ b/gui.cpp	Sat Apr 13 02:11:54 2013 +0300
@@ -44,6 +44,7 @@
 EXTERN_ACTION (splitQuads)
 EXTERN_ACTION (setContents)
 EXTERN_ACTION (makeBorders)
+EXTERN_ACTION (makeCornerVerts)
 EXTERN_ACTION (moveUp)
 EXTERN_ACTION (moveDown)
 EXTERN_ACTION (newSubfile)
@@ -192,6 +193,7 @@
 	qEditMenu->addAction (ACTION_NAME (splitQuads));		// Split Quads
 	qEditMenu->addAction (ACTION_NAME (setContents));		// Set Contents
 	qEditMenu->addAction (ACTION_NAME (makeBorders));		// Make Borders
+	qEditMenu->addAction (ACTION_NAME (makeCornerVerts));	// Make Corner Vertices
 	
 	// Move menu
 	qMoveMenu = menuBar ()->addMenu (tr ("&Move"));
@@ -308,6 +310,7 @@
 	ADD_TOOLBAR_ITEM (splitQuads)
 	ADD_TOOLBAR_ITEM (setContents)
 	ADD_TOOLBAR_ITEM (makeBorders)
+	ADD_TOOLBAR_ITEM (makeCornerVerts)
 	
 	updateToolBars ();
 }
--- a/gui_editactions.cpp	Fri Apr 12 02:54:25 2013 +0300
+++ b/gui_editactions.cpp	Sat Apr 13 02:11:54 2013 +0300
@@ -317,6 +317,57 @@
 // =============================================================================
 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 // =============================================================================
+ACTION (makeCornerVerts, "Make Corner Vertices", "corner-verts",
+	"Adds vertex objects to the corners of the given polygons", (0))
+{
+	vector<ulong> ulaIndices;
+	vector<LDObject*> paObjs;
+	
+	for (LDObject* obj : g_ForgeWindow->getSelectedObjects ()) {
+		vertex* vaCoords = nullptr;
+		ushort uNumCoords = 0;
+		
+		switch (obj->getType ()) {
+		case OBJ_Quad:
+			uNumCoords = 4;
+			vaCoords = static_cast<LDQuad*> (obj)->vaCoords;
+			break;
+		
+		case OBJ_Triangle:
+			uNumCoords = 3;
+			vaCoords = static_cast<LDTriangle*> (obj)->vaCoords;
+			break;
+		
+		case OBJ_Line:
+			uNumCoords = 2;
+			vaCoords = static_cast<LDLine*> (obj)->vaCoords;
+			break;
+		
+		default:
+			break;
+		}
+		
+		ulong idx = obj->getIndex (g_CurrentFile);
+		for (ushort i = 0; i < uNumCoords; ++i) {
+			LDVertex* pVert = new LDVertex;
+			pVert->vPosition = vaCoords[i];
+			pVert->dColor = obj->dColor;
+			
+			g_CurrentFile->objects.insert (g_CurrentFile->objects.begin() + ++idx, pVert);
+			ulaIndices.push_back (idx);
+			paObjs.push_back (pVert->clone ());
+		}
+	}
+	
+	if (ulaIndices.size() > 0) {
+		History::addEntry (new AddHistory (ulaIndices, paObjs));
+		g_ForgeWindow->refresh ();
+	}
+}
+
+// =============================================================================
+// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
+// =============================================================================
 static void doMoveSelection (const bool bUp) {
 	vector<LDObject*> objs = g_ForgeWindow->getSelectedObjects ();
 	
--- a/ldtypes.cpp	Fri Apr 12 02:54:25 2013 +0300
+++ b/ldtypes.cpp	Sat Apr 13 02:11:54 2013 +0300
@@ -447,7 +447,13 @@
 			if (!bFirstDetails)
 				zText += ", ";
 			
-			zText.appendformat ("%lu %s%s", ulCount, g_saObjTypeNames[eType], PLURAL (ulCount));
+			str zNoun = str::mkfmt ("%s%s", g_saObjTypeNames[eType], PLURAL (ulCount));
+			
+			// Plural of "vertex" is "vertices". Stupid English.
+			if (eType == OBJ_Vertex && ulCount != 1)
+				zNoun = "vertices";
+			
+			zText.appendformat ("%lu %s", ulCount, zNoun.chars ());
 			bFirstDetails = false;
 		}
 	}
--- a/ldtypes.h	Fri Apr 12 02:54:25 2013 +0300
+++ b/ldtypes.h	Sat Apr 13 02:11:54 2013 +0300
@@ -76,6 +76,9 @@
 	// do not use this field.
 	short dColor;
 	
+	// OpenGL list for this object
+	uint uGLList;
+	
 	// Type enumerator of this object
 	virtual LDObjectType_e getType () const {
 		return OBJ_Unidentified;
--- a/main.cpp	Fri Apr 12 02:54:25 2013 +0300
+++ b/main.cpp	Sat Apr 13 02:11:54 2013 +0300
@@ -32,6 +32,7 @@
 QApplication* g_qMainApp = nullptr;
 
 const vertex g_Origin (0.0f, 0.0f, 0.0f);
+const matrix g_mIdentity (1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
 
 int main (int dArgc, char* saArgv[]) {
 	// Load or create the configuration

mercurial