Exemple #1
0
int pSim::Update()
{
#ifdef VERBOSE
	update_log << "Update no contact" << endl;
#endif
#ifdef TIMING_CHECK
	update_start_time = MPI_Wtime();
#endif
#ifdef PSIM_TEST
	max_condition_number = -1.0;
	max_sigma_ratio = -1.0;
	max_condition_number_joint = 0;
	max_sigma_ratio_joint = 0;
	condition_numbers.resize(n_dof);
	sigma_ratios.resize(n_dof);
	condition_numbers.zero();
	sigma_ratios.zero();
	total_gamma_error = 0.0;
#endif
	/**** assembly ****/
	// position-dependent variables
	update_position();
#if 1
	if(do_connect)
	{
		//
		// do collision computation if needed
		//
		update_collision();
		// don't forget to recompute link velocities
		CalcVelocity();
		do_connect = false;
	}
#endif
	// velocity-dependent variables
	update_velocity();

#ifdef TIMING_CHECK
	cerr << "[" << rank << "] disassembly t = " << MPI_Wtime()-update_start_time << endl;
#endif
	/**** disassembly ****/
	disassembly();
	
#ifdef PSIM_TEST
	cerr << "--- max condition number = " << max_condition_number << " at " << max_condition_number_joint->name << endl;
	cerr << "--- max sigma ratio = " << max_sigma_ratio << " at " << max_sigma_ratio_joint->name << endl;
	cerr << "--- total_gamma_error = " << total_gamma_error << endl;
//	cerr << "condition_numbers = " << tran(condition_numbers) << endl;
//	cerr << "sigma_ratios = " << tran(sigma_ratios) << endl;
#endif
#ifdef USE_MPI
	// scatter results
	scatter_acc();
#endif
	return 0;
}
void GameObject::Update(float deltaTime) {
	this->m_vForward = CalcForwardVector(this->Pitch(), this->Yaw());
	this-> m_vRight = CalcRightVector(this->Pitch(), this->Yaw());
	this->m_vUp = CalcUpVector(this->Pitch(), this->Yaw());

	this->m_vCameraForward = CalcForwardVector(this->CameraPitch(), this->CameraYaw());
	this->m_vCameraRight = CalcRightVector(this->CameraPitch(), this->CameraYaw());
	this->m_vCameraUp = CalcUpVector(this->CameraPitch(), this->CameraYaw());

	CalcVelocity();
}
Exemple #3
0
	Vector2 ObstacleAvoidance::CalcVelocity()
	{
		Vector2 leftRay = mActor->GetVelocity();
		Vector2 rightRay = mActor->GetVelocity();

		// We have a second to avoid obstacle
		float distance = mActor->GetVelocity().Length() * 1.0f;

		VehiclePtr leftObstacle = mActor->RayQuery(leftRay, distance);
		VehiclePtr rightObstacle = mActor->RayQuery(rightRay, distance);

		if (leftObstacle && rightObstacle)
		{
			// We have 2 obstacles and should ovoid both of them
			Vector2 lAvoidance = CalcVelocity(leftObstacle);
			Vector2 rAvoidance = CalcVelocity(rightObstacle);
			float lSDistance = (leftObstacle->GetPosition() - mActor->GetPosition()).LengthSquared();
			float rSDistance = (rightObstacle->GetPosition() - mActor->GetPosition()).LengthSquared();
			float k = lSDistance / rSDistance;
			Vector2 result = k * lAvoidance + (1.0f - k) * rAvoidance;

			return result;
		}
		else if (leftObstacle)
		{
			// We have only left obstacle
			return CalcVelocity(leftObstacle);
		}
		else if (rightObstacle)
		{
			// We have only right obstacle
			return CalcVelocity(rightObstacle);
		}
		else
		{
			// We have no obstacles
			return Vector2(0.0f, 0.0f);
		}
	}
