Turtle graphics, move without drawing question

Hello,

I am trying to create a 3D Turtle. I have successfully been able to draw a line from (x,y,z) to (x’,y’,z’) using ofPolyline lineTo and addVertex methods.

My issue arises when I try to move to another point without drawing. Is there a way I could do this using ofPolyline, or should I try another way? Which way, how?

Here is some of my code;

.h:

ofPolyline line;

.cpp:

float xCoord = 250.0;
float yCoord = 250.0;
float zCoord = 250.0;
// -------- Vector variables
float xVec = 1;// x of vector
float yVec = 0;// y of vector
float zVec = 0;// z of vector

//--------------------------------------------------------------
void ofApp::setup(){
ofBackground(0,0,0);
    ofPoint pt;
    pt.set(xCoord , yCoord, zCoord);
    camDist  = 1000; // set the camera distance
    cam.setDistance(camDist);
    }

void ofApp::keyPressed(int key){
switch(key)
{
case 102:
        {
            xCoord = xCoord + (xVec * stepSize);
            yCoord = yCoord + (yVec * stepSize);
            zCoord = zCoord + (zVec * stepSize); 
     
         ofPoint pt; 
         pt.set(xCoord, yCoord, zCoord);
         line.addVertex(pt); line is an ofPolyline

//  // this also works:
//  line.lineTo(xCoord, yCoord, zCoord);
}
break;
}

The question is how would I make it move without drawing, leave a gap, and then draw again without connecting to previous point. I tried leaving the addVertex method out by doing this:

case 70:// F, move forward but not draw  // --------------------------------
        {          
            xCoord = xCoord + (xVec * stepSize);
            yCoord = yCoord + (yVec * stepSize);
            zCoord = zCoord + (zVec * stepSize);
            
            ofPoint pt;
            pt.set(xCoord, yCoord, zCoord);// sets a point and then draws the line to that point   
        }

but as soon as I drew another line it would connect to the last drawn point.
Any help or suggestion is welcome.

Thanks!
Irv.

You can’t do it with ofPolyline . ofPolyline connects all the points in the container together, without any interruption. I would suggest you to use ofMesh and the OF_PRIMITIVE_LINES. On the OF website there is a nice tutorial about how to use the ofMesh class. Basically, you have to move the turtle, and put in the mesh the starting point and the ending point for the line that you want to draw. If you don’t want to draw a line, simply don’t put the starting point and the ending point in the mesh.
I would suggest you first to draw 2 separate lines with ofMesh, and then try to implement that in your program.

you can also ofPath which apart from lineTo also has moveTo, internally it’ll just use several polylines that you can later recover using getContous.

to work with contours only you’ll need to setFilled(false) and setContourWidth(1)

Thank you for your prompt responses. I went for the ofPath because it seems more simple to me, although I may be wrong. But is working for these tasks.

The mesh does seem interesting for further explorations of the drawn results, I may try it later, once everything is set and running.

Best,
Irving.