void drawTargets() {
	background(51);
	noStroke();
	drawTarget(width*0.25, height*0.4, 200, 4);
	drawTarget(width*0.5, height*0.5, 300, 10);
	drawTarget(width*0.75, height*0.3, 120, 6);
}
Exemple #2
0
void Character::draw() {
  if (move.position.y > move.target.y) {
    drawTarget();
    drawCharacter();
  } else {
    drawCharacter();
    drawTarget();
  }

}
Exemple #3
0
void renderScene(){
        
    // Clear framebuffer & depth buffer
	glClearColor(0.5,0.8,0.7,0.0);
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	//Enable lighting
 	glEnable(GL_LIGHTING);

	//Set the material properties
	glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, grey_ambient);
	glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, grey_diffuse);
	glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, grey_specular);
	glMaterialf(GL_FRONT_AND_BACK, GL_SHININESS, grey_shininess);   

	// Reset Modelview matrix      	
    glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();
	
	// Set view position & direction (Camera at (-5,0,0) looking on the positive X-axis). World is Y-up.
	gluLookAt(-5,0,0, 1,0,0, 0,1,0);

	//To setup the creation of quadric objects
	GLUquadric* nQ;
	nQ=gluNewQuadric();

    glPushMatrix(); //remember the current state of the modelview matrix

	// Rotate from the angle between the first bone and the Z axis
	glRotatef(BoneA_Angle,1,0,0);

	//Draw the first cone at the origin
	gluCylinder(nQ, 0.1, 0.01, BoneA_Length, 30, 5) ;
	gluSphere(nQ, 0.1, 30, 5);
	
	// Translate by the bone length
	glTranslatef(0,0.0,BoneA_Length);

	glPushMatrix(); //remember the current state of the modelview matrix

	// Rotate from the angle between the first and second bones
	glRotatef(BoneB_Angle,1,0,0);

	//Draw the second cone at the origin, pointing up
	gluCylinder(nQ, 0.1, 0.01, BoneB_Length, 30, 5) ;
	gluSphere(nQ, 0.1, 30, 5);

	glPopMatrix(); //restore the state of the modelview matrix

	glPopMatrix(); //restore the state of the modelview matrix

	drawTarget();

	glDisable(GL_LIGHTING);
	
    // Swap double buffer for flicker-free animation
    glutSwapBuffers();
        
}
Exemple #4
0
//thread
void *inputHandler(void *vargp) {
    initTermios();
    char cc;
    pthread_t tid2;
    pthread_create(&tid2, NULL, drawGun, NULL);
    drawTarget(getTargetPosX(TP),getTargetPosY(TP),50,220,10);
    while(stop == 0) {
    	drawTarget(getTargetPosX(TP),getTargetPosY(TP),50,220,10);
    	usleep(1000);
    	
    	if (kbhit()) {
			cc = getch();resetTermios();
			switch (cc) {
				case 'w': case 'W' :
					clearTarget(getTargetPosX(TP),getTargetPosY(TP));
    				moveTarget(&TP,0,-15);
					break;
				case 'a': case 'A' :
					clearTarget(getTargetPosX(TP),getTargetPosY(TP));
    				moveTarget(&TP,-15,0);
					break;
				case 's': case 'S' :
					clearTarget(getTargetPosX(TP),getTargetPosY(TP));
    				moveTarget(&TP,0,15);
					break;
				case 'd': case 'D' :
					clearTarget(getTargetPosX(TP),getTargetPosY(TP));
    				moveTarget(&TP,15,0);
					break;
				case 'q' : case 'Q' :
					stop = 1;
					break;
				case 'i' : case 'I' :
					if(! isActive(B)) {
    					makeBomb(getTargetPosX(TP),getTargetPosY(TP),&B);
    					setActive(&B,1);
    				}
			}
			initTermios();
		}
    }
    pthread_join(tid2, NULL); 
}
float SpecificWorker::go ( const TargetPose &target )
{
    qDebug() <<"GO";
//primeraVez=true;
    ctarget.target = QVec::vec3 ( target.x, target.y, target.z );
	qDebug()<<ctarget.target;
    ctarget.active = true;
    state = State::WORKING;
    drawTarget ( ctarget.target );
    return ( inner->transform ( "world","robot" ) - ctarget.target ).norm2();
}
void Thermal::draw(){
    if(thermalEngine->hasImages()){
        
        thermalEngine->prev(19).draw(84, 200, 910,  450);
        thermalEngine->prev(9).draw(84, 784, 910,  450);
        thermalEngine->lastImage().draw(84, 1366, 910,  450);
    }
    
    drawElapsedTime();
    drawTexts();
    drawThermalData();
    drawTemperature();
    drawTarget();
    
    assets->wireframe_thermal.draw(0, 0);
    
};
float SpecificWorker::goReferenced(const TargetPose &target_, const float xRef, const float zRef, const float threshold)
{
	/////////////////////
	//CHECK PARAMETERS
	/////////////////////
	if (isnan(target_.x) or std::isnan(target_.y) or std::isnan(target_.z) or std::isnan(target_.ry))
	{
		qDebug() << __FUNCTION__ << "Returning. Input parameter -target- is not valid:" << target_.x << target_.y
		         << target_.z << target_.ry;
		RoboCompTrajectoryRobot2D::RoboCompException ex;
		ex.text = "Doing nothing. Invalid Target with nan in it";
		throw ex;
	}

	QVec currentT = currentTarget.getTranslation();
	QVec currentRot = currentTarget.getRotation();
	QVec robotT = innerModel->transform("world", "robot");
	QVec robotRot = innerModel->transform6D("world", "robot").subVector(3, 5);
	QVec targetT = QVec::vec3(target_.x, target_.y, target_.z);
	QVec targetRot = QVec::vec3(target_.rx, target_.ry, target_.rz);
	drawTarget(targetT);
	
	qDebug() << __FUNCTION__
	         << "----------------------------------------------------------------------------------------------";
	qDebug() << __FUNCTION__ << ": Target received" << targetT << targetRot << "with ROBOT at" << robotT << robotRot;
	qDebug() << __FUNCTION__ << "Translation error: " << (targetT - robotT).norm2() << "mm. Rotation error:"
	         << targetRot.y() - robotRot.y() << "rads";

	///////////////////////////////////////////////
	//Maximun admitted rate of requests  (one each 250 ms)
	///////////////////////////////////////////////
	if (relojForInputRateControl.elapsed() < 250)
	{
		RoboCompTrajectoryRobot2D::RoboCompException ex;
		ex.text = "Fail. Call too close in time. Please wait and call again";
		throw ex;
	}
	else
		relojForInputRateControl.restart();

	///////////////////////////////////////////////
	// Minimun change admitted 60mm and 0.05rads
	///////////////////////////////////////////////
	const int MINCHANGE = 7;
	const float MINROTATION = 0.03;
	if ((targetT - robotT).norm2() < MINCHANGE and fabs(targetRot.y() - robotRot.y()) < MINROTATION)
	{

		QString s = "Fail. Target too close to current pose. TDist=" + QString::number((targetT - robotT).norm2()) +
		            "mm. Min = 60mm. RDist="
		            + QString::number(targetRot.y() - robotRot.y()) + "rads. Min = 0.05rads";
		qDebug() << __FUNCTION__ << s;
		RoboCompTrajectoryRobot2D::RoboCompException ex;
		ex.text = s.toStdString();
		tState.setDescription("Target too close");
		throw ex;
	}

	///////////////////////////////////////////////
	// Check if robot is inside limits and not in collision.
	///////////////////////////////////////////////
	auto r = sampler.checkRobotValidStateAtTarget(robotT, robotRot);
	if (std::get<bool>(r) == false)
	{
		RoboCompTrajectoryRobot2D::RoboCompException ex;
		ex.text = "Execption: Robot is outside limits or colliding. Ignoring request. " + std::get<QString>(r).toStdString();
		qDebug() << __FUNCTION__ << QString::fromStdString(ex.text);
		tState.setDescription(ex.text);
		currentTarget.setState(CurrentTarget::State::ROBOT_COLLISION);
		throw ex;
	}

	///////////////////////////////////////////////
	// Check if target is a a valid point, inside limits and not in collision.
	///////////////////////////////////////////////
	r = sampler.checkRobotValidStateAtTarget(targetT, targetRot);
	if (std::get<bool>(r) == false)
	{
		RoboCompTrajectoryRobot2D::RoboCompException ex;
		ex.text = "Exception: Target outside limits or colliding. Ignoring request. " + std::get<QString>(r).toStdString();
		qDebug() << __FUNCTION__ << QString::fromStdString(ex.text);
		tState.setDescription(ex.text);
		currentTarget.setState(CurrentTarget::State::TARGET_COLLISION);
		throw ex;
	}

	///////////////////////////////////////////////
	// Let's see what these guys want
	///////////////////////////////////////////////

	// move virtualrobot to xref, zRef to act as a surrogate
	//innerModel->updateTransformValues("virtualRobot", xRef, 0, zRef, 0, 0, 0, "robot");
	//InnerModelDraw::addPlane_ignoreExisting(innerViewer, "virtualRobot", "robot", QVec::vec3(xRef,0,zRef), QVec::vec3(0,0,0), "#555555", QVec::vec3(50,1000,50));
	
	road.setThreshold(threshold);

	currentTarget.reset(targetT, targetRot, target_.doRotation);
	currentTarget.setState(CurrentTarget::State::GOTO);
	tState.setState("EXECUTING");	
	
	taskReloj.restart();
	return (robotT - targetT).norm2();
}
task main()
{
	//Declare variables
	int targetImage[8][8] = {{1, 1, 1, 0, 0, 1, 1, 1},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{1, 0, 0, 0, 0, 0, 0, 1},
	{1, 1, 1, 0, 0, 1, 1, 1}};
	
	int hitImage[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 1, 1, 1, 1, 0, 0},
	{0, 1, 1, 1, 1, 1, 1, 0},
	{0, 1, 1, 1, 1, 1, 1, 0},
	{0, 1, 1, 1, 1, 1, 1, 0},
	{0, 1, 1, 1, 1, 1, 1, 0},
	{0, 0, 1, 1, 1, 1, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0}};
	
	int splashImage[8][8] = {{0, 0, 0, 0, 0, 0, 0, 0},
	{0, 0, 1, 1, 1, 1, 0, 0},
	{0, 1, 0, 0, 0, 0, 1, 0},
	{0, 1, 0, 0, 0, 0, 1, 0},
	{0, 1, 0, 0, 0, 0, 1, 0},
	{0, 1, 0, 0, 0, 0, 1, 0},
	{0, 0, 1, 1, 1, 1, 0, 0},
	{0, 0, 0, 0, 0, 0, 0, 0}};
	
	int mainGrid[8][8] = 
	{{0, 1, 1, 1, 1, 1, 0, 0}, //[0][0-8]
	{0, 0, 0, 0, 0, 0, 0, 0}, //[1][0-7]
	{0, 1, 0, 0, 0, 0, 0, 0}, //[2][0-7]
	{0, 1, 0, 0, 0, 1, 1, 1}, //[3][0-7]
	{1, 0, 0, 0, 0, 0, 0, 0}, //[4][0-7]
	{1, 0, 0, 0, 0, 0, 0, 0}, //[5][0-7]
	{1, 0, 1, 1, 1, 0, 0, 0}, //[6][0-7]
	{1, 0, 0, 0, 0, 0, 0, 0}}; //[7][0-7]
	
	int colourValue;
	
	int x=10;
	int y=10;
	
	int xMove=0;
	int yMove=0;
	
	int xShip=0;
	int yShip=7-yMove;
	
	int hits=0;
	
	//Setup colour sensor
	SensorType[S3] = sensorEV3_Color;//set TYPE
	SensorMode[S3] = modeEV3Color_Color;//set MODE
	
	while(hits<17)
