void RenderVideoFrame::setState(int v) {
    if (v != state  &&  -2 <= v  &&  v <= 3) {
        state = v;
        switch (state) {
        case -2:
            // uninitialized
            point_x = point_y = -1;
            value = 0;
            capturing = false;
            update();
            break;

        case -1:
            // initialized
            point_x = point_y = -1; // do it again in case of restarting
            value = 0;

            startCapturing(0);
            setState(0);
            break;

        case 0:
            // waiting for user to select the object to track
            break;

        case 1:
            // tracking object and selecting circles
            break;

        case 2:
            // finished everything :)
            stopCapturing();
            countValue();
            initCircles();
            update();
            break;

        case 3:
            // interrupted :(
            stopCapturing();
            initCircles();
            update();
            break;

        }

        emit stateChanged(v);
    }
}
int main(int argc, char **argv) {
	initCircles();		//initialize circle values

	glutInit(&argc, argv);
	glutInitDisplayMode(GLUT_DEPTH | GLUT_SINGLE | GLUT_RGBA | GLUT_ALPHA);

	glutInitWindowPosition(0,0);					//window position
	glutInitWindowSize(WINDOW_SIZE, WINDOW_SIZE);	//window size
	glutCreateWindow ("circles!!!");				//window name
	glClearColor(0.0, 0.0, 0.0, 0.0);				//background color
	glClear(GL_COLOR_BUFFER_BIT);

	//The four following statements set up the viewing rectangle
	glMatrixMode(GL_PROJECTION);					// use proj. matrix
	glLoadIdentity();								// load identity matrix
	gluOrtho2D(-1.0, 1.0, -1.0, 1.0);				// set orthogr. proj.
	glMatrixMode(GL_MODELVIEW);						// back to modelview m.

	glEnable (GL_BLEND);
	glBlendFunc (GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA);

	glutDisplayFunc(display);
	glutTimerFunc(waitTime, timer, 1);
	glutMouseFunc(mouse);
	glutKeyboardFunc(keyboard);
	glutReshapeFunc(reshape);

	glutMainLoop();
  	return 0;
}
void ScanLineHelper::init( ){

	short ax = 0;
	short ay = 0;
	short ex = 0;
	short ey = 0;

	numberOfCircles = 16;

	innerLines = (short *) malloc(nLines/2 * maxPoints * 2 * sizeof(short));
	innerLinesN = (short *) malloc(nLines/2 * sizeof(short));
	outerLines = (short *) malloc(nLines/2 * maxPoints/2 * 2 * sizeof(short));
	outerLinesN = (short *) malloc(nLines/2 * sizeof(short));
	circles = (short *) malloc(1500*numberOfCircles*2*sizeof(short));
	circleOffsets = (short *) malloc((numberOfCircles + 1)*sizeof(short));

	printf("Sizeof short: %d\n", (int)sizeof(short));

	for(int i = 0; i < nLines; i++){

		double angle = i*1.0/nLines *2*M_PI;


		if(i % 2 == 0){
			if(fabs(angle) < 4*M_PI/5 || fabs(angle) > 6*M_PI/5) {
				ax = (short) (cos(angle)*iRadius + mx);
				ay = (short) (sin(angle)*iRadius + my);
			} else {
				double helpRadius = -frontScanlineDistance / cos(angle);
				ax = (short) (cos(angle)*helpRadius + mx);
				ay = (short) (sin(angle)*helpRadius + my);
			}

			ex = (short) (cos(angle)*(double) oRadius + (double) mx);
			ey = (short) (sin(angle)*(double) oRadius + (double) my);

			int offset = (i/2)*maxPoints*2;
			DrawLine(innerLines + offset, innerLinesN + (i/2), ax, ay, ex, ey);

		}
		else{

			ax = (short) (cos(angle)*(iRadius + (oRadius - iRadius)/4) + mx);
			ay = (short) (sin(angle)*(iRadius + (oRadius - iRadius)/4) + my);

			ex = (short) (cos(angle)*oRadius + mx);
			ey = (short) (sin(angle)*oRadius + my);
			
			int offset = (i/2)*maxPoints;
			DrawLine(outerLines + offset, outerLinesN + (i/2), ax, ay, ex, ey);
		}



	}

	initCircles();

}
Exemple #4
0
	void initialise() {
		PI = Pi();
		frameCap = 60;
		inputCap = 60;
		updateCap = 240;

		play = false;
		drawing = false;
		verts = 50;
		speed = 4;
		circleColour = vec4(0.4, 0.3, 0.8, 1);
		mark = Marker(vec4(0.0, 0.6, 0.8, 1));
		glPointSize(10.0f);

		float theta[NUMBER] = {1,2,3,4,0,0};
		float radii[NUMBER] = {300,150,100,50,20,10};
		float rates[NUMBER] = {1,2,3,4*PI,5,6};

		initCircles(vec2(500,500),radii, rates, theta);
	}
RenderVideoFrame::RenderVideoFrame(QWidget *parent) :
    QWidget(parent)
{
    // circles settings
    //computed for 6x5 circles on 640x480 surface
    // 640 = 6*d + 5*s1
    // 480 = 5*d + 4*s2
    //there cannot be more circles, unless one wants to use huge integers
    //(more than 2^64)
    d = 80-1;  //circle diameter; '-1' is for the width of the circle
    s1 = 32; //space between circles on X-axis
    s2 = 20; //space between circles on Y-axis
    c_x = 6;
    c_y = 5;

    initCircles();

    //selected point
    point_diameter = 16;

    timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(queryFrame()) );
    setState(-2);
}