Пример #1
0
/**
 * Check whether active unit can still drive,
 * otherwise make switch.
 */
void
Controls::checkActive()
{
    if (m_active == m_units.end() || !(*m_active)->canDrive()) {
        switchActive();
    }
}
void GLWidget::mousePressEvent(QMouseEvent *event)
{
	if (event->button() == Qt::RightButton || event->button() == Qt::LeftButton) {
		lastPoint = event->pos();
		dragging = true;
	}
	if(event->button() == Qt::LeftButton) {
		//Picking
		//Make sure we sample from the fbo textures
		glBindFramebuffer(GL_FRAMEBUFFER, fbo);
		//Make sure we are done drawing
		glFlush();
		glFinish();

		//We want to sample the picking buffer
		glReadBuffer( GL_COLOR_ATTACHMENT1);
		glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

		//Make some room for the pixel data and transform into tex coords
		unsigned char data[4];
		int x = 1024 * (event->x() / (float) width());
		int y = 786 * ((height() - event->y()) / (float) height());
		;
		//Get dem pixorz!
		glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, data);

		//Unpack the data into the id
		int pickedID = data[0] + data[1] * 256 + data[2] * 256*256;
		if(pickedID < 100) { //The background color, have to make this more robust
			emit changedActiveId(pickedID);
			emit changedCurrent(scene->identify(pickedID));
		}
		//Leave as before
		glBindFramebuffer(GL_FRAMEBUFFER, 0);
	}
	emit switchActive(this);
}