obj File loader Bezier curve

Hello everyone!

I want to load an obj file with opengl which shows a bezier curve.

I know how to load the v, vt, f.
The if-query for the “v” looks like this:


if(prefix.compare("v")==0) 
		{
			line = line.substr(line.find_first_of("v")+2);
			Vertex v;

			istringstream s(line);
			s>>v.x;
			s>>v.y;
			s>>v.z;
			if(v.x<min[0])
				min[0] = v.x;
			if(v.y<min[1])
				min[1] = v.y;
			if(v.z<min[2])
				min[2] = v.z;

			if(v.x>max[0])
				max[0] = v.x;
			if(v.y>max[1])
				max[1] = v.y;
			if(v.z>max[2])
				max[2] = v.z;
			mesh.vertices.push_back(v);
		}

But how can I make the If- Query to load the ctype, deg and curve?
I only have this so far:


if (prefix.compare("deg")==0)
		{
			line = line.substr(line.find_first_of("deg")+1);// deg +1;
 
		}
		
		if (prefix.compare("curve")==0)
		{
			// curve
		}


here is an example obj File Bezier curve


v 0.0 0.0 0.0
v 0.0 1.0 0.0
v 1.0 1.0 0.0
v 1.0 0.0 0.0
cstype bezier
deg 3
curv 1 2 3 4
end

This is actually a c++ question so would not noramlly be answered here; but try this


if (prefix.compare("deg")==0)        
{            
  line = line.substr(line.find("deg")+4);// deg +1; 
   istringstream s(line);
  s>>degree;     
}        
if (prefix.compare("curve")==0)        
{            // curve        
  line = line.substr(line.find("curve")+6);// curve+1; 
  istringstream s(line)
  s>>curve.v1;     
  s>>curve.v2;     
  s>>curve.v3     
  s>>curve.v4;     
}

Thank you very much. I will try that out:D

Now I have another problem with that. Maybe you can help me there as well?
How do i implement the class method to the if queries of “deg” and curve"?
Something like this or how shall I implement this?

struct Degree
{
float d;
};

struct Curve {
float v;

int order;
struct Vertex vertex;
};

I found an example to draw the bezier curve.
But how can I put all together so that I can load the Beziercurve from an obj file and draw it?

Here is the example I found:


 #include <iostream>
    #include <glut.h>
    
    struct point {
      float x;
      float y;
    };
     
     
     

    void reshape( int w, int h )
    {
      glViewport( 0, 0, w, h );
      glMatrixMode( GL_PROJECTION );
      glLoadIdentity();
      glOrtho( 0, w, 0, h, -1, 1);
      glMatrixMode( GL_MODELVIEW );
    }
     
    point linearInterpolate( point pA, point pB, float t )
    {
      point returnPoint;
     
      returnPoint.x = pA.x + (pB.x - pA.x)*t;
      returnPoint.y = pA.y + (pB.y - pA.y)*t;    
      return returnPoint;
    }
 
    void markPoint( point p )
    {
      glBegin( GL_POINTS );
      glVertex2i( p.x - 2, p.y - 2 );
      glVertex2i( p.x    , p.y - 2 );
      glVertex2i( p.x + 2, p.y - 2 );
     
      glVertex2i( p.x - 2, p.y     );
      glVertex2i( p.x + 2, p.y     );
     
      glVertex2i( p.x - 2, p.y + 2 );
      glVertex2i( p.x    , p.y + 2 );
      glVertex2i( p.x + 2, p.y + 2 );
      glEnd();
    }
     
  //
    void drawBezier( point p0, point p1, point p2, point p3 )
    {
     
            float steps = 100;
     
            glBegin( GL_POINTS );
            for(int i = 0; i < steps; i++) {
                    float t = (float)i / (steps - 1);
                    point resP = linearInterpolate(
                            linearInterpolate(
                                    linearInterpolate(p0, p1, t),
                                    linearInterpolate(p1, p2, t),
                            t),
                            linearInterpolate(
                                    linearInterpolate(p1, p2, t),
                                    linearInterpolate(p2, p3, t),
                            t),
                    t);
                    glVertex2i(resP.x, resP.y);
            }
            glEnd();
    }
     
     
     
    void draw()
    {
            glClear( GL_COLOR_BUFFER_BIT );
     
      point p0;
      point p1;
      point p2;
      point p3;
     
     
      p0.x = 10; 
      p0.y = 10; 
     
      p1.x = 100; 
      p1.y = 350;
     
      p2.x = 350; 
      p2.y = 150; 
     
      p3.x = 500;
      p3.y = 400;
     
      glColor3f( 1.0f, 0.0f, 0.0f );
      markPoint( p0 );
     
      glColor3f( 0.0f, 1.0f, 0.0f );
      markPoint( p1 );
     
      glColor3f( 0.0f, 0.0f, 1.0f );
      markPoint( p2 );
     
      glColor3f( 1.0f, 1.0f, 0.0f );
      markPoint( p3 );
     
      glColor3f( 1.0f, 1.0f, 1.0f );
      drawBezier( p0, p1, p2, p3 );
     
      glutSwapBuffers();
    }
     

    int main (int argc, char*  argv[] )
    {
     [....]
    }


Please help me