Example #1
0
void Physics2DDirectBodyState::integrate_forces() {

	real_t step = get_step();
	Vector2 lv = get_linear_velocity();
	lv+=get_total_gravity() * step;

	real_t av = get_angular_velocity();

	float damp = 1.0 - step * get_total_linear_damp();

	if (damp<0) // reached zero in the given time
		damp=0;

	lv*=damp;

	damp = 1.0 - step * get_total_angular_damp();

	if (damp<0) // reached zero in the given time
		damp=0;

	av*=damp;

	set_linear_velocity(lv);
	set_angular_velocity(av);


}
Example #2
0
void GameObject::Update() {
    input_->Update(this);
    physics_->Update(this);
    graphics_->Update(this);

    set_linear_velocity();
    set_angular_velocity();
}
Example #3
0
void GameObject::Reset() {
    Clamp clamp = { { 0.f, 0.f }, { 0.f, 0.f } };

    set_position();
    set_rotation();
    set_size();
    set_linear_velocity();
    set_angular_velocity();
    set_clamp(clamp);
    set_movement_velocity();
    set_rotation_velocity();
}
Example #4
0
void RigidBody::set_axis_velocity(const Vector3& p_axis) {

	Vector3 v = state? state->get_linear_velocity() : linear_velocity;
	Vector3 axis = p_axis.normalized();
	v-=axis*axis.dot(v);
	v+=p_axis;
	if (state) {
		set_linear_velocity(v);
	} else {
		PhysicsServer::get_singleton()->body_set_axis_velocity(get_rid(),p_axis);
		linear_velocity=v;
	}
}
Example #5
0
void RigidBodyBullet::set_state(PhysicsServer::BodyState p_state, const Variant &p_variant) {

	switch (p_state) {
		case PhysicsServer::BODY_STATE_TRANSFORM:
			set_transform(p_variant);
			break;
		case PhysicsServer::BODY_STATE_LINEAR_VELOCITY:
			set_linear_velocity(p_variant);
			break;
		case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY:
			set_angular_velocity(p_variant);
			break;
		case PhysicsServer::BODY_STATE_SLEEPING:
			set_activation_state(!bool(p_variant));
			break;
		case PhysicsServer::BODY_STATE_CAN_SLEEP:
			can_sleep = bool(p_variant);
			if (!can_sleep) {
				// Can't sleep
				btBody->forceActivationState(DISABLE_DEACTIVATION);
			}
			break;
	}
}
Example #6
0
void PhysicsDirectBodyState::integrate_forces() {

	real_t step = get_step();
	Vector3 lv = get_linear_velocity();
	lv += get_total_gravity() * step;

	Vector3 av = get_angular_velocity();

	float linear_damp = 1.0 - step * get_total_linear_damp();

	if (linear_damp < 0) // reached zero in the given time
		linear_damp = 0;

	float angular_damp = 1.0 - step * get_total_angular_damp();

	if (angular_damp < 0) // reached zero in the given time
		angular_damp = 0;

	lv *= linear_damp;
	av *= angular_damp;

	set_linear_velocity(lv);
	set_angular_velocity(av);
}
Example #7
0
void bird_4::skill(){
    set_linear_velocity(b2Vec2(-50, 0));
}
Example #8
0
BodyDescription::BodyDescription(const PhysicsContext &pc, const std::string &resource_id, const XMLResourceDocument &resources)
: impl(new BodyDescription_Impl(pc.impl->get_owner()))
{
	/* example resource entry with all parameters:
	
	<body2d name="TestBody" type="static">
        <position x="0" y="0"/>
        <rotation angle="180"/>
        <velocity x="0" y="0" angular="0"/>
        <damping linear="0" angular="0"/>
		<parameters awake="true" can_sleep="true" bullet="false" active="true" />
    </body2d>

	*/
	XMLResourceNode resource = resources.get_resource(resource_id);
	if (resource.get_type() != "body2d" && resource.get_type() != "body2d_description")
		throw Exception(string_format("Resource '%1' is not of type 'body2d' or 'body2d_description'", resource_id));

	DomNode cur_node = resource.get_element().get_first_child();

	//Body type
	std::string body_type = resource.get_element().get_attribute("type","static");
	if(body_type == "kinematic") set_type(body_kinematic);
	else if(body_type == "dynamic") set_type(body_dynamic);
	else set_type(body_static);

	while(!cur_node.is_null())
	{
		if (!cur_node.is_element()) 
			continue;
		
		DomElement cur_element = cur_node.to_element();
		std::string tag_name = cur_element.get_tag_name();

		//<position x="0" y="0"/>
		if(tag_name == "position")
		{
			float pos_x = 0.0f;
			float pos_y = 0.0f;

			if(cur_element.has_attribute("x"))
			{
				pos_x = StringHelp::text_to_float(cur_element.get_attribute("x"));
			}

			if(cur_element.has_attribute("y"))
			{
				pos_y = StringHelp::text_to_float(cur_element.get_attribute("y"));
			}

			set_position(pos_x, pos_y);
		}

		//<rotation angle="180"/>
		else if(tag_name == "rotation")
		{
			Angle angle(0.0f, angle_degrees);

			if(cur_element.has_attribute("angle"))
			{
				angle = Angle(StringHelp::text_to_float(cur_element.get_attribute("angle")), angle_degrees);
			}

			set_angle(angle);
		}

		//<velocity x="0" y="0" angular="0"/>
		else if(tag_name == "velocity")
		{
			Vec2f velocity(0.0f, 0.0f);
			Angle angular_velocity(0.0f, angle_degrees);

			if(cur_element.has_attribute("x"))
			{
				velocity.x = StringHelp::text_to_float(cur_element.get_attribute("x"));
			}

			if(cur_element.has_attribute("y"))
			{
				velocity.y = StringHelp::text_to_float(cur_element.get_attribute("y"));
			}

			if(cur_element.has_attribute("angular"))
			{
				angular_velocity = Angle(StringHelp::text_to_float(cur_element.get_attribute("angular")), angle_degrees);
			}

			set_linear_velocity(velocity);
			set_angular_velocity(angular_velocity);
		}

		//<damping linear="0" angular="0"/>
		else if(tag_name == "damping")
		{
			float linear;
			float angular;

			if(cur_element.has_attribute("linear"))
			{
				linear = StringHelp::text_to_float(cur_element.get_attribute("linear"));
			}

			if(cur_element.has_attribute("angular"))
			{
				angular = StringHelp::text_to_float(cur_element.get_attribute("angular"));
			}

			set_linear_damping(linear);
			set_angular_damping(angular);
		}

		//<parameters awake="true" can_sleep="true" bullet="false" active="true" />
		else if(tag_name == "parameters")
		{
			bool value;
		
			if(cur_element.has_attribute("awake"))
			{
				value = true;
				value = StringHelp::text_to_bool(cur_element.get_attribute("awake"));
				set_awake(value);
			}
			if(cur_element.has_attribute("active"))
			{
				value = true;
				value = StringHelp::text_to_bool(cur_element.get_attribute("active"));
				set_active(value);
			}
			if(cur_element.has_attribute("bullet"))
			{
				value = false;
				value = StringHelp::text_to_bool(cur_element.get_attribute("bullet"));
				set_as_bullet(value);
			}
			if(cur_element.has_attribute("can_sleep"))
			{
				value = true;
				value = StringHelp::text_to_bool(cur_element.get_attribute("can_sleep"));
				allow_sleep(value);
			}
		}

		cur_node = cur_node.get_next_sibling();
	}
}