7 Replies - 307 Views - Last Post: 22 October 2013 - 08:18 PM Rate Topic: -----

#1 bcnafegar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 13-May 11

counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 07:11 PM

I'm working on an opengl assignment where I need to tween between a square and a circle. everything works except I need it to go from square to circle, then tween back to square and so on until the user exits. Right now it goes from square to circle then jumps right back to the square and starts over instead of turning from a circle to a square. Anyone have any thoughts? Oh and the 0 and 1000 is an array that contains the time frames I guess you could say. That's why I need to do this.

Is This A Good Question/Topic? 0
  • +

Replies To: counting from 0 to 1000 and then back to 0 continuously

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3590
  • View blog
  • Posts: 11,166
  • Joined: 05-May 12

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 07:43 PM

Show us your current code.

The solutions should be a simple as incrementing and then decrementing a variable.
Was This Post Helpful? 0
  • +
  • -

#3 bcnafegar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 13-May 11

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 07:49 PM

while(true)
		{
		int max2=0;//current
		int last=1000;
		int temp=0;
		bool up=true;
		if(max2 < 1000 && up) 
		{
			max2++;
		}
		if(max2> 0 && !up) 
			{
				max2--;
		}
		if(max2==1000) 
		{
			up=false;
		}
		if(max2==0) 
		{
			up=true;
		}


Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3001
  • View blog
  • Posts: 10,393
  • Joined: 08-August 08

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 07:52 PM

Don't you think you might want to output max2 somewhere in the loop so you can see if it's working?
Was This Post Helpful? 0
  • +
  • -

#5 bcnafegar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 13-May 11

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 07:54 PM

its at the bottom of that i just didn't include it for whatever reason..Its staying at 1 for some reason
Was This Post Helpful? 0
  • +
  • -

#6 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 3001
  • View blog
  • Posts: 10,393
  • Joined: 08-August 08

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 08:01 PM

If you don't start paying attention to details — and start providing them too — this will take a very long time.
Show your code and the results.
Was This Post Helpful? 0
  • +
  • -

#7 bcnafegar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 13-May 11

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 08:04 PM

#include <iostream>
#include <stdlib.h>
#include <GL/glut.h>
#include <math.h>





using namespace std;

int width =640;
int height = 480;
float PI =3.14;
//void drawtween (float A[], float B[], float time)
//{

//}
double sx[8];
double sy[8];
double cx[8];
double cy[8];

double tx[8];
double ty[8];


/*void drawtween()
{
	sx[1] =.5;
	sx[2]= 1;
	sx[3]= 1;
	sx[4]= 1;
	sx[5]= .5;
	sx[6]= 0;
	sx[7]= 0;

	sy[0]=0;
	sy[1]=0;
	sy[2] = 0;
	sy[3]=.5;
	sy[4]=1;
	sy[5]=1;
	sy[6]=1;
	sy[7]=.5;


	
	//int j=0.1;
	glBegin(GL_LINE_LOOP);
	for (int c=0;c<8;c++)
	{
		glVertex2d(sx[c],sy[c]);
		
	}
	glEnd();
	glFlush();
	glutPostRedisplay();
}*/


void getpoints(double time, int increment)
{
	
	sx[0]=0;
	sx[1] =.5;
	sx[2]= 1;
	sx[3]= 1;
	sx[4]= 1;
	sx[5]= .5;
	sx[6]= 0;
	sx[7]= 0;

	sy[0]=0;
	sy[1]=0;
	sy[2] = 0;
	sy[3]=.5;
	sy[4]=1;
	sy[5]=1;
	sy[6]=1;
	sy[7]=.5;

	//int j=0.1;
	//glBegin(GL_LINE_LOOP);
	//for (int c=0;c<8;c++)
	//{
	//	glVertex2d(sx[c],sy[c]);
		
	//}
	//glEnd();
	int b=0;
	//glBegin(GL_LINE_LOOP);
	glClear(GL_COLOR_BUFFER_BIT);
	for(double t = 0; t< 2 * PI; t += PI / 4)
		{
			
			cx[b]=cos(t) * .5;
			cy[b]=sin(t) * .5;
			//cout<<"circle c: "<<cx[b]<<endl;
 		//	glVertex2f(cos(t) * .5, sin(t) * .5);
			b++;
			
			
		}
	//glEnd();
				double k =.125;
				
				for(int h=0;h<8;h++)
				{
				tx[h]=(sx[h]*(1-time))+cx[h]*time;
				ty[h]=(sy[h]*(1-time)) + cy[h]*time;
				
					// time+=time;
				glColor3f(0,0,0);
				glLineWidth(2);
				glBegin(GL_LINE_LOOP);
				if(increment==0)
				{
					glVertex2d(tx[increment],ty[increment]);
				}
			else
					
					glVertex2d(tx[h],ty[h]);
				}
					//glFlush();
				
				glEnd();
				glutSwapBuffers();
			//glutPostRedisplay();
				glFlush();
					

}
void display()
{
//	drawtween();
	glClear(GL_COLOR_BUFFER_BIT);
	glClearColor(1,1,1,0);	
	
	int n =8;
	int i;
	double v=0.125;
	
	
	
	
	double k;
	
				glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
		int q=0;
		
		int incre =0;
		/*double temp=1.0;
		double d =.001; 
		double last =1.0;*/
		//double current =0.0;
	/*	double max =1.0;
		double min =0.0;*/
		double current[1000];
		int max=0;
		for (double d=0.0 ;d<1.0;d+=.001)
		{
			
			current[max]=d;
			max++;
				
				
				
		}
		int max3=0;//current
		int last=1000;
		int temp=0;
		bool up=true;
		while(true)
		{
		
		if(max3 < 1000 && up) 
		{
			max3++;
		}
		if(max3> 0 && !up) 
			{
				max3--;
		}
		if(max3==1000) 
		{
			up=false;
		}
		if(max3==0) 
		{
			up=true;
		}
		cout<<max3<<endl;
			if(incre==8)
				{
					incre=-incre;
				}
				getpoints(current[max3],incre);
		
		
		}
		
		glutSwapBuffers();
				glEnd();
				
				//glEnd();
		
		
				
		
	 
			
	
	//();
		glFlush();
		glutPostRedisplay();
			
	
}





void init()
{

	glClearColor(1,1,1,0);
	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	glutInitDisplayMode(GLUT_DOUBLE);
	
	
	gluOrtho2D(-5,5,-5,5);

}






int main (int argc, char** argv)
{
    


	
	glutInit(&argc,argv);
	glutInitDisplayMode(GLUT_SINGLE| GLUT_RGB);
	glutInitWindowSize(640,480);
	glutInitWindowPosition(400,400);
	glutCreateWindow("Tween"); 
		//glutMouseFunc(mymouse);
	
	
	glutDisplayFunc(display);
	init();
	//glutMouseFunc(MyMouse);

	
    glutMainLoop();
}










its now doing the counting correctly but i must have messed with the swapbuffers() because now there is now picture
Was This Post Helpful? 0
  • +
  • -

#8 bcnafegar  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 31
  • Joined: 13-May 11

Re: counting from 0 to 1000 and then back to 0 continuously

Posted 22 October 2013 - 08:18 PM

I figured it out, thanks for looking though
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1