Question

C++/Opengl: Object Oriented Bezier Curves

Asked by: eye30

Hi, I'm relatively new to OOP/C++/Opengl.  Thanks in advance.

I want to create multiple Bezier curves in a OOP class structure.  Eventually I would like to create multiple bezier curves with different attributes like x, y position, line thickness, etc.

I'm having difficulty with pointer/array portion.  I want to create an array of 100 bezier curves.  These individual curves are set up in an 6x3 array.  I'm getting 2 errors.  

My code:
#include <windows.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <iostream.h>
#include <time.h>

//function prototypes

//Define bezier class for animation

class BezierClass {

      public:
      float x1,y1;
      float x2,y2;
      float x_cp1,y_cp1;
      float x_cp2,y_cp2;
      float x_cp3,y_cp3;
      float x_cp4,y_cp4;
      float xpos,ypos;

      BezierClass() {
      float bezierArray[6][3] =
                  { {x1, y1, 0.0},      /* 1st End Point */
                  {x_cp1, y_cp1, 0.0},      /* 1st Control P. */
                  {x_cp2, y_cp2, 0.0},      /* 2nd Control P. */
                  {x_cp3, y_cp3, 0.0},      /* 3rd Control P. */
                  {x_cp4, y_cp4, 0.0},      /* 3th Control P. */
                  {x2, y2, 0.0} };            /* 2nd End Point */;

      }

};


/* Create an array of type bezierClass that may hold 100 beziers */
BezierClass bezierArray[100];
int beziernum=0;
int totalbezier=5;
float zoom = -7;

void InitGL(int Width, int Height)
{
      glClearDepth(1.0);
      glClearColor(0.0, 0.0, 0.0, 0.0);      /* bg color = black */
      glDepthFunc(GL_LESS);                  /* nearer appears nearer */
      glEnable(GL_DEPTH_TEST);            /* enable depth testing */
      glShadeModel(GL_SMOOTH);            /* shade colors smooth */
      glMatrixMode(GL_PROJECTION);            /* switch the matrix */
      glLoadIdentity();                  /* reset the cur. matrix */
      gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
      glMatrixMode(GL_MODELVIEW);            /* switch matrix back */
}

void DrawGLScene(void)
{
      int i;                              /* temp var */

      /* Clear the screen and the buffers */
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();                  /* reset cur. matrix */
      glTranslatef(0.0f, 0.0f, -10.0f);      /* move the cam */

      /* ok, this is the main point of our bezier curve
       * void glMap1f(GLenum target, float u1, float u2, int stride
       *          int order, const float *points);
       * target is one of these:
       * GL_MAP1_VERTEX_3      (Vertex Coordinates (xyz))
       * GL_MAP1_VERTEX_4      (Vertex Coordinates (xyzw))
       * GL_MAP1_INDEX      (Color Index)
       * GL_MAP1_COLOR_4      (Color Values (rgba))
       * GL_MAP1_NORMAL      (Normal Coordinates)
       * GL_MAP1_TEXTURE_COORD_1/2/3/4 (Texture Coordinates(s/st/str/strq)
       *
       * no idea what u1 and u2 these are, but it works with 0.0 and 1.0
       * stride is the distance between each point on the curve
       * order should always just fit the number of the points
       * points is just a pointer to the pointdata(array)*/
////********error here: says "pointer/array required"//////////////

                glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, &bezierArray[0][0]);
               

      glEnable(GL_MAP1_VERTEX_3);            /* enable the mode */

      glColor3f(1.0, 1.0, 1.0);            /* set color to white */

      glBegin(GL_LINE_STRIP);                  /* start drawing */
            for(i = 0; i <= 60; i++)
            {
                  /* start evaluating the points
                   * void glEvalCoord1f(float u);
                   * u is the current point we evaluate */
                  glEvalCoord1f((float)i/60.0f);
            }
      glEnd();                        /* stop drawing */

      glPointSize(3.0);                  /* set point size to 3px */
      glColor3f(1.0f, 1.0f, 0.0f);            /* set color to yellow */
      glBegin(GL_POINTS);                  /* start drawing again */
            for(i = 0; i < 6; i++)
            {
                  /* draw all control/end points */
////********error here: says "pointer/array required"//////////////
                  glVertex3fv(&bezierArray[i][0]);
            }
      glEnd();

      glFlush();                        /* Flush all buffers */
      glutSwapBuffers();                  /* Sawp buffers */
      return;
}

