Beispiel #1
0
        void rotating_body::update(const simulation_context *c)
        {
            if (rotator)
                rotator->calc_orientation(c->julian_cur, get_orientation(), get_angular_velocity());

            assert(get_linear_velocity().mag() == 0);
        } // update()
Beispiel #2
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);


}
Beispiel #3
0
        void orbital_frame::update(const simulation_context *c)
        {
            if (prop)
                prop->update(c->julian_cur, get_translation(), get_linear_velocity());

            assert(get_angular_velocity().mag() == 0);
        } // orbital_frame::update()
	double agent_body::get_sensor_value(agent_sensor_id const& sensor) const
	{
		switch(sensor)
		{
			case Position_X:
			return get_position().x;
			case Position_Y:
			return get_position().y;
			case WorldVelocity_X:
			return get_linear_velocity().x;
			case WorldVelocity_Y:
			return get_linear_velocity().y;
			case KineticEnergy:
			return get_kinetic_energy();

			default:
			throw std::exception("Invalid Sensor Id");
		}
	}
Beispiel #5
0
		size_t composite_body::initialize_state_value_bindings_(sv_bindings_t& bindings, sv_accessors_t& accessors) const
		{
			auto initial_count = bindings.size();
			auto bound_id = accessors.size();

			bindings[s_sv_names.left.at(StateValue::PositionX)] = bound_id++;
			accessors.push_back([this]
			{
				return get_com_position().x;
			});
			bindings[s_sv_names.left.at(StateValue::PositionY)] = bound_id++;
			accessors.push_back([this]
			{
				return get_com_position().y;
			});
			bindings[s_sv_names.left.at(StateValue::LinVelX)] = bound_id++;
			accessors.push_back([this]
			{
				return get_linear_velocity().x;
			});
			bindings[s_sv_names.left.at(StateValue::LinVelY)] = bound_id++;
			accessors.push_back([this]
			{
				return get_linear_velocity().y;
			});
			bindings[s_sv_names.left.at(StateValue::KE)] = bound_id++;
			accessors.push_back([this]
			{
				return get_kinetic_energy();
			});

			// TODO: what about joints added or removed dynamically? can these be supported?
			for(auto const& rev : m_revolutes)
			{
				rev.rev->initialize_state_value_bindings_(bindings, accessors, rev.name);
			}

			return bindings.size() - initial_count;
		}
Beispiel #6
0
Variant RigidBodyBullet::get_state(PhysicsServer::BodyState p_state) const {
	switch (p_state) {
		case PhysicsServer::BODY_STATE_TRANSFORM:
			return get_transform();
		case PhysicsServer::BODY_STATE_LINEAR_VELOCITY:
			return get_linear_velocity();
		case PhysicsServer::BODY_STATE_ANGULAR_VELOCITY:
			return get_angular_velocity();
		case PhysicsServer::BODY_STATE_SLEEPING:
			return !is_active();
		case PhysicsServer::BODY_STATE_CAN_SLEEP:
			return can_sleep;
		default:
			WARN_PRINTS("This state " + itos(p_state) + " is not supported by Bullet");
			return Variant();
	}
}
Beispiel #7
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);
}