Beispiel #1
0
void rect(const unsigned texture,
		  const vec2& v0,
		  const vec2& v1,
		  const vec2& vt0,
		  const vec2& vt1)
{
	if(!glIsTexture(texture))
		return;

	const BindTexture2D bind(texture);
	GLint old_state(0);
	glGetTexEnviv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, &old_state);

	if(old_state != GL_MODULATE)
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);

	vec2 vp[4] = {v0, vec2(v1.x, v0.y), vec2(v0.x, v1.y), v1};
	vec2 vtp[4] = {vt0, vec2(vt1.x, vt0.y), vec2(vt0.x, vt1.y), vt1};

	glTexCoordPointer(2, GL_FLOAT, 0, vtp);
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);
	glVertexPointer(2, GL_FLOAT, 0, vp);
	glEnableClientState(GL_VERTEX_ARRAY);
	glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
	glDisableClientState(GL_VERTEX_ARRAY);
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);

	if(old_state != GL_MODULATE)
		glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, old_state);
}
Beispiel #2
0
std::ostream & operator<< (std::ostream & os, const pfp::cp::Bytes & b) {
  // Save state of stream
  std::ios old_state(nullptr);
  old_state.copyfmt(os);

  // Apply our iomanips and print the hex prefix
  os << std::hex << std::setfill('0') << "0x";

  // Print out the hex representation of our Bytes in MSB first order
  for (auto it = b.rbegin(), end = b.rend(); it != end; ++it) {
    os << std::setw(2) << static_cast<int>(*it);
  }

  // Restore state of stream
  os.copyfmt(old_state);

  return os;
}
Beispiel #3
0
void Widget::SetState( State state ) {
	// Do nothing if state wouldn't change.
	if( m_state == state ) {
		return;
	}

	State old_state( m_state );
	m_state = state;

	// If HandleStateChange() changed the state, do not call observer, will be
	// done from there too.
	if( m_state != old_state ) {
		HandleStateChange( old_state );
		OnStateChange();
	}

	if( state == Active ) {
		GrabFocus( shared_from_this() );
	}
}
Beispiel #4
0
int main()
{
	//learning factor
	const double alpha = 0.5;
	//discount factor
	const double gamma = 0.5;
	
	const double deltatime = 0.05;
	const double mass = 0.5;
	const double length = 0.08;
	const int angle_bins = 100;
	const int velocity_bins = 50;
	const int torque_bins = 9;
	const double max_angle = M_PI;
	const double max_velocity = 10;
	const double max_torque = 4;
	
	Environment* env = new Environment(0, 0, 0, max_torque, 0, deltatime, mass, length, gamma);
	
	//seed rng
	std::srand(static_cast<unsigned int>(std::time(NULL)));
	
	//create the possible actions as well as the chosen action
	float chosen_action = 1;	// rip f
	float actions[torque_bins];
	for (int i = 0; i < (max_torque*2)+1 ; ++i)
	{
		actions[i] = static_cast<float>(-max_torque+i);
	}
	
	//create a priority queue to copy to all the state space priority queues
	PriorityQueue<float, double> initiator_queue(MAX);
	for (int i = 0; i < torque_bins; ++i)
	{
		initiator_queue.enqueueWithPriority(actions[i], 0);
	}
	
	//create the state space
	StateSpace space(initiator_queue, angle_bins, velocity_bins, torque_bins, max_angle, max_velocity, max_torque);
	
	//state objects
	State current_state(0, 0, 0);
	State old_state(0, 0, 0);
	
//	std::ofstream file("output.txt");
//	file.precision(16);
	
//	file << "Trialno" << "	" << "Time" << "		" << "Theta" << "	" << "Thetadot" << "		" << "Torque" << std::endl;
	
	double trialno = 1;
	unsigned long i=0;
	while (true)
	{
		current_state.theta = env->getTheta();
		current_state.theta_dot = env->getThetadot();
		current_state.torque = env->getTorque();
		
		std::cout << "State Read" << std::endl;
		
		updateQ(space, chosen_action, old_state, current_state, alpha, gamma);

		if (std::abs(current_state.theta_dot) > 5)
		{
			env->resetPendulum();
			std::cout<<"->unsuccessful trial\n";
			trialno++;
			i = 0;
			continue;
		}
		
		old_state = current_state;
		
		chosen_action = selectAction(space[current_state],i);
		std::cout << "Action Selected" << std::endl;
		env->setTorque(chosen_action);
		
		env->propagate();
		std::cout << "Environment Propagated\n" << std::endl;

//		file << trialno << "	  " << env->getTime() << "	  " << current_state.theta << "	  " << current_state.theta_dot << "	   " << current_state.torque << std::endl;
		++i;
	}

//	file.close();
	
	delete env;
	
	return 1;
}