void ccPolyline::drawMeOnly(CC_DRAW_CONTEXT& context) { //no picking enabled on polylines if (MACRO_DrawPointNames(context)) return; unsigned vertCount = size(); if (vertCount < 2) return; bool draw = false; if (MACRO_Draw3D(context)) { draw = !m_mode2D; } else if (m_mode2D) { bool drawFG = MACRO_Foreground(context); draw = ((drawFG && m_foreground) || (!drawFG && !m_foreground)); } if (draw) { //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueIDForDisplay()); if (colorsShown()) ccGL::Color3v(m_rgbColor.rgb); //display polyline if (vertCount > 1) { if (m_width != 0) { glPushAttrib(GL_LINE_BIT); glLineWidth(static_cast<GLfloat>(m_width)); } //DGM: we do the 'GL_LINE_LOOP' manually as I have a strange bug //on one on my graphic card with this mode! //glBegin(m_isClosed ? GL_LINE_LOOP : GL_LINE_STRIP); glBegin(GL_LINE_STRIP); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } if (m_isClosed) { ccGL::Vertex3v(getPoint(0)->u); } glEnd(); //display arrow if (m_showArrow && m_arrowIndex < vertCount && (m_arrowIndex > 0 || m_isClosed)) { const CCVector3* P0 = getPoint(m_arrowIndex == 0 ? vertCount-1 : m_arrowIndex-1); const CCVector3* P1 = getPoint(m_arrowIndex); //direction of the last polyline chunk CCVector3 u = *P1 - *P0; u.normalize(); if (m_mode2D) { u *= -m_arrowLength; static const PointCoordinateType s_defaultArrowAngle = static_cast<PointCoordinateType>(15.0 * CC_DEG_TO_RAD); static const PointCoordinateType cost = cos(s_defaultArrowAngle); static const PointCoordinateType sint = sin(s_defaultArrowAngle); CCVector3 A(cost * u.x - sint * u.y, sint * u.x + cost * u.y, 0); CCVector3 B(cost * u.x + sint * u.y, -sint * u.x + cost * u.y, 0); glBegin(GL_POLYGON); ccGL::Vertex3v((A+*P1).u); ccGL::Vertex3v((B+*P1).u); ccGL::Vertex3v(( *P1).u); glEnd(); } else { if (!c_unitArrow) { c_unitArrow = QSharedPointer<ccCone>(new ccCone(0.5,0.0,1.0)); c_unitArrow->showColors(true); c_unitArrow->showNormals(false); c_unitArrow->setVisible(true); c_unitArrow->setEnabled(true); } if (colorsShown()) c_unitArrow->setTempColor(m_rgbColor); else c_unitArrow->setTempColor(context.pointsDefaultCol); //build-up unit arrow own 'context' CC_DRAW_CONTEXT markerContext = context; markerContext.flags &= (~CC_DRAW_ENTITY_NAMES); //we must remove the 'push name flag' so that the sphere doesn't push its own! markerContext._win = 0; glMatrixMode(GL_MODELVIEW); glPushMatrix(); ccGL::Translate(P1->x,P1->y,P1->z); ccGLMatrix rotMat = ccGLMatrix::FromToRotation(CCVector3(0,0,1),u); glMultMatrixf(rotMat.inverse().data()); glScalef(m_arrowLength,m_arrowLength,m_arrowLength); ccGL::Translate(0.0,0.0,-0.5); c_unitArrow->draw(markerContext); glPopMatrix(); } } if (m_width != 0) { glPopAttrib(); } } //display vertices if (m_showVertices) { glPushAttrib(GL_POINT_BIT); glPointSize((GLfloat)m_vertMarkWidth); glBegin(GL_POINTS); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); glPopAttrib(); } if (pushName) glPopName(); } }
void ccPolyline::drawMeOnly(CC_DRAW_CONTEXT& context) { //no picking enabled on polylines if (MACRO_DrawPointNames(context)) return; unsigned vertCount = size(); if (vertCount < 2) return; bool draw = false; if (MACRO_Draw3D(context)) { draw = !m_mode2D; } else if (m_mode2D) { bool drawFG = MACRO_Foreground(context); draw = ((drawFG && m_foreground) || (!drawFG && !m_foreground)); } if (draw) { //standard case: list names pushing bool pushName = MACRO_DrawEntityNames(context); if (pushName) glPushName(getUniqueIDForDisplay()); if (colorsShown()) glColor3ubv(m_rgbColor); //display polyline { if (m_width != 0) { glPushAttrib(GL_LINE_BIT); glLineWidth(static_cast<GLfloat>(m_width)); } glBegin(m_isClosed ? GL_LINE_LOOP : GL_LINE_STRIP); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); if (m_width != 0) { glPopAttrib(); } } //display vertices if (m_showVertices) { glPushAttrib(GL_POINT_BIT); glPointSize((GLfloat)m_vertMarkWidth); glBegin(GL_POINTS); for (unsigned i=0; i<vertCount; ++i) { ccGL::Vertex3v(getPoint(i)->u); } glEnd(); glPopAttrib(); } if (pushName) glPopName(); } }
void ccHObject::draw(CC_DRAW_CONTEXT& context) { if (!isEnabled()) return; //are we currently drawing objects in 2D or 3D? bool draw3D = MACRO_Draw3D(context); //the entity must be either visible and selected, and of course it should be displayed in this context bool drawInThisContext = ((m_visible || m_selected) && m_currentDisplay == context._win); //no need to display anything but clouds and meshes in "element picking mode" drawInThisContext &= ( ( !MACRO_DrawPointNames(context) || isKindOf(CC_TYPES::POINT_CLOUD) ) || ( !MACRO_DrawTriangleNames(context) || isKindOf(CC_TYPES::MESH) )); //apply 3D 'temporary' transformation (for display only) if (draw3D && m_glTransEnabled) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(m_glTrans.data()); } //draw entity if (m_visible && drawInThisContext) { if (( !m_selected || !MACRO_SkipSelected(context) ) && ( m_selected || !MACRO_SkipUnselected(context) )) { //apply default color (in case of) glColor3ubv(context.pointsDefaultCol); drawMeOnly(context); //draw name in 3D (we display it in the 2D foreground layer in fact!) if (m_showNameIn3D && MACRO_Draw2D(context) && MACRO_Foreground(context) && !MACRO_DrawNames(context)) drawNameIn3D(context); } } //draw entity's children for (Container::iterator it = m_children.begin(); it != m_children.end(); ++it) (*it)->draw(context); //if the entity is currently selected, we draw its bounding-box if (m_selected && draw3D && drawInThisContext && !MACRO_DrawNames(context)) { switch (m_selectionBehavior) { case SELECTION_AA_BBOX: drawBB(context.bbDefaultCol); break; case SELECTION_FIT_BBOX: { ccGLMatrix trans; ccBBox box = getFitBB(trans); if (box.isValid()) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(trans.data()); box.draw(context.bbDefaultCol); glPopMatrix(); } } break; case SELECTION_IGNORED: break; default: assert(false); } } if (draw3D && m_glTransEnabled) glPopMatrix(); }
void ccHObject::draw(CC_DRAW_CONTEXT& context) { if (!isEnabled()) return; bool draw3D = MACRO_Draw3D(context); bool drawInThisContext = (!m_visible && !m_selected ? false : m_currentDisplay == context._win); //no need to display anything but clouds and meshes in "point picking mode" bool DrawMesh = false; if (MACRO_DrawTriangleNames(context) && isKindOf(CC_MESH)) { ccGenericMesh *mesh = static_cast<ccGenericMesh*>(this); ccGenericPointCloud *cloud = mesh->getAssociatedCloud(); DrawMesh = (cloud == NULL || !cloud->isEnabled()); } drawInThisContext &= ( (!MACRO_DrawPointNames(context) || isKindOf(CC_POINT_CLOUD)) || (!MACRO_DrawTriangleNames(context) || DrawMesh) ); //apply 3D 'temporary' transformation (for display only) if (draw3D && m_glTransEnabled) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(m_glTrans.data()); } //draw entity if (m_visible && drawInThisContext) { if ((!m_selected || !MACRO_SkipSelected(context)) && (m_selected || !MACRO_SkipUnselected(context))) { glColor3ubv(context.pointsDefaultCol); drawMeOnly(context); //draw name in 3D (we display it in the 2D foreground layer in fact!) if (m_showNameIn3D && MACRO_Draw2D(context) && MACRO_Foreground(context) && !MACRO_DrawNames(context)) drawNameIn3D(context); } } //draw entity's children for (Container::iterator it = m_children.begin(); it!=m_children.end(); ++it) (*it)->draw(context); //if the entity is currently selected if (m_selected && draw3D && drawInThisContext) { switch (m_selectionBehavior) { case SELECTION_AA_BBOX: drawBB(context.bbDefaultCol); break; case SELECTION_FIT_BBOX: { ccGLMatrix trans; ccBBox box = getFitBB(trans); if (box.isValid()) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(trans.data()); box.draw(context.bbDefaultCol); glPopMatrix(); } } break; case SELECTION_IGNORED: break; default: assert(false); } } if (draw3D && m_glTransEnabled) glPopMatrix(); }
//================================================draw====================================================// void ccHObject::draw(CC_DRAW_CONTEXT& context) { if (!isEnabled())return; //是否开启 //are we currently drawing objects in 2D or 3D? bool draw3D = MACRO_Draw3D(context); //判断是在三维上绘制还是在二维上绘制? //the entity must be either visible and selected, and of course it should be displayed in this context //是否可视,是否被选择,是否在当前窗口下显示 bool drawInThisContext = ((m_visible || m_selected) && m_currentDisplay == context._win); //no need to display anything but clouds and meshes in "element picking mode" drawInThisContext &= ( ( !MACRO_DrawPointNames(context) || isKindOf(CC_TYPES::POINT_CLOUD) ) || ( !MACRO_DrawTriangleNames(context) || isKindOf(CC_TYPES::MESH) )); if (draw3D){ //apply 3D 'temporary' transformation (for display only) if (m_glTransEnabled){ //可以进行变换 glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(m_glTrans.data()); } if ( context.decimateCloudOnMove //LOD for clouds is enabled? && context.currentLODLevel >= context.minLODLevel //and we are currently rendering higher levels? ){ //only for real clouds drawInThisContext &= isA(CC_TYPES::POINT_CLOUD); //LOD只对点云有效?????????? } } //draw entity if (m_visible && drawInThisContext){ if (( !m_selected || !MACRO_SkipSelected(context) ) && ( m_selected || !MACRO_SkipUnselected(context) )) { //apply default color (in case of) ccGL::Color3v(context.pointsDefaultCol.rgb); //不同的物体绘制方式不同 drawMeOnly(context); //draw name in 3D (we display it in the 2D foreground layer in fact!) if (m_showNameIn3D && MACRO_Draw2D(context) && MACRO_Foreground(context) && !MACRO_DrawNames(context)) drawNameIn3D(context); } } //draw entity's children //绘制物体的子物体 for (Container::iterator it = m_children.begin(); it != m_children.end(); ++it) (*it)->draw(context); //绘制BB //if the entity is currently selected, we draw its bounding-box if (m_selected && draw3D && drawInThisContext && !MACRO_DrawNames(context) && context.currentLODLevel == 0){ drawBB(context.bbDefaultCol); } if (draw3D && m_glTransEnabled) glPopMatrix(); }
void ccHObject::draw(CC_DRAW_CONTEXT& context) { if (!isEnabled()) return; bool draw3D = MACRO_Draw3D(context); bool drawInThisContext = (!visible && !selected ? false : currentDisplay == context._win); //no need to display anything but clouds in "point picking mode" drawInThisContext &= (!MACRO_DrawPointNames(context) || isKindOf(CC_POINT_CLOUD)); //apply 3D 'temporary' transformation (for display only) if (draw3D && glTransEnabled) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(glTrans.data()); } //draw entity if (visible && drawInThisContext) { if ((!selected || !MACRO_SkipSelected(context)) && (selected || !MACRO_SkipUnselected(context))) { glColor3ubv(context.pointsDefaultCol); drawMeOnly(context); } } //draw entity's children for (Container::iterator it = m_children.begin(); it!=m_children.end(); ++it) (*it)->draw(context); //if the entity is currently selected if (selected && draw3D && drawInThisContext) { switch (m_selectionBehavior) { case SELECTION_AA_BBOX: drawBB(context.bbDefaultCol); break; case SELECTION_FIT_BBOX: { ccGLMatrix trans; ccBBox box = getFitBB(trans); if (box.isValid()) { glMatrixMode(GL_MODELVIEW); glPushMatrix(); glMultMatrixf(trans.data()); box.draw(context.bbDefaultCol); glPopMatrix(); } } break; case SELECTION_IGNORED: break; default: assert(false); } } if (draw3D && glTransEnabled) glPopMatrix(); }