common/gluvi.cpp
/** 
     * Draw a vector in 3D.  If arrow_head_length not specified, set it to 10% of vector length.
     * Mar 29, 2006
     */
Draw a vector in 3D.  If arrow_head_length not specified, set it to 10% of vector length.
Draw a vector in 3D . If arrow_head_length not specified set it to 10% of vector length .
void draw_3d_arrow(const float base[3], const float point[3], float arrow_head_length)
    {
        glLineWidth(1);
        glColor3f(0.5f,0.5f,0.5f);
        Vec3f w(point[0]-base[0], point[1]-base[1], point[2]-base[2]);
        float len = mag(w);
        w = w / len;    
        Vec3f u = cross(w, Vec3f(0,1,0));
        if (mag(u) == 0)
            u = cross(w, Vec3f(1,0,0));
        Vec3f v = cross(w, u/mag(u));
        v = v/mag(v);
        if (!arrow_head_length)
            arrow_head_length = 0.1f * len;
        Vec3f arrow1, arrow2;
        arrow1[0] = point[0] + arrow_head_length * (v[0] - w[0]);
        arrow1[1] = point[1] + arrow_head_length * (v[1] - w[1]);
        arrow1[2] = point[2] + arrow_head_length * (v[2] - w[2]);
        arrow2[0] = point[0] + arrow_head_length * (-v[0] - w[0]);
        arrow2[1] = point[1] + arrow_head_length * (-v[1] - w[1]);
        arrow2[2] = point[2] + arrow_head_length * (-v[2] - w[2]);
        glBegin(GL_LINES);
        glVertex3f(base[0],   base[1],   base[2]);
        glVertex3f(point[0],  point[1],  point[2]);
        glVertex3f(point[0],  point[1],  point[2]);
        glVertex3f(arrow1[0], arrow1[1], arrow1[2]);
        glVertex3f(point[0],  point[1],  point[2]);
        glVertex3f(arrow2[0], arrow2[1], arrow2[2]);
        glEnd();
    }
void draw_3d_arrow ( const float base [ 3 ] , const float point [ 3 ] , float arrow_head_length ) { glLineWidth ( 1 ) ; glColor3f ( 0.5f , 0.5f , 0.5f ) ; Vec3f w ( point [ 0 ] - base [ 0 ] , point [ 1 ] - base [ 1 ] , point [ 2 ] - base [ 2 ] ) ; float len = mag ( w ) ; w = w / len ; Vec3f u = cross ( w , Vec3f ( 0 , 1 , 0 ) ) ; if ( mag ( u ) == 0 ) u = cross ( w , Vec3f ( 1 , 0 , 0 ) ) ; Vec3f v = cross ( w , u / mag ( u ) ) ; v = v / mag ( v ) ; if ( ! arrow_head_length ) arrow_head_length = 0.1f * len ; Vec3f arrow1 , arrow2 ; arrow1 [ 0 ] = point [ 0 ] + arrow_head_length * ( v [ 0 ] - w [ 0 ] ) ; arrow1 [ 1 ] = point [ 1 ] + arrow_head_length * ( v [ 1 ] - w [ 1 ] ) ; arrow1 [ 2 ] = point [ 2 ] + arrow_head_length * ( v [ 2 ] - w [ 2 ] ) ; arrow2 [ 0 ] = point [ 0 ] + arrow_head_length * ( - v [ 0 ] - w [ 0 ] ) ; arrow2 [ 1 ] = point [ 1 ] + arrow_head_length * ( - v [ 1 ] - w [ 1 ] ) ; arrow2 [ 2 ] = point [ 2 ] + arrow_head_length * ( - v [ 2 ] - w [ 2 ] ) ; glBegin ( GL_LINES ) ; glVertex3f ( base [ 0 ] , base [ 1 ] , base [ 2 ] ) ; glVertex3f ( point [ 0 ] , point [ 1 ] , point [ 2 ] ) ; glVertex3f ( point [ 0 ] , point [ 1 ] , point [ 2 ] ) ; glVertex3f ( arrow1 [ 0 ] , arrow1 [ 1 ] , arrow1 [ 2 ] ) ; glVertex3f ( point [ 0 ] , point [ 1 ] , point [ 2 ] ) ; glVertex3f ( arrow2 [ 0 ] , arrow2 [ 1 ] , arrow2 [ 2 ] ) ; glEnd ( ) ; }
Draw a vector in 3D.
Draw a vector in 3D .
//glPushAttrib(GL_CURRENT_BIT|GL_ENABLE_BIT|GL_LINE_BIT); //glDisable(GL_LIGHTING); // normalize to build coordinate system // create a coordinate system from the vector: // get a vector perp to w and y-axis // If vector is parallel to the y-axis, use the x-axis // get a vector perp to w and u // arrow head points //@@@@@@@ POSSIBILITY: CREATE FOUR ARROW HEAD SEGMENTS INSTEAD OF TWO //glPopAttrib();