void CLBullet::Moving(float v_max)
{
	CalcVelocity(v_max);
}
Exemple #5
0
void obj_AI_Bubble::Update()
{
	if(volume < 0)
		SetAlive(false);
	
	/*
	-Find out which bubble is closest (an AI bubble or player bubble)
	Find out if it is bigger than the other
	if it is bigger			-> move away
	else if it is smaller	-> move towards it
	*/

	float S;
	float ox;
	float oy;
	GameObject *closestBubble = GameObjectManager::GetInstance().GetClosestBubble(x,y,GetInstanceID(),shotBubbles);
	//It checks for volume/75 so it doesn't fly towards a bubble en when it shoots it is smaller
	if(closestBubble!=NULL)
	{
		if(volume-(volume/75) > closestBubble->GetVolume())
		{
			hasFoundDirection = true;
			//std::cout << "Towards\n";
			ox = closestBubble->GetX();
			oy = closestBubble->GetY();
			S = sqrt( ((ox)-(x))*((ox)-(x)) + ((oy) - (y))*((oy)-(y)) );
			if(y < oy)
				destinationDirection=acos((ox-x)/S) + PI;
			else
				destinationDirection=PI - acos((ox-x)/S) + 2*PI;

		}
		else if(volume <= closestBubble->GetVolume() && closestBubble->GetVolume() > volume/70)
		{
			hasFoundDirection = true;
			//std::cout << "Away\n";
			ox = closestBubble->GetX();
			oy = closestBubble->GetY();
			S = sqrt( (ox-x)*(ox-x) + (oy-y)*(oy-y) );
		
			if(y < oy)
				destinationDirection=acos((ox-x)/S);
			else
				destinationDirection=PI - acos((ox-x)/S) + PI;
		}
	}

	//Shoot a bubble once in 0.5 - 2 seconds
	if(hasFoundDirection && GameObjectManager::GetInstance().IsPlaying())
	{
		if(--shootCount <= 0)
		{
			AudioManager::GetInstance().PlaySoundEffect(rand()%3+1);
			shootCount = rand()%100+60;

			float otherVolume = volume/75;
			float otherRadius = CalcRadius(otherVolume);
			float otherVelX = cos(destinationDirection)*5;
			float otherVelY = sin(destinationDirection)*5;
			float otherEnergyVelX = CalcEnergyKinetic(otherVelX, otherVolume);
			float otherEnergyVelY = CalcEnergyKinetic(otherVelY, otherVolume);
			//Change velocity based on the kinetic energy created by shooting the other bubble away
			if(otherVelX >= 0)
				velX -= CalcVelocity(otherEnergyVelX, volume);
			else
				velX += CalcVelocity(otherEnergyVelX, volume);
			if(otherVelY >0)
				velY -= CalcVelocity(otherEnergyVelY, volume);
			else
				velY += CalcVelocity(otherEnergyVelY, volume);
			//Create the bubble (using some of the info calculated earlier in this if statement)
			obj_Bubble *shotBubble = GameObjectManager::GetInstance().CreateBubble(x + (radius+otherRadius)*cos(destinationDirection),
				y + (radius+otherRadius)*sin(destinationDirection),	otherVelX + velX, otherVelY + velY, otherVolume);
			shotBubbles.push_back(shotBubble->GetInstanceID());
			//Change volume of the player's bubble
			volume -= otherVolume;
		}
	}

	if(--removeBubbleFromShotBubblesCount<=0)
	{
		removeBubbleFromShotBubblesCount=300;
		if(shotBubbles.size()>0)
			shotBubbles.erase(shotBubbles.begin());
	}


	x+=velX;
	y+=velY;

	if(x<radius)
	{
		velX = -(velX);
		x=radius;
	}
	else if(x>_LEVEL_WIDTH - radius)
	{
		velX = -(velX);
		x = _LEVEL_WIDTH - radius;
	}
	if(y<radius)
	{
		velY = -(velY);
		y=radius;
	}
	else if(y>_LEVEL_HEIGHT - radius)
	{
		velY = -(velY);
		y = _LEVEL_HEIGHT - radius;
	}

	if(volume != volumePrevious)
	{
		radius = CalcRadius(volume);
		circumference = CalcCircumference(radius);
		/*float energyVelX = CalcEnergyKinetic(velX, volumePrevious);
		float energyVelY = CalcEnergyKinetic(velY, volumePrevious);
		if(velX >= 0)
			velX = CalcVelocity(energyVelX,volume);
		else
			velX = -CalcVelocity(energyVelX,volume);
		if(velY >= 0)
			velY = CalcVelocity(energyVelY,volume);
		else
			velY = -CalcVelocity(energyVelY,volume);
			*/
	}

	if(GameObjectManager::GetInstance().TimesBiggerThanPlayer(volume)>1)
	{
		r+=3;
		g-=3;
		if(r>50)
			r=50;
		if(g<0)
			g=0;
	}
	else
	{
		g+=3;
		r-=3;
		if(g>50)
			g=50;
		if(r<0)
			r=0;
	}

	volumePrevious = volume;
	hasFoundDirection = false;
}