예제 #1
0
void callWhenCollide(point curP, point wallP, struct world * jello, int springType, int prop)
{
	
	point hooksF, dampF;		
	
	memset( (void*)&hooksF, 0, sizeof(hooksF));
	memset( (void*)&dampF, 0, sizeof(dampF));

	hooksF = computeHooksForce(curP, wallP, jello, springType, KCOLLISION);
	dampF = computeDampingForce(curP, wallP, jello, DCOLLISION);
	
	if(prop == WALL)
	{
		// Add the forces to the current point in the loop
		force[(int)curP.x][(int)curP.y][(int)curP.z].x += (hooksF.x) + dampF.x + 0.9;
		force[(int)curP.x][(int)curP.y][(int)curP.z].y += (hooksF.y) + dampF.y + 0.9;
		force[(int)curP.x][(int)curP.y][(int)curP.z].z += (hooksF.z) + dampF.z + 0.9;
	}
	else if(prop == SPHERE)
	{
		// Add the forces to the current point in the loop
		force[(int)curP.x][(int)curP.y][(int)curP.z].x += (hooksF.x)/4 + dampF.x/2;
		force[(int)curP.x][(int)curP.y][(int)curP.z].y += (hooksF.y)/4 + dampF.y/2;
		force[(int)curP.x][(int)curP.y][(int)curP.z].z += (hooksF.z)/4 + dampF.z/2;

	}
}
void callWhenCollide(node curP, point collisionP, cloth *clothItem, int springType, int prop)
{
	point hooksF, dampF;		
	int index;
	
	memset( (void*)&hooksF, 0, sizeof(hooksF));
	memset( (void*)&dampF, 0, sizeof(dampF));

	index = FindIndexInArray(curP.y, curP.x, clothItem->width);
	hooksF = computeHooksForce(index, 0,  collisionP, clothItem, springType, KCOLLISION);
	dampF = computeDampingForce(index, 0, collisionP, clothItem, DCOLLISION);
	
	if(prop == WALL)
	{
		// Add the forces to the current point in the loop
		clothItem->force[index].x += (hooksF.x) + dampF.x;
		clothItem->force[index].y += (hooksF.y) + dampF.y;
		clothItem->force[index].z += (hooksF.z) + dampF.z;
	}
	else if(prop == SPHERE)
	{
		// Add the forces to the current point in the loop
		clothItem->force[index].x += (hooksF.x) + dampF.x;
		clothItem->force[index].y += (hooksF.y) + dampF.y;
		clothItem->force[index].z += (hooksF.z) + dampF.z;
	}
}
예제 #3
0
/* Function: PenaltyPushBack
 * Description: Responds to the collision that is detected and performs penalty method
 * Input: index - index of the vertex which collided 
 *		  wallP - point on the wall where the vertex is colliding
 * Output: void
 */
void PenaltyPushBack(int index, point wallP, phyzx *phyzxObj)
{
	GLMnode *node;
	point hooksF, dampF, temp;
	
	memset( (void*)&hooksF, 0, sizeof(hooksF));
	memset( (void*)&dampF, 0, sizeof(dampF));

	hooksF = computeHooksForce(index, wallP, phyzxObj);
	dampF = computeDampingForce(index, wallP, phyzxObj);
	
	// Add the forces to the collided vertex
	phyzxObj->extForce[index].x += hooksF.x + dampF.x;
	phyzxObj->extForce[index].y += hooksF.y + dampF.y;
	phyzxObj->extForce[index].z += hooksF.z + dampF.z;
}
예제 #4
0
// Checks wheather typeP point is inside jello cube
// Checks if the spring connecting curP and typeP is already parsed 
// Computes the hooks and damp force for the spring connecting them
// Updates the force array with the force computed
void updateForce(point curP, point typeP, struct world * jello, int springType)
{
	
	int inOrOut = 0;			// 1 = inside , 0 = outside
	int parsedOrNot = 0;		// 1 = unparsed, 0 = already parsed
	point hooksF, dampF;		// to store the force computed in the above defined functions
	
	memset( (void*)&hooksF, 0, sizeof(hooksF));
	memset( (void*)&dampF, 0, sizeof(dampF));

	inOrOut = checkIfInsideCube(typeP);

	if(inOrOut)		
	{
		// type# point is inside the jello cube
		parsedOrNot = checkIfAlreadyParsed(typeP, curP);

		if(parsedOrNot)
		{
			// type# point has not been parsed yet

			hooksF = computeHooksForce(curP, typeP, jello, springType, KELASTIC);
			dampF = computeDampingForce(curP, typeP, jello, DELASTIC);
			
			// Add the forces to the current point in the loop
			force[(int)curP.x][(int)curP.y][(int)curP.z].x += hooksF.x + dampF.x;
			force[(int)curP.x][(int)curP.y][(int)curP.z].y += hooksF.y + dampF.y;
			force[(int)curP.x][(int)curP.y][(int)curP.z].z += hooksF.z + dampF.z;
			
			// Add the forces to the current type# point
			force[(int)typeP.x][(int)typeP.y][(int)typeP.z].x += -hooksF.x + (-dampF.x);
			force[(int)typeP.x][(int)typeP.y][(int)typeP.z].y += -hooksF.y + (-dampF.y);
			force[(int)typeP.x][(int)typeP.y][(int)typeP.z].z += -hooksF.z + (-dampF.z);
		}
	}
}
void updateForce(node curP, node typeP, cloth *clothItem, int springType)
{
	int inOrOut = 0;			// 1 = inside , 0 = outside
	int parsedOrNot = 0;		// 1 = unparsed, 0 = already parsed
	point hooksF, dampF;		// to store the force computed in the above defined functions
	int indexC, indexT;

	memset( (void*)&hooksF, 0, sizeof(hooksF));
	memset( (void*)&dampF, 0, sizeof(dampF));

	inOrOut = checkIfInsideCloth(typeP, clothItem);

	if(inOrOut)		
	{
		// type# point is inside the jello cube
		parsedOrNot = checkIfAlreadyParsed(typeP, curP);

		if(parsedOrNot)
		{
			indexC = FindIndexInArray(curP.y, curP.x, clothItem->width);
			indexT = FindIndexInArray(typeP.y, typeP.x, clothItem->width);
			// type# point has not been parsed yet

			hooksF = computeHooksForce(indexC, indexT, vMake(0.0), clothItem, springType, KELASTIC);
			dampF = computeDampingForce(indexC, indexT, vMake(0.0), clothItem, DELASTIC);

			// Add the forces to the current point in the loop
			clothItem->force[indexC].x += hooksF.x + dampF.x;
			clothItem->force[indexC].y += hooksF.y + dampF.y;
			clothItem->force[indexC].z += hooksF.z + dampF.z;
			
			// Add the forces to the current type# point
			clothItem->force[indexT].x += -hooksF.x + (-dampF.x);
			clothItem->force[indexT].y += -hooksF.y + (-dampF.y);
			clothItem->force[indexT].z += -hooksF.z + (-dampF.z);

			if(gWind == 1)
			{
				if(windCount < 30 && flag != 1)
				{
					clothItem->force[indexC].x += gWindAmountX;
					clothItem->force[indexC].y += 0.0;
					clothItem->force[indexC].z += gWindAmountZ;
					windCount++;
					if(windCount == 30)
					{
						flag = 1;
					}
				}
				else
				{
					windCount -= 1;
					if(windCount == 0)
					{
						flag = 0;
					}
				}
			}
		}
	}
}