void reshape(int w, int h)
{
      glViewport(0, 0, (GLint) w, (GLint) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();

      if ( h==0)
            gluPerspective(45, (GLdouble)w, 1.0, 100.0);
      else
            gluPerspective(45, (GLdouble)w/(GLdouble)h,1.0, 100.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

//test-trying to make the bezier curve move in y direction.

void idle_func (void)
{
for (beziernum=0 ;beziernum < 100; beziernum++) {
   //bezierArray[beziernum].ypos+=1;

   }
   glutPostRedisplay();
}

/*  Main Loop
 *  Open window with initial window size, title bar,
 *  RGBA display mode, and handle input events.
 */
int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
   glutInitWindowSize (800, 600);
   glutCreateWindow (argv[0]);
   glutReshapeFunc (reshape);
   glutDisplayFunc (DrawGLScene);
   glutIdleFunc (idle_func);
   glutMainLoop();
   return 0;
}
//end of code



This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2003-11-26 at 14:31:51ID20809629
Tags

opengl

,

bezier

,

curve

Topic

OpenGL Graphics & Game Programming

Participating Experts
2
Points
250
Comments
5

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. OpenGL Texture Mapping
    Hey folks, I need a piece of Delphi4-code that makes use of plain OpenGL-syntax and does the following: A rectangle with a texture on it (loaded from a BMP) turning e.g. around the z-axis with a background image (also loaded from a BMP) behind the scene. The main problem is ...
  2. OpenGl
    ONLY OPENGL CODE WILL BE ACCEPTED!!! I need a sample program of a bitmap that looks like a ball thrown up. When gravity overpowers the throw the ball should fall down. Please do not not use glut.h use only gl.h or glu.h I will assign extra 50 points if the program works!!!
  3. Texture Mapping OpenGl
    Hi, I need to do a texture mapping on a 3D object, cube mapping,sphere mapping and cylinder mapping. My program now,includes the ability to load *.skl format,then *.obj/*.off and then *.wgt(weights file). I have hierarchy window which has a tree of all the skeleton bone heira...
  4. Desktop As an OpenGL Texture
    Hi, I would like to get a screenshot of my desktop as a texture to use with opengl (realtime, no file loading). I'm writing my own screensaver so i'm using MFC under Visual C++. Thanks a lot !
  5. OpenGL texture loading from an array
    Question: I have an image that is already stored in memory. How do I load it as an OpenGL texture? The image is stored as an array of unsigned int and represents a 32x32 pixel image, with each pixel stored as 3 sequential unsigned int values in RGB order. I have tried: G...
  6. Window Coordinates (OpenGL)-> coordinates with reg…
    This question pertains to OpenGL. I have a rotated texture. The coordinates I have for some other part of the program are in Windows coordinates (full on view, zero rotation). How can I tranform these coordinates to fall within the rotated textures object coordinates? Than...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: sunnycoderPosted on 2003-11-26 at 21:33:39ID: 9829715

>glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, &bezierArray[0][0]);

from the man page::::
points is the location of  the first control point, which occupies one,  two,  three, or  four  contiguous  memory locations, depending on which map is being defined.

so you really should be passing &bezierArray[1][0] ... but anyway, it should not have complained as the data types look right ...

try casting to GLfloat *

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, (GLfloat *)&bezierArray[0][0]);

If that does not work, tell us the following:
what is the platform? ... also what is the exact error message (along with the error number)

 

by: eye30Posted on 2003-11-26 at 21:51:49ID: 9829774

I tried the cast as you suggested, still spits out 3 errors.  I wrote the errors in the previous code.  I'll rewrite them here to make them clearer and more obvious.  Thanks again.  

#include <windows.h>
#include <GL/glu.h>
#include <GL/glut.h>
#include <GL/glut.h>
#include <stdlib.h>
#include <iostream.h>
#include <time.h>

class BezierClass {

      public:
      float x1,y1;
      float x2,y2;
      float x_cp1,y_cp1;
      float x_cp2,y_cp2;
      float x_cp3,y_cp3;
      float x_cp4,y_cp4;
      float xpos,ypos;
      float bezierArray[6][3];
      
      BezierClass() {
            float x1,y1;
            float x2,y2;
            float x_cp1,y_cp1;
            float x_cp2,y_cp2;
            float x_cp3,y_cp3;
            float x_cp4,y_cp4;
            float xpos,ypos;


             bezierArray[6][3]={ {x1, y1, 0.0},      ********error here:Expression syntax error****

                  {x_cp1, y_cp1, 0.0},      /* 1st Control P. */
                  {x_cp2, y_cp2, 0.0},      /* 2nd Control P. */
                  {x_cp3, y_cp3, 0.0},      /* 3rd Control P. */
                  {x_cp4, y_cp4, 0.0},      /* 3th Control P. */
                  {x2, y2, 0.0}      };      /* 2nd End Point */
            }      
      

};

