示例#1
0
void RigidBody::ApplyForce(Vector force, Vector pos)
{
	SetForce(GetForce() + force);

	// Torque = r x F
	//SetTorque(force.cross(pos));
	SetTorque((pos - GetPosition()).cross(force));
}
示例#2
0
文件: Ship.cpp 项目: metiscus/space
 void Ship::GetClientUpdateMessage(ClientShipUpdate& message) const
 {
     message.fired = false; //TODO: implement
     strcpy(message.name, GetName().c_str());
     Vector3f vec = GetForce();
     message.force[0] = vec[0];
     message.force[1] = vec[1];
     message.force[2] = vec[2];
     message.torque = GetTorque();
 }
示例#3
0
wxString CppCheckSettings::GetOptions() const
{
	wxString options;
	if (GetStyle()) {
		options << wxT(" --enable=style ");
	}
	if (GetPerformance()) {
		options << wxT(" --enable=performance ");
	}
	if (GetPortability()) {
		options << wxT(" --enable=portability ");
	}
	if (GetUnusedFunctions()) {
		options << wxT(" --enable=unusedFunction ");
	}
	if (GetMissingIncludes()) {
		options << wxT(" --enable=missingInclude ");
	}
	if (GetInformation()) {
		options << wxT(" --enable=information ");
	}
	if (GetPosixStandards()) {
		options << wxT(" --std=posix ");
	}
	if (GetC99Standards()) {
		options << wxT(" --std=c99 ");
	}
	if (GetCpp11Standards()) {
		options << wxT(" --std=c++11 ");
	}
	if (GetForce()) {
		options << wxT("--force ");
	}

	// Now add any ticked suppressedwarnings
	std::map<wxString, wxString>::const_iterator iter = m_SuppressedWarnings1.begin();
	for (; iter != m_SuppressedWarnings1.end(); ++iter) {
		options << wxT(" --suppress=") << (*iter).first;
	}

	options << wxT(" --template gcc ");
	return options;
}
示例#4
0
	void Physics::CalculatePosition(GameObject& obj)
	{
		if (state != PHYSICS_PAUSE)
		{
			auto transformComponent = obj.has(Transform);
			auto bodyComponent = obj.has(Body);
			//accumulate the total force
			auto a = gravity + bodyComponent->GetForce()*bodyComponent->GetInverseMass();
			auto position = transformComponent->GetPosition() + bodyComponent->GetVelocity()*debugDt;
			auto velocity = bodyComponent->GetVelocity() + a*debugDt;
			velocity *= std::pow(damping, debugDt);
			transformComponent->SetPosition(position);
			//Dont set the velocity of the object
			if (state != PHYSICS_FORWARD && state != PHYSICS_REVERSE)
			{
				bodyComponent->SetVelocity(velocity);
			}
		}
		switch (state)
		{
		case PHYSICS_PLAY:
			break;
		case PHYSICS_PAUSE:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		case PHYSICS_FORWARD:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		case PHYSICS_REVERSE:
			debugDt = 0.0f;
			state = PHYSICS_PAUSE;
			break;
		}	
		auto draw = true;
		ImGui::Begin("Physics", &draw, ImVec2(350, 350), 0.5);
		ImGui::Text("Use Space to Toogle play/pause");
		ImGui::Text("Left arrow key for previous frame(when paused)");
		ImGui::Text("Right arrow key for next frame(when paused)");
		ImGui::Text("Use 1 to toogle debug draw");
		ImGui::End();
	}