/*
	*************************************************************
	Red - 5 - SHOOT
	Blue - 2 - LEFT
	Yellow - 4 - RIGHT
	Green - 3 - DOWN
	*************************************************************
	*/		
	{
		//Erase target image
		clearTarget(targetImage,x,y);
		sleep(500);
		
		//Check colour
		colourValue=getColorName(S3);
		sleep(50);
		
		if (colourValue==2)
		{
			if(xMove>0)
			{
				xMove--;
			}
			else if(xMove==0)
			{
				xMove=7;
			}
		}
		if (colourValue==4)
		{
			if(xMove<7)
			{
				xMove++;
			}
			else if(xMove==7)
			{
				xMove=0;
			}
		}
		if (colourValue==3)
		{
			if(yMove>0)
			{
				yMove--;
			}
			else if(yMove==0)
			{
				yMove=7;
			}
		}
		x=xMove*8+10;
		y=yMove*8+10;
		if (colourValue==5)
		{
			//Calculate Main Grid Location
			xShip=xMove;
			yShip=7-yMove;
			
			//Play torpedo drop sound
			torpedoSound();


			if (mainGrid[yShip][xShip]==1)
			{
				//Play hit sound
				kabloom();

				//Draw hit image
				kabloomDraw(hitImage,x,y);
				
				//Increment hits
				hits++;
				
				//Remove ship
				mainGrid[yShip][xShip]=0;
			}
			else {
				//Play splash sound
				sploosh();
				
				//Draw splash image
				splooshDraw(splashImage,x,y);
				
			}
		}	
		//Draw target image
		drawTarget(targetImage,x,y);
		//Sleep for a small amount of time
		sleep(500);
	}
	displayBigTextLine(2, "Winner!");
	sleep(5000);
}
Exemple #9
0
int main(void) {

    GLFWwindow *window;

    // application time 
    static GLfloat last = 0;
    static GLfloat lastDelay = 0;
    GLfloat timer = glfwGetTime();
    GLfloat start;
    start = timer;
    last = timer;
    lastDelay = timer;

    int i;
    int movedCircle;

    GLfloat total = TOTAL_TIME * 60;

    char text[] = "output.txt";
    out = fopen(text, "w");

    Node * currentNode;

    // initialize all circles in the array
    initArrayOfQueue(stimuli);
    initCircleArray(targetCircles, TARGET_Y);

    glfwSetErrorCallback(error);

    if (!glfwInit() || out == NULL) {
        return -1;
    }

    window = glfwCreateWindow(SCREEN_WIDTH, SCREEN_HEIGHT, "Ax", NULL, NULL);

    if (!window) {
        glfwTerminate();
        return -1;
    }

    glfwMakeContextCurrent(window);
 
    glViewport(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT);
    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();
    glOrtho(0, SCREEN_WIDTH, 0, SCREEN_HEIGHT, 0, 1);
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    glfwSetKeyCallback(window, key_callback);

    // set background color to white
    glClearColor(0.9f, 0.9f, 0.9f, 0.0f);

    // enable blend mode to have transparent effects  
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

    movedCircle = 0;
    
    // Loop until the user closes the window or program terminates
    while (timer - start < total
            && !glfwWindowShouldClose(window)) {
        glClear(GL_COLOR_BUFFER_BIT);

        timer = glfwGetTime();

        // set the correct order of appearance 
        for (i = 0; i < BARS; i++) {
            drawTarget(targetCircles[i]);
            drawQueue(stimuli[i]);
        }
        // whether we should move the circle         
        if (timer - lastDelay > DELAY_TIME) {
            lastDelay = timer;
            movedCircle = movedCircle % BARS;
            push_back(stimuli[movedCircle], movedCircle);
            movedCircle++;
        }

        if (timer - last > SLEEP_TIME) {
            last = timer;
            for (i = 0; i < BARS; i++) {
                moveDownward(stimuli[i]);
            }
        }

        glfwSwapBuffers(window);
        glfwPollEvents();
    }

    fclose(out);
    glfwDestroyWindow(window);
    glfwTerminate();

    return 0;
}