Ejemplo n.º 1
0
void MyCamera::rotateDn(float an){
	///////////////////////Anton
	glm::vec3 view_vec = viewC - eyePositionE;
	glm::vec3 crossV = glm::cross(view_vec,upVectorU);
	glm::mat4 rotm = glm::rotate(an,crossV);
	////////////////////////////
	glm::vec4 eyen(1.0);
	eyen[0]=eyePositionE[0];
	eyen[1]=eyePositionE[1];
	eyen[2]=eyePositionE[2];
	eyen[3]=1;
	eyen = rotm*eyen;
	glm::vec4 upn(1.0);
	upn[0]=upVectorU[0];
	upn[1]=upVectorU[1];
	upn[2]=upVectorU[2];
	upn[3]=1;
	upn = rotm*upn;
	eyePositionE[0]=eyen[0];
	eyePositionE[1]=eyen[1];
	eyePositionE[2]=eyen[2];
	upVectorU[0]=upn[0];
	upVectorU[1]=upn[1];
	upVectorU[2]=upn[2];

}
Ejemplo n.º 2
0
void MyCamera::rotateY(float an){
	glm::mat4 rotm = glm::rotate(an, glm::vec3(0.0,1.0,0.0));

	glm::vec4 eyen(1.0);
	eyen[0]=eyePositionE[0];
	eyen[1]=eyePositionE[1];
	eyen[2]=eyePositionE[2];
	eyen[3]=1;
	eyen = rotm*eyen;
	glm::vec4 upn(1.0);
	upn[0]=upVectorU[0];
	upn[1]=upVectorU[1];
	upn[2]=upVectorU[2];
	upn[3]=1;
	upn = rotm*upn;
	eyePositionE[0]=eyen[0];
	eyePositionE[1]=eyen[1];
	eyePositionE[2]=eyen[2];
	upVectorU[0]=upn[0];
	upVectorU[1]=upn[1];
	upVectorU[2]=upn[2];

}
Ejemplo n.º 3
0
int main(int argc, char const *argv[])
{
	int n;						// number of lions
	int k;						// number of times each lion is going to eat
	pid_t *pid;
	int status;

	int i,j;					// iterating variables
	int curr_pit;				// stores the current pit from which the lion is going to eat

	int check;					// stores the pit that will be available;

	// read the number of lions form arguments
	if(argc < 3)
	{
		perror("Didn't provide the number of lions");
		exit(0);
	}
	// Read the number of lions
	n = atoi(argv[1]);
	// Read the number of times each lion is going to eat
	k = atoi(argv[2]);


	pid = (pid_t*)malloc(n*sizeof(pid_t));
	// Wait for the start signal from the Ranger

	// Create Semaphores
	sem_mut 	= semget(MUTEX, 1, IPC_CREAT|0666);
	sem_lion 	= semget(LION, N_PITS + 1, IPC_CREAT|0666);
	sem_jackal 	= semget(JACKAL, N_PITS + 1, IPC_CREAT|0666);
	sem_ranger 	= semget(RANGER, N_PITS + 1, IPC_CREAT|0666);
	sem_pit 	= semget(PIT, N_PITS + 1, IPC_CREAT|0666);
	sem_mem		= semget(NEXT_PIT, 1, IPC_CREAT|0666);
	sem_lion_init = semget(INIT_LION, 1, IPC_CREAT|0666);
	semctl(sem_lion_init,0,SETVAL,0);
	down(sem_lion_init,0);
	printf("Lion Started %d %d\n",n,k);

	// fork n lions
	for(i = 0; i < n; i++)
	{
		pid[i] = fork();
		if(pid[i] == 0)
		{
			srand(time(NULL));
			// forked process
			// actual lion code
			id = i;
			// chosen a random pit
			curr_pit = rand()%N_PITS + 1;
			for(j = 0; j < k; j++)
			{

				check = check_availability(curr_pit);
				if(check == -1)
				{
					// no pit available
					curr_pit = (curr_pit - 1 + N_PITS - 1)%N_PITS + 1;
					printf("%s %d in wait queue of meat-pit %d\n",SELF,id,curr_pit);
					// block in the waiting queue
					down(sem_self,0);
					curr_pit = semctl(sem_mem,0,GETVAL,0);
					j--;
					continue;
				}
				//Current consumer will eat from meat-pit number 'check'
				curr_pit = check;

				// Take control
				printf("Before::Number of %s in meat-pit %d = %d\t\t\t%s %d\n",SELF,curr_pit,semctl(sem_self,curr_pit,GETVAL,0),SELF,id);
				up(sem_self,curr_pit);
				printf("After::Number of %s in meat-pit %d = %d\t\t\t%s %d\n",SELF,curr_pit,semctl(sem_self,curr_pit,GETVAL,0),SELF,id);
				printf("%s %d in control of meat-pit %d\n\n\n",SELF,id,curr_pit);
				// Consume
				down(sem_pit,curr_pit);
				printf("\t\t\t\t\t Meat in Pits %d %d %d\n",semctl(sem_pit, 1, GETVAL, 0),semctl(sem_pit, 2, GETVAL, 0),semctl(sem_pit, 3, GETVAL, 0));
				sleep(2);
				// Check if last consumer to leave the pit

				printf("Number of %s in meat-pit %d = %d\t\t\t%s %d\n",SELF,curr_pit,semctl(sem_self,curr_pit,GETVAL,0),SELF,id);
				if(semctl(sem_self,curr_pit,GETVAL,0) > 1)// || semctl(sem_pit,curr_pit,GETVAL,0) == 0)
				{
					// do not send signal and continue
					down(sem_self,curr_pit);
					continue;
				}
				printf("Down karega %s %d\n",SELF,id);
				down(sem_self,curr_pit);

//				down(sem_mut,0);

				printf("%s %d left meat-pit %d\n",SELF,id,curr_pit);
				// send signals
				// set shared memory to current pit
				semctl(sem_mem,0,SETVAL,curr_pit);
				// wake up ranger and rival
				if(semctl(sem_ranger,0,GETVAL,0) == 0)				// wake up ranger only when sleeping
				up(sem_ranger,0);
				if(semctl(sem_rival, 0, GETNCNT, 0) == 0)
					printf("Koi uthane ko nahi hai %s %d\n",SELF,id);			
				printf("\t\t\tNumber of Jackals waiting %d\n",semctl(sem_jackal, 0, GETNCNT, 0));
				printf("\t\t\tNumber of Lions waiting %d\n",semctl(sem_lion, 0, GETNCNT, 0));
				upn(sem_rival,0,semctl(sem_rival, 0, GETNCNT, 0));
				printf("%s %d giving signal to wait queue of all meat-pit\n",SELF,id);
				
				curr_pit = rand()%N_PITS + 1;
				
//				up(sem_mut,0);
			}
			exit(0);
		}
		else if(pid[i] < 0)
		{
			perror("Fork error!!");
			exit(0);
		}
	}
	for(i = 0; i < n; i++)
		waitpid(pid[i],&status,0);
	free(pid);
	return 0;
}