示例#5
0
UpdateResult Turret::update2(int ms, GlobalState &GS)
{
	bool Firing = false;
	Vector2d ShootingDirection = Vector2d(0,0);
	Grid* G = GS.TheGrid;
	std::list<Cell*> NearbyCells;
	G->get_nearby_cells(NearbyCells, Pos, CellSize * 12);
	for (auto itr = NearbyCells.begin(); itr != NearbyCells.end(); ++itr)
	{
		for (auto itr2 = (*itr)->CreepList.begin(); itr2 != (*itr)->CreepList.end(); ++itr2)
		{
			if(CheckVisibility(Pos, (*itr)->getPos()))
				ShootingDirection += GetForce(Pos, (*itr)->getPos());
		}
	}
	if(ShootingDirection.x != 0 && ShootingDirection.y != 0)
	{
		Firing = true;
		TurnTo(Rot, atan2(ShootingDirection.y, ShootingDirection.x), 8 * (ms / 1000.0));
	}
	FireTimer -= ms;
	if(FireTimer < 0)
	{
		if(Firing)
		{

			FireTimer += FireRate;
			Projectile* new_projectile = ProjectileToFireOnDeath->clone();
			new_projectile->setPos(Pos);
			new_projectile->setRot(Rot);
			Parent->AddChild (new_projectile);
			//Out of ammo
			if(--Ammo == 0)
				return UPDATE_DELETE;
		}
		else
		{
			FireTimer = 0;
		}
	}

	return UPDATE_REDRAW;
}
///compute the suspension force for the given time interval and external displacement
Dbl CARSUSPENSION::Update(Dbl dt, Dbl ext_displacement)
{
	// clamp external displacement
	overtravel = ext_displacement - travel;
	if (overtravel < 0)
		overtravel = 0;
	if (ext_displacement > travel)
		ext_displacement = travel;
	else if (ext_displacement < 0)
		ext_displacement = 0;

	Dbl new_displacement;

	/*const Dbl inv_mass = 1/20.0;
	const Dbl tire_stiffness = 250000;

	Dbl ext_force = tire_stiffness * ext_displacement;

	// predict new displacement
	new_displacement = displacement + velocity * dt + 0.5 * force * inv_mass * dt * dt;

	// clamp new displacement
	if (new_displacement > travel)
		new_displacement = travel;
	else if (new_displacement < 0)
		new_displacement = 0;
	
	// calculate derivatives
	//if (new_displacement < ext_displacement)*/
		new_displacement = ext_displacement;

	velocity = (new_displacement - displacement) / dt;
	
	// clamp velocity (workaround for very high damping values)
	if (velocity > 5) velocity = 5;
	else if (velocity < -5) velocity = -5;

	displacement = new_displacement;
	force = GetForce(displacement, velocity);

	return -force;
}
    void ExplicitSolverStrategy::ForceOperations(ModelPart& r_model_part) {
        KRATOS_TRY
        // 3. Get and Calculate the forces
        CleanEnergies();

        GetForce(); // Basically only calls CalculateRightHandSide( )

        //FastGetForce();

        GetClustersForce();

        if (r_model_part.GetProcessInfo()[COMPUTE_FEM_RESULTS_OPTION]) {
            CalculateConditionsRHSAndAdd();
            CalculateNodalPressuresAndStressesOnWalls();
        }

        // 4. Synchronize (should be just FORCE and TORQUE)
        SynchronizeSolidMesh(r_model_part);
        KRATOS_CATCH("")
    }//ForceOperations;