/* Create an array of type bezierClass that may hold 100 beziers */
BezierClass bezier[100];
int beziernum=0;
int totalbezier=5;
float zoom = -7;

void InitGL(int Width, int Height)
{
      glClearDepth(1.0);
      glClearColor(0.0, 0.0, 0.0, 0.0);      /* bg color = black */
      glDepthFunc(GL_LESS);                  /* nearer appears nearer */
      glEnable(GL_DEPTH_TEST);            /* enable depth testing */
      glShadeModel(GL_SMOOTH);            /* shade colors smooth */
      glMatrixMode(GL_PROJECTION);            /* switch the matrix */
      glLoadIdentity();                  /* reset the cur. matrix */
      gluPerspective(45.0f,(GLfloat)Width/(GLfloat)Height,0.1f,100.0f);
      glMatrixMode(GL_MODELVIEW);            /* switch matrix back */
}

void DrawGLScene(void)
{
      int i;                              /* temp var */

      /* Clear the screen and the buffers */
      glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
      glLoadIdentity();                  /* reset cur. matrix */
      glTranslatef(0.0f, 0.0f, -10.0f);      /* move the cam */

      glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, (GLfloat*) bezier[0].bezierArray[1][0]); ********error here********
                        (Error: Illegal explicit conversion from 'float' to 'float*')

      glEnable(GL_MAP1_VERTEX_3);            /* enable the mode */

      glColor3f(1.0, 1.0, 1.0);            /* set color to white */

      glBegin(GL_LINE_STRIP);                  /* start drawing */
            for(i = 0; i <= 60; i++)
            {
                  glEvalCoord1f((float)i/60.0f);
            }
      glEnd();                        /* stop drawing */

      glPointSize(3.0);                  /* set point size to 3px */
      glColor3f(1.0f, 1.0f, 0.0f);            /* set color to yellow */
      glBegin(GL_POINTS);                  /* start drawing again */
            for(i = 0; i < 6; i++)
            {
                  /* draw all control/end points */
                  glVertex3fv((GLfloat*)bezier[0].bezierArray[i][0]);********error here********
                                                (Error: Illegal explicit conversion from 'float' to 'float*')
            }
      glEnd();

      glFlush();                        /* Flush all buffers */
      glutSwapBuffers();                  /* Sawp buffers */
      return;
}

void reshape(int w, int h)
{
      glViewport(0, 0, (GLint) w, (GLint) h);
                glMatrixMode(GL_PROJECTION);
                glLoadIdentity();

      if ( h==0)
            gluPerspective(45, (GLdouble)w, 1.0, 100.0);
      else
            gluPerspective(45, (GLdouble)w/(GLdouble)h,1.0, 100.0);
                glMatrixMode(GL_MODELVIEW);
                glLoadIdentity();
}

void idle_func (void)
{
for (beziernum=0 ;beziernum < 100; beziernum++) {
   //bezierArray[beziernum].ypos+=1;

   }
   glutPostRedisplay();
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE);
   glutInitWindowSize (800, 600);
   glutCreateWindow (argv[0]);
   glutReshapeFunc (reshape);
   glutDisplayFunc (DrawGLScene);
   glutIdleFunc (idle_func);
   glutMainLoop();
   return 0;
}





 

by: sunnycoderPosted on 2003-11-26 at 21:58:54ID: 9829798

