# HG changeset patch # User Santeri Piippo # Date 1368464002 -10800 # Node ID cfe9ae5f1124b6aedfa921a5fff8e3c1cde2c6e2 # Parent ce8e25ccbaf6966c3b0786c7c7386e35f7dc47df Fixed coordconv3_2 algorithm, plane drawing works on any of the fixed cameras now. diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/gldraw.cpp --- a/src/gldraw.cpp Mon May 13 00:04:54 2013 +0300 +++ b/src/gldraw.cpp Mon May 13 19:53:22 2013 +0300 @@ -384,7 +384,7 @@ } // ============================================================================= -vertex GLRenderer::coord_2to3 (const QPoint& pos2d, const bool snap) const { +vertex GLRenderer::coordconv2_3 (const QPoint& pos2d, bool snap) const { vertex pos3d; const staticCameraMeta* cam = &g_staticCameras[m_camera]; const Axis axisX = cam->axisX; @@ -411,36 +411,31 @@ } // ============================================================================= -QPoint GLRenderer::coord_3to2 (const vertex& pos3d) const { - /* - cx = (-m_virtWidth + ((2 * pos2d.x () * m_virtWidth) / m_width) - m_panX) - (negXFac * g_objOffset[axisX]); - - cx = (-vw + ((2 * x * vw) / w) - panx) - (neg * ofs) - cx + (neg * ofs) = (-vw + ((2 * x * vw) / w) - panx) - cx + (neg * ofs) = ((2 * x * vw) / w) - vw - panx - (cx + (neg * ofs)) + vw + panx = (2 * x * vw) / w - ((cx + (neg * ofs)) + vw + panx) * w = 2 * vw * x - - x = (((cx + (neg * ofs)) + vw + panx) * w) / (2 * vw) - */ - - QPoint pos2d; +QPoint GLRenderer::coordconv3_2 (const vertex& pos3d) const { + GLfloat m[16]; const staticCameraMeta* cam = &g_staticCameras[m_camera]; const Axis axisX = cam->axisX; const Axis axisY = cam->axisY; const short negXFac = cam->negX ? -1 : 1, negYFac = cam->negY ? -1 : 1; - short x1 = (((pos3d[axisX] + (negXFac * g_objOffset[axisX])) + - m_virtWidth + m_panX) * m_width) / (2 * m_virtWidth); - short y1 = -(((pos3d[axisY] + (negYFac * g_objOffset[axisY])) - - m_virtHeight + m_panY) * m_height) / (2 * m_virtHeight); + glGetFloatv (GL_MODELVIEW_MATRIX, m); + + const double x = pos3d.x (); + const double y = pos3d.y (); + const double z = pos3d.z (); - x1 *= negXFac; - y1 *= negYFac; + vertex transformed; + transformed[X] = (m[0] * x) + (m[1] * y) + (m[2] * z) + m[3]; + transformed[Y] = (m[4] * x) + (m[5] * y) + (m[6] * z) + m[7]; + transformed[Z] = (m[8] * x) + (m[9] * y) + (m[10] * z) + m[11]; - pos2d = QPoint (x1, y1); - return pos2d; + double rx = (((transformed[axisX] * negXFac) + (negXFac * g_objOffset[axisX]) + + m_virtWidth + m_panX) * m_width) / (2 * m_virtWidth); + double ry = (((transformed[axisY] * negYFac) + (negYFac * g_objOffset[axisY]) + - m_virtHeight + m_panY) * m_height) / (2 * m_virtHeight); + + return QPoint (rx, -ry); } // ============================================================================= @@ -473,7 +468,7 @@ if (m_camera != Free) { // Calculate 3d position of the cursor - m_hoverpos = coord_2to3 (m_pos, true); + m_hoverpos = coordconv2_3 (m_pos, true); // Paint the coordinates onto the screen. str text; @@ -496,13 +491,13 @@ uchar i = 0; for (vertex& vert : m_planeDrawVerts) { - poly[i] = coord_3to2 (vert); + poly[i] = coordconv3_2 (vert); ++i; } // Draw the cursor vertex as the last one in the list. if (numverts < 5) - poly[i] = coord_3to2 (m_hoverpos); + poly[i] = coordconv3_2 (m_hoverpos); else numverts = 4; @@ -623,6 +618,7 @@ compileObject (obj); // Compile axes + glDeleteLists (m_axeslist, 1); m_axeslist = glGenLists (1); glNewList (m_axeslist, GL_COMPILE); glBegin (GL_LINES); @@ -782,7 +778,7 @@ // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -void GLRenderer::clampAngle (double& angle) { +void GLRenderer::clampAngle (double& angle) const { while (angle < 0) angle += 360.0; while (angle > 360.0) @@ -1158,9 +1154,9 @@ // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= void GLRenderer::compileObject (LDObject* obj) { + deleteLists (obj); + for (const GL::ListType listType : g_glListTypes) { - glDeleteLists (obj->glLists[listType], 1); - GLuint list = glGenLists (1); glNewList (list, GL_COMPILE); @@ -1203,4 +1199,10 @@ break; } } +} + +// ============================================================================= +void GLRenderer::deleteLists (LDObject* obj) { + for (const GL::ListType listType : g_glListTypes) + glDeleteLists (obj->glLists[listType], 1); } \ No newline at end of file diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/gldraw.h --- a/src/gldraw.h Mon May 13 00:04:54 2013 +0300 +++ b/src/gldraw.h Mon May 13 19:53:22 2013 +0300 @@ -50,23 +50,25 @@ GLRenderer (QWidget* parent = null); ~GLRenderer (); - void beginPlaneDraw (); - Camera camera () const { return m_camera; } - void compileObject (LDObject* obj); - void compileAllObjects (); - void endPlaneDraw (bool accept); - QColor getMainColor (); - void hardRefresh (); - bool picking () const { return m_picking; } - void refresh (); - void resetAngles (); - uchar* screencap (ushort& w, ushort& h); - void setBackground (); - void setCamera (const GLRenderer::Camera cam); - void setZoom (const double zoom) { m_zoom = zoom; } - void setWireframe (const bool set); - bool wireframe () const; - double zoom () const { return m_zoom; } + void beginPlaneDraw (); + Camera camera () const { return m_camera; } + void compileObject (LDObject* obj); + void compileAllObjects (); + void endPlaneDraw (bool accept); + QColor getMainColor (); + void hardRefresh (); + bool picking () const { return m_picking; } + void refresh (); + void resetAngles (); + uchar* screencap (ushort& w, ushort& h); + void setBackground (); + void setCamera (const GLRenderer::Camera cam); + void setZoom (const double zoom) { m_zoom = zoom; } + void setWireframe (const bool set); + bool wireframe () const; + double zoom () const { return m_zoom; } + + static void deleteLists (LDObject* obj); protected: void contextMenuEvent (QContextMenuEvent* ev); @@ -96,16 +98,16 @@ ushort m_width, m_height; std::vector m_planeDrawVerts; - void calcCameraIcons (); - void clampAngle (double& angle); - void compileList (LDObject* obj, const ListType list); - void compileSubObject (LDObject* obj, const GLenum gltype); - void compileVertex (const vertex& vrt); - vertex coord_2to3 (const QPoint& pos2d, const bool snap) const; - QPoint coord_3to2 (const vertex& pos3d) const; - void drawGLScene () const; - void pick (uint mouseX, uint mouseY); - void setObjectColor (LDObject* obj, const ListType list); + void calcCameraIcons (); // Compute geometry for camera icons + void clampAngle (double& angle) const; // Clamps an angle to [0, 360] + void compileList (LDObject* obj, const ListType list); // Compile one of the lists of an object + void compileSubObject (LDObject* obj, const GLenum gltype); // Sub-routine for object compiling + void compileVertex (const vertex& vrt); // Compile a single vertex to a list + vertex coordconv2_3 (const QPoint& pos2d, bool snap) const; // Convert a 2D point to a 3D point + QPoint coordconv3_2 (const vertex& pos3d) const; // Convert a 3D point to a 2D point + void drawGLScene () const; // Paint the GL scene + void pick (uint mouseX, uint mouseY); // Perform object selection + void setObjectColor (LDObject* obj, const ListType list); // Set the color to an object list private slots: void slot_toolTipTimer (); diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/gui.cpp --- a/src/gui.cpp Mon May 13 00:04:54 2013 +0300 +++ b/src/gui.cpp Mon May 13 19:53:22 2013 +0300 @@ -773,7 +773,7 @@ m_renderer->hardRefresh (); } -void ForgeWindow::update() { +void ForgeWindow::refresh () { buildObjList (); m_renderer->update (); } diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/gui.h --- a/src/gui.h Mon May 13 00:04:54 2013 +0300 +++ b/src/gui.h Mon May 13 19:53:22 2013 +0300 @@ -129,7 +129,7 @@ void buildObjList (); void setTitle (); void fullRefresh (); - void update (); + void refresh (); ulong getInsertionPoint (); void deleteSelection (vector* ulapIndices, std::vector* papObjects); void updateToolBars (); diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/gui_editactions.cpp --- a/src/gui_editactions.cpp Mon May 13 00:04:54 2013 +0300 +++ b/src/gui_editactions.cpp Mon May 13 19:53:22 2013 +0300 @@ -312,34 +312,32 @@ daColors.push_back (obj->color); obj->color = dColor; + g_win->R ()->compileObject (obj); } } History::addEntry (new SetColorHistory (ulaIndices, daColors, dColor)); - g_win->fullRefresh (); + g_win->refresh (); } } // ============================================================================= // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // ============================================================================= -MAKE_ACTION (makeBorders, "Make Borders", "make-borders", "Add borders around given polygons.", - CTRL_SHIFT (B)) -{ +MAKE_ACTION (makeBorders, "Make Borders", "make-borders", "Add borders around given polygons.", CTRL_SHIFT (B)) { vector objs = g_win->sel (); - - vector ulaIndices; - vector paObjs; + vector historyIndices; + vector historyObjs; for (LDObject* obj : objs) { if (obj->getType() != LDObject::Quad && obj->getType() != LDObject::Triangle) continue; - short dNumLines; + short numLines; LDLine* lines[4]; if (obj->getType() == LDObject::Quad) { - dNumLines = 4; + numLines = 4; LDQuad* quad = static_cast (obj); lines[0] = new LDLine (quad->coords[0], quad->coords[1]); @@ -347,7 +345,7 @@ lines[2] = new LDLine (quad->coords[2], quad->coords[3]); lines[3] = new LDLine (quad->coords[3], quad->coords[0]); } else { - dNumLines = 3; + numLines = 3; LDTriangle* tri = static_cast (obj); lines[0] = new LDLine (tri->coords[0], tri->coords[1]); @@ -355,19 +353,20 @@ lines[2] = new LDLine (tri->coords[2], tri->coords[0]); } - for (short i = 0; i < dNumLines; ++i) { + for (short i = 0; i < numLines; ++i) { ulong idx = obj->getIndex (g_curfile) + i + 1; lines[i]->color = edgecolor; g_curfile->insertObj (idx, lines[i]); - ulaIndices.push_back (idx); - paObjs.push_back (lines[i]->clone ()); + historyIndices.push_back (idx); + historyObjs.push_back (lines[i]->clone ()); + g_win->R ()->compileObject (lines[i]); } } - History::addEntry (new AddHistory (ulaIndices, paObjs)); - g_win->fullRefresh (); + History::addEntry (new AddHistory (historyIndices, historyObjs)); + g_win->refresh (); } // ============================================================================= @@ -392,12 +391,13 @@ g_curfile->insertObj (++idx, vert); ulaIndices.push_back (idx); paObjs.push_back (vert->clone ()); + g_win->R ()->compileObject (vert); } } if (ulaIndices.size() > 0) { History::addEntry (new AddHistory (ulaIndices, paObjs)); - g_win->fullRefresh (); + g_win->refresh (); } } @@ -455,10 +455,11 @@ for (LDObject* obj : g_win->sel ()) { ulaIndices.push_back (obj->getIndex (g_curfile)); obj->move (vVector); + g_win->R ()->compileObject (obj); } History::addEntry (new MoveHistory (ulaIndices, vVector)); - g_win->fullRefresh (); + g_win->refresh (); } MAKE_ACTION (moveXNeg, "Move -X", "move-x-neg", "Move selected objects negative on the X axis.", KEY (Left)) { @@ -506,10 +507,9 @@ g_win->R ()->compileObject (obj); } - printf ("%lu entries\n", history->numEntries ()); if (history->numEntries () > 0) { History::addEntry (history); - g_win->buildObjList (); + g_win->refresh (); } else delete history; } @@ -568,6 +568,8 @@ rad->transform = rad->transform * transform; } else if (obj->getType () == LDObject::Vertex) queue.push_back (&static_cast (obj)->pos); + + g_win->R ()->compileObject (obj); } for (vertex* v : queue) { @@ -576,7 +578,7 @@ v->move (origin); } - g_win->fullRefresh (); + g_win->refresh (); } MAKE_ACTION (rotateXPos, "Rotate +X", "rotate-x-pos", "Rotate objects around X axis", CTRL (Right)) { diff -r ce8e25ccbaf6 -r cfe9ae5f1124 src/ldtypes.cpp --- a/src/ldtypes.cpp Mon May 13 00:04:54 2013 +0300 +++ b/src/ldtypes.cpp Mon May 13 19:53:22 2013 +0300 @@ -212,6 +212,9 @@ for (ulong i = 0; i < g_win->sel ().size(); ++i) if (g_win->sel ()[i] == this) g_win->sel ().erase (g_win->sel ().begin() + i); + + // Delete the GL lists + GL::deleteLists (this); } // =============================================================================