love247
July 27th, 2007, 01:55 PM
hi everybody,
first of all im working on c++ openGL..
i am thinking of drawing a closed flower of 3 ellipses, then rotate the ellipses , and then scale the elipses (to show that it is blooming)
here is a picture of what i have in mind, of course it will be in 2D
http://i92.photobucket.com/albums/l37/love247_jo/flower3.jpg
i've done the part of drawing the first flower, and i can draw the other 2 flowers....
but now how can i animate it?? i tried with idle function and with double buffer, but it is not moving right... here is the code with just the first flower:
..
.
.
.
.
.
.
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
const GLfloat DEG2RAD = 3.14159/180;
void drawEllipse(void)
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(1.0 ,0.0 ,0.5);
glBegin(GL_POLYGON); //to draw the ellipse in a filled color
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void drawBorder(void) //to draw the ellipse with just its border
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(0.0 ,0.0 ,0.0);
glBegin(GL_LINE_LOOP);
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0 , 1.0 ,0.6);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex2f(5.0,6.0);
glVertex2f(5.0,17.0);
glEnd();
//center petal
glPushMatrix() ;
glTranslatef(5,5,0) ;
glRotatef(90,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//right petal
glPushMatrix() ;
glTranslatef(3.7, 6.6,0);
glRotatef(20,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//left petal
glPushMatrix() ;
glTranslatef(6.4, 6.6,0) ;
glRotatef(160,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("ellipse");
myInit();
glutDisplayFunc(display);
gluOrtho2D (17.0, 0.0, 17.0, 0.0);
glutMainLoop();
}
.
.
.
.
.
.
.
and here is the code with the animation thing(that did not work properly):
.
.
.
.
.
[source lang="cpp"]
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
GLfloat xradius = 3.5,
angle_mod = 45 ;
GLfloat yradius=2;
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
const GLfloat DEG2RAD = 3.14159/180;
void drawEllipse(void)
{
GLint i;
//GLfloat xradius=3.5;
//GLfloat yradius=2;
glColor3f(1.0 ,0.0 ,0.5);
glBegin(GL_POLYGON);
for (i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void drawBorder(void)
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(0.0 ,0.0 ,0.0);
glBegin(GL_LINE_LOOP);
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0 , 1.0 ,0.6);
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex2f(5.0,6.0);
glVertex2f(5.0,17.0);
glEnd();
//center petal
glPushMatrix() ;
glTranslatef(5,5,0) ;
glRotatef(90,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//right petal
glPushMatrix() ;
glTranslatef(3.7+angle_mod/100,5.6,0);
glRotatef(20+angle_mod,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//left petal
glPushMatrix() ;
glTranslatef(6.4-angle_mod/100,5.6,0) ;
glRotatef(160-angle_mod,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
glFlush();
glutPostRedisplay();
}
void idle(void)
{
xradius += 0.00001 ;
if( xradius >= 4 )
{ xradius = 4 ; }
yradius += 0.00001 ;
if( yradius >= 2 )
{ yradius = 2 ; }
angle_mod -= 0.001 ;
if( angle_mod <= 0 )
{ angle_mod = 0 ; }
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutCreateWindow("ellipse");
myInit();
glutDisplayFunc(display);//CHANGED
gluOrtho2D (17.0, 0.0, 17.0, 0.0);
glutIdleFunc(idle);
glutMainLoop();
}
.
.
.
.
.
can anybody help me of how i can animate it????
it is not neccessory to be fully animated....
it is enough that the first flower appears, then dissapears, and the second appears and dissapears, and the third appears....can anybody help plz?
finally i must say, without the help of some people, i would have never knew how to do these stuff... so my hopes are high that u can help too, and i will really apreciate it:)
first of all im working on c++ openGL..
i am thinking of drawing a closed flower of 3 ellipses, then rotate the ellipses , and then scale the elipses (to show that it is blooming)
here is a picture of what i have in mind, of course it will be in 2D
http://i92.photobucket.com/albums/l37/love247_jo/flower3.jpg
i've done the part of drawing the first flower, and i can draw the other 2 flowers....
but now how can i animate it?? i tried with idle function and with double buffer, but it is not moving right... here is the code with just the first flower:
..
.
.
.
.
.
.
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
const GLfloat DEG2RAD = 3.14159/180;
void drawEllipse(void)
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(1.0 ,0.0 ,0.5);
glBegin(GL_POLYGON); //to draw the ellipse in a filled color
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void drawBorder(void) //to draw the ellipse with just its border
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(0.0 ,0.0 ,0.0);
glBegin(GL_LINE_LOOP);
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0 , 1.0 ,0.6);
glLineWidth(5.0);
glBegin(GL_LINES);
glVertex2f(5.0,6.0);
glVertex2f(5.0,17.0);
glEnd();
//center petal
glPushMatrix() ;
glTranslatef(5,5,0) ;
glRotatef(90,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//right petal
glPushMatrix() ;
glTranslatef(3.7, 6.6,0);
glRotatef(20,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//left petal
glPushMatrix() ;
glTranslatef(6.4, 6.6,0) ;
glRotatef(160,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
glFlush();
}
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE | GLUT_RGB);
glutCreateWindow("ellipse");
myInit();
glutDisplayFunc(display);
gluOrtho2D (17.0, 0.0, 17.0, 0.0);
glutMainLoop();
}
.
.
.
.
.
.
.
and here is the code with the animation thing(that did not work properly):
.
.
.
.
.
[source lang="cpp"]
#include <GL/glut.h>
#include <GL/gl.h>
#include <windows.h>
#include <math.h>
GLfloat xradius = 3.5,
angle_mod = 45 ;
GLfloat yradius=2;
void myInit(void)
{
glClearColor(1.0, 1.0, 1.0, 0.0);
}
const GLfloat DEG2RAD = 3.14159/180;
void drawEllipse(void)
{
GLint i;
//GLfloat xradius=3.5;
//GLfloat yradius=2;
glColor3f(1.0 ,0.0 ,0.5);
glBegin(GL_POLYGON);
for (i=0; i < 360; i++)
{
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void drawBorder(void)
{
GLint i;
GLfloat xradius=3.5;
GLfloat yradius=2;
glColor3f(0.0 ,0.0 ,0.0);
glBegin(GL_LINE_LOOP);
for (i=0; i < 360; i++)
{
//convert degrees into radians
float degInRad = i*DEG2RAD;
glVertex2f ( cos (degInRad) *xradius, sin (degInRad) *yradius);
}
glEnd();
}
void display(void)
{
glClear(GL_COLOR_BUFFER_BIT);
glColor3f(0.0 , 1.0 ,0.6);
glLineWidth(3.0);
glBegin(GL_LINES);
glVertex2f(5.0,6.0);
glVertex2f(5.0,17.0);
glEnd();
//center petal
glPushMatrix() ;
glTranslatef(5,5,0) ;
glRotatef(90,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//right petal
glPushMatrix() ;
glTranslatef(3.7+angle_mod/100,5.6,0);
glRotatef(20+angle_mod,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
//left petal
glPushMatrix() ;
glTranslatef(6.4-angle_mod/100,5.6,0) ;
glRotatef(160-angle_mod,0,0,1) ;
drawEllipse() ;
drawBorder();
glPopMatrix() ;
glFlush();
glutPostRedisplay();
}
void idle(void)
{
xradius += 0.00001 ;
if( xradius >= 4 )
{ xradius = 4 ; }
yradius += 0.00001 ;
if( yradius >= 2 )
{ yradius = 2 ; }
angle_mod -= 0.001 ;
if( angle_mod <= 0 )
{ angle_mod = 0 ; }
glutPostRedisplay();
}
int main(int argc,char** argv)
{
glutInit(&argc, argv);
glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
glutCreateWindow("ellipse");
myInit();
glutDisplayFunc(display);//CHANGED
gluOrtho2D (17.0, 0.0, 17.0, 0.0);
glutIdleFunc(idle);
glutMainLoop();
}
.
.
.
.
.
can anybody help me of how i can animate it????
it is not neccessory to be fully animated....
it is enough that the first flower appears, then dissapears, and the second appears and dissapears, and the third appears....can anybody help plz?
finally i must say, without the help of some people, i would have never knew how to do these stuff... so my hopes are high that u can help too, and i will really apreciate it:)