>    glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, (GLfloat*) bezier[0].bezierArray[1][0]); ********error here********
>                       (Error: Illegal explicit conversion from 'float' to 'float*')

glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 6, (GLfloat*) &(bezier[0].bezierArray[1][0]) );

>glVertex3fv((GLfloat*)bezier[0].bezierArray[i][0]);********error here********
>                                               (Error: Illegal explicit conversion from 'float' to 'float*')

glVertex3fv((GLfloat*) &(bezier[0].bezierArray[i][0]));

 

by: sunnycoderPosted on 2003-11-26 at 22:21:01ID: 9829865

just checked your class definition

class BezierClass {

    public:
    float x1,y1;
    float x2,y2;
    float x_cp1,y_cp1;
    float x_cp2,y_cp2;
    float x_cp3,y_cp3;
    float x_cp4,y_cp4;
    float xpos,ypos;

    BezierClass() {
    float bezierArray[6][3] =
              { {x1, y1, 0.0},     /* 1st End Point */
               {x_cp1, y_cp1, 0.0},     /* 1st Control P. */
               {x_cp2, y_cp2, 0.0},     /* 2nd Control P. */
               {x_cp3, y_cp3, 0.0},     /* 3rd Control P. */
               {x_cp4, y_cp4, 0.0},     /* 3th Control P. */
               {x2, y2, 0.0} };          /* 2nd End Point */;

    }

};

bezierArray is not a member of your class ... rather it is a local variable for the constructor ... perhaps you would like to include it as a class member and initialize it in the constructor ...

 

by: Tsiu6Posted on 2005-03-12 at 23:08:00ID: 13527595

Error Free Solid Code

#include "stdafx.h"

/*  bezcurve.c                  
 *  This program uses evaluators to draw a Bezier curve.
 */
#include <stdlib.h>
#include <GL/glut.h>

GLfloat ctrlpoints[4][3] = {
      { -4.0, -4.0, 0.0}, { -2.0, 4.0, 0.0},
      {2.0, -4.0, 0.0}, {4.0, 4.0, 0.0}};

void init(void)
{
   glClearColor(0.0, 0.0, 0.0, 0.0);
   glShadeModel(GL_FLAT);
   glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, &ctrlpoints[0][0]);
   glEnable(GL_MAP1_VERTEX_3);
}

void display(void)
{
   int i;

   glClear(GL_COLOR_BUFFER_BIT);
   glColor3f(1.0, 1.0, 1.0);
   glBegin(GL_LINE_STRIP);
      for (i = 0; i <= 30; i++)
         glEvalCoord1f((GLfloat) i/30.0);
   glEnd();
   /* The following code displays the control points as dots. */
   glPointSize(5.0);
   glColor3f(1.0, 1.0, 0.0);
   glBegin(GL_POINTS);
      for (i = 0; i < 4; i++)
         glVertex3fv(&ctrlpoints[i][0]);
   glEnd();
   glFlush();
}

void reshape(int w, int h)
{
   glViewport(0, 0, (GLsizei) w, (GLsizei) h);
   glMatrixMode(GL_PROJECTION);
   glLoadIdentity();
   if (w <= h)
      glOrtho(-5.0, 5.0, -5.0*(GLfloat)h/(GLfloat)w,
               5.0*(GLfloat)h/(GLfloat)w, -5.0, 5.0);
   else
      glOrtho(-5.0*(GLfloat)w/(GLfloat)h,
               5.0*(GLfloat)w/(GLfloat)h, -5.0, 5.0, -5.0, 5.0);
   glMatrixMode(GL_MODELVIEW);
   glLoadIdentity();
}

/* ARGSUSED1 */
void keyboard(unsigned char key, int x, int y)
{
   switch (key) {
      case 27:
         exit(0);
         break;
   }
}

int main(int argc, char** argv)
{
   glutInit(&argc, argv);
   glutInitDisplayMode (GLUT_SINGLE | GLUT_RGB);
   glutInitWindowSize (500, 500);
   glutInitWindowPosition (100, 100);
   glutCreateWindow (argv[0]);
   init ();
   glutDisplayFunc(display);
   glutReshapeFunc(reshape);
   glutKeyboardFunc (keyboard);
   glutMainLoop();
   return 0;
}

Cheers,
       Tsiu

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...