wxString CppCheckSettings::GetOptions() const
{
    wxString options;
    if(GetStyle()) {
        options << wxT(" --enable=style ");
    }
    if(GetPerformance()) {
        options << wxT(" --enable=performance ");
    }
    if(GetPortability()) {
        options << wxT(" --enable=portability ");
    }
    if(GetUnusedFunctions()) {
        options << wxT(" --enable=unusedFunction ");
    }
    if(GetMissingIncludes()) {
        options << wxT(" --enable=missingInclude ");
    }
    if(GetInformation()) {
        options << wxT(" --enable=information ");
    }
    if(GetPosixStandards()) {
        options << wxT(" --std=posix ");
    }
    if(GetC99Standards()) {
        options << wxT(" --std=c99 ");
    }
    if(GetCpp11Standards()) {
        options << wxT(" --std=c++11 ");
    }
    if(GetForce()) {
        options << wxT("--force ");
    }
    if(GetJobs() > 1) {
        options << wxT("-j") << GetJobs() << " ";
    }
    if(GetCheckConfig()) {
        options << wxT("--check-config "); // Though this turns off other checks, afaict it does not harm to emit them
    }

    // Now add any ticked suppressedwarnings
    std::map<wxString, wxString>::const_iterator iter = m_SuppressedWarnings1.begin();
    for(; iter != m_SuppressedWarnings1.end(); ++iter) {
        options << wxT(" --suppress=") << (*iter).first << " ";
    }

    // IncludeDirs
    for(size_t n = 0; n < m_IncludeDirs.GetCount(); ++n) {
        wxString item = m_IncludeDirs.Item(n);
        item.Trim().Trim(false);
        if(!item.empty()) {
            options << " -I" << item << " ";
        }
    }
    if(m_SuppressSystemIncludes) {
        options << wxT(" --suppress=") << "missingIncludeSystem ";
    }

    // (Un)Definitions
    for(size_t n = 0; n < m_definitions.GetCount(); ++n) {
        wxString item = m_definitions.Item(n);
        item.Trim().Trim(false);
        if(!item.empty()) {
            options << " -D" << item << " ";
        }
    }
    for(size_t n = 0; n < m_undefines.GetCount(); ++n) {
        wxString item = m_undefines.Item(n);
        item.Trim().Trim(false);
        if(!item.empty()) {
            options << " -U" << item << " ";
        }
    }

    options << wxT(" --template gcc ");
    return options;
}
示例#9
0
文件: curtains.cpp 项目: JunC74/PYX
	void Curtains::Update(float dt)
	{
		vec3 Li;
		for (int i =0;i<height;i++)
		{
			for(int j = 0;j<width;j++)
			{
				ff[i][j] = particle[i][j];
			}
		}
		for (int i =0;i<height;i++)
		{
			for(int j = 0;j<width;j++)
			{
				if(particle[i][j].fixed)
				{
					continue;
				}
				memset(&Li, 0, sizeof(vec3));
				if (i > 0)
				{
					GetForce(&ff[i][j], &ff[i - 1][j], &Li);
				}
				if (i < height - 1)
				{
					GetForce(&ff[i][j], &ff[i + 1][j], &Li);
				}
				particle[i][j].velocity.x += Li.x;

				if(!particle[i][j].fixedY)
					particle[i][j].velocity.y += Li.y;

				particle[i][j].velocity.z += Li.z;
				// 计算左右相邻点的作用力
				memset(&Li, 0, sizeof(vec3));
				if (j > 0)
				{
					GetForce(&ff[i][j], &ff[i][j - 1], &Li);
				}
				if (j < width - 1)
				{
					GetForce(&ff[i][j], &ff[i][j + 1], &Li);
				}

				// 默认质量为1,外力的加速度数值上等于外力
				// 速度改变
				particle[i][j].velocity.x += Li.x + gravity[0];
				if(!particle[i][j].fixedY)
					particle[i][j].velocity.y += Li.y + gravity[1];
				particle[i][j].velocity.z += Li.z + gravity[2];

				// 坐标改变
				particle[i][j].position.x += particle[i][j].velocity.x;
				if(!particle[i][j].fixedY)
					particle[i][j].position.y+= particle[i][j].velocity.y;
				particle[i][j].position.z += particle[i][j].velocity.z;
			}
		}


		index = 0;
		for(int i = 0;i<height-1;i++)
			for(int j = 0;j<width-1;j++)
			{
				addC(particle[i][j].position,particle[i+1][j].position,particle[i+1][j+1].position,particle[i][j+1].position);
			}

			geomety_model_->SetVertexData(vectex_array,Num*sizeof(VertexFormat_XYZ_NORMAL_TEX),Num);
			geomety_model_->SetVertexFomat(FVF_XYZ_NORMAL_TEX);
			//Log::GetInstance()->Debug("aaaaaaaa");
	}
示例#10
0
文件: curtains.cpp 项目: JunC74/PYX
void curtains::UpdateParticle()
{
	
	vec3 Li;
	for (int i =0;i<height;i++)
	{
		for(int j = 0;j<width;j++)
		{
			ff[i][j] = particle[i][j];
		}
	}
	for (int i =0;i<height;i++)
	{
		for(int j = 0;j<width;j++)
		{
			if(particle[i][j].fixed)
			{
				continue;
			}
			memset(&Li, 0, sizeof(vec3));
			if (i > 0)
			{
				GetForce(&ff[i][j], &ff[i - 1][j], &Li);
			}
			if (i < height - 1)
			{
				GetForce(&ff[i][j], &ff[i + 1][j], &Li);
			}
			particle[i][j].velocity.x += Li.x;

			if(!particle[i][j].fixedY)
				particle[i][j].velocity.y += Li.y;
			
			particle[i][j].velocity.z += Li.z;
			// 计算左右相邻点的作用力
			memset(&Li, 0, sizeof(vec3));
			if (j > 0)
			{
				GetForce(&ff[i][j], &ff[i][j - 1], &Li);
			}
			if (j < width - 1)
			{
				GetForce(&ff[i][j], &ff[i][j + 1], &Li);
			}

			// 默认质量为1,外力的加速度数值上等于外力
			// 速度改变
			particle[i][j].velocity.x += Li.x + gravity[0];
			if(!particle[i][j].fixedY)
				particle[i][j].velocity.y += Li.y + gravity[1];
			particle[i][j].velocity.z += Li.z + gravity[2];

			// 坐标改变
			particle[i][j].position.x += particle[i][j].velocity.x;
			if(!particle[i][j].fixedY)
				particle[i][j].position.y+= particle[i][j].velocity.y;
			particle[i][j].position.z += particle[i][j].velocity.z;
		}
	}


	index = 0;
	for(int i = 0;i<height-1;i++)
		for(int j = 0;j<width-1;j++)
		{
			addC(particle[i][j].position,particle[i+1][j].position,particle[i+1][j+1].position,particle[i][j+1].position);
		}
	// glutPostRedisplay(); 重绘窗口
	Sleep(10);

}