#Rotating a Bézier Curve in OpenGL & Cpp
3 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For more information use !howto ask.
#define _USE_MATH_DEFINES
#include <GL/glut.h>
#include <math.h>
void init(void){
glClearColor(1, 1, 1, 1);
glMatrixMode(GL_PROJECTION);
gluOrtho2D(0, 1000, 0, 1000);
}
void BezierCurves(void){
glClear(GL_COLOR_BUFFER_BIT);
float ControlPoints[4][3] = {{100, 100, 0}, {200, 400, 0}, {300, 400, 0}, {400, 100, 0}};
float dx = ControlPoints[4][1] - ControlPoints[1][1];
float dy = ControlPoints[4][2] - ControlPoints[1][2];
float m;
bool vLine = false;
if(dx != 0){
m = dy/dx;
}else
vLine = true;
glPushMatrix();
glTranslatef(500, 500, 0);
glRotatef(M_PI/2, 0, 1, 0);
glTranslatef(0, 0, 0);
glMap1f(GL_MAP1_VERTEX_3, 0, 1, 3, 4, *ControlPoints);
glEnable(GL_MAP1_VERTEX_3);
glMapGrid1f(100, 0, 1);
glColor3f(0, 0, 1);
glEvalMesh1(GL_LINE, 0, 100);
glDisable(GL_MAP1_VERTEX_3);
glPopMatrix();
glFlush();
}
int main(int argc, char** argv){
glutInitWindowSize(1000, 1000);
glutInit(&argc, argv);
glutCreateWindow("Bézier Curves");
init();
glutDisplayFunc(BezierCurves);
glutMainLoop();
}