Exemple #1
0
// Set the text for the input-field to display
void InputField::SetText(std::string text)
{
	this->text = text;

	// Update the displayed text
	UpdateDisplayText();
}
Exemple #2
0
bool nn_testing_app::Update()
{
	if(frame_by_frame)
	{
		if(!advance)
		{
			return core->Update();
		}
		advance = false;
	}

	Number elapsed = core->getElapsed();
	double timestep = 0.01;

	std::vector< double > inputs;
	problem_t::state problem_st;
	problem_st.agents.resize(1);
	problem_st.agents[0] = ship_st;

	problem_t::nn_agent_impl< 2, 0 > agent(ship_st.thruster_cfg->num_thrusters());
	//agent.nn = boost::shared_ptr< FANN::neural_net >(new FANN::neural_net(nn));
	agent.nn = nn;
	thruster_base::thruster_activation ta = agent(problem_st.get_sensor_state(0));
	
	dim_traits::force_t thrust;
	dim_traits::torque_t torque;
	boost::tie(thrust, torque) = ship_st.thruster_cfg->calc_resultants(ta, ship_st.c_of_mass);

	double thruster_power = 0.02;//0.001;

	dim_traits::force_t thrust_W = dim_traits::transform_dir(thrust, ship_st.orientation);
	ship_st.lin_velocity += thrust_W * thruster_power * timestep;

	dim_traits::torque_t torque_W = dim_traits::transform_dir(torque, ship_st.orientation);
	ship_st.ang_velocity += torque_W * thruster_power * timestep;
/* todo:
	st.delta -= st.omega * timestep;
	// Keep delta in the range [-Pi, Pi)
	st.delta = std::fmod(st.delta + boost::math::double_constants::pi, 2.0 * boost::math::double_constants::pi) -
		boost::math::double_constants::pi;
*/
	ship_st.position += ship_st.lin_velocity * timestep;
			
	// Now update the bot's world space facing, using the new angular velocity
	ship_st.orientation += ship_st.ang_velocity * timestep;
	// TODO: facing = std::fmod(facing, 2.0 * boost::math::double_constants::pi);

/*	Vector2d vel2d_world = Eigen::Rotation2D< double >(facing) * Vector2d(st.lin_vel[0], st.lin_vel[1]);
*/

	for(size_t i = 0; i < ship_st.thruster_cfg->num_thrusters(); ++i)
	{
		if(ta[i])
		{
			thruster_sys[i].t.engage();
		}
		else
		{
			thruster_sys[i].t.disengage();
		}
	}
	
	ship_base->setPosition(to_polycode_vector(ship_st.position));// * SHIP_BASE_SIZE / 2);

#if 0
	// Instead of moving the ship, move the background
	Vector3 cur_pos = grid->getPosition();
	cur_pos.x += -SCREEN_WIDTH / 2 + vel2d_world[0] * SHIP_BASE_SIZE / 2;
//	cur_pos.y += -SCREEN_HEIGHT / 2 + vel2d_world[1] * SHIP_BASE_SIZE / 2;
	cur_pos.x = std::fmod(cur_pos.x, GRID_SCALE);
//	cur_pos.y = std::fmod(cur_pos.y, GRID_SCALE);

	grid->setPosition(SCREEN_WIDTH / 2 + cur_pos.x, /*SCREEN_HEIGHT / 2 +*/ cur_pos.y);
#endif

	ship_base->setRotation(ship_st.orientation * 360.0 / (2.0 * PI));

/*	if(lin_vel_line != nullptr)
	{
		ship_base->removeChild(lin_vel_line);
		delete lin_vel_line;
	}
	lin_vel_line = new ScreenLine(Vector2(0, 0), Vector2(st.lin_vel[0] * 30, st.lin_vel[1] * 30));
	ship_base->addChild(lin_vel_line);

	if(lin_acc_line != nullptr)
	{
		ship_base->removeChild(lin_acc_line);
		delete lin_acc_line;
	}
	lin_acc_line = new ScreenLine(Vector2(0, 0), Vector2(thrust[0] * 30, thrust[1] * 30));
	lin_acc_line->setColor(1.0, 0.0, 0.0, 1.0);
	ship_base->addChild(lin_acc_line);
*/

	for(int t = 0; t < ship_st.thruster_cfg->num_thrusters(); ++t)
	{
		if(!thruster_sys[t].t.is_engaged())
		{
			thruster_sys[t].t.cool_down(elapsed);
		}

		thruster_shapes[t]->setColor(1.0, 1.0 - thruster_sys[t].t.temperature(), 1.0 - thruster_sys[t].t.temperature(), 1.0);
	}

	UpdateDisplayText();
	
	return core->updateAndRender();
}