Ejemplo n.º 1
0
// Am I completely inside a given box?
bool guiGate::isWithinBox(GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) {
	klsBBox selBBox;
	selBBox.reset();
	selBBox.addPoint(GLPoint2f( x1, y1) );
	selBBox.addPoint(GLPoint2f( x2, y2) );
	return selBBox.contains(this->getBBox());
}
Ejemplo n.º 2
0
// Check if any of the hotspots of this gate are within the delta
// of the world coordinates sX and sY. delta is in gl coords.
string guiGate::checkHotspots(GLfloat x, GLfloat y, GLfloat delta) {
	// Set up the mouse as a collision object:
	klsCollisionObject mouse(COLL_MOUSEBOX);
	klsBBox mBox;
	mBox.addPoint(GLPoint2f( x, y) );
	mBox.extendTop(delta);
	mBox.extendBottom(delta);
	mBox.extendLeft(delta);
	mBox.extendRight(delta);
	mouse.setBBox(mBox);

	// Check if any hotspots hit the mouse:
	CollisionGroup results = this->checkSubsToObj(&mouse);
	CollisionGroup::iterator rs = results.begin();
	while(rs != results.end()) {
		// If there were any hotspots that hit, then return
		// the first one to the caller:
		if((*rs)->getType() == COLL_GATE_HOTSPOT) {
			return((gateHotspot*) *rs)->name;
		}

		rs++;
	}

	return "";
}
Ejemplo n.º 3
0
// Draw this gate as selected from now until unselect() is
// called, if the coordinate passed to it is within
// this gate's bounding box in GL coordinates.
// Return true if this gate is selected.
bool guiGate::clickSelect(GLfloat x, GLfloat y) {
	if(this->getBBox().contains( GLPoint2f( x, y) ) ) {
		selected = true;
		return true;
	} else {
		return false;
	}
}
Ejemplo n.º 4
0
// Convert model->world coordinates:
GLPoint2f guiGate::modelToWorld(GLPoint2f c) {

	// Perform a matrix-vector multiply to get the point coordinates in world-space:
	GLfloat x = c.x * mModel[0] + c.y * mModel[4] + 1.0*mModel[12];
	GLfloat y = c.x * mModel[1] + c.y * mModel[5] + 1.0*mModel[13];

	return GLPoint2f(x, y);
}
Ejemplo n.º 5
0
// Insert a hotspot in the hotspot list.
void guiGate::insertHotspot(float x1, float y1, string connection) {
	if(hotspots.find(connection) != hotspots.end()) return; // error: hotspot already exists
	
	gateHotspot* newHS = new gateHotspot(connection);
	newHS->modelLocation = GLPoint2f(x1, y1);

	// Add the hs to the gate's struct:
	hotspots[connection] = newHS;
	
	// Add the hs to the gate's sub-object list:
	this->insertSubObject(newHS);
	
	// Update the hotspot's world-space bbox:
	updateBBoxes();
}
Ejemplo n.º 6
0
void gateImage::setViewport() {
	// Set the projection matrix:	
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();

	wxSize sz = GetClientSize();
	klsBBox m_gatebox = m_gate->getModelBBox();
	GLPoint2f minCorner = GLPoint2f(m_gatebox.getLeft()-0.5,m_gatebox.getTop()+0.5);
	GLPoint2f maxCorner = GLPoint2f(m_gatebox.getRight()+0.5,m_gatebox.getBottom()-0.5);

	double screenAspect = (double) sz.GetHeight() / (double) sz.GetWidth();
	double mapWidth = maxCorner.x - minCorner.x;
	double mapHeight = minCorner.y - maxCorner.y; // max and min corner's defs are weird...
	
	GLPoint2f orthoBoxTL, orthoBoxBR;
	
	// If the map's width is the limiting factor:
	if( screenAspect * mapWidth >= mapHeight ) {
		// Fit to width:
		double imageHeight = screenAspect * mapWidth;

		// Set the ortho box width equal to the map width, and center the
		// height in the box:
		orthoBoxTL = GLPoint2f( minCorner.x, minCorner.y + 0.5*(imageHeight - mapHeight) );
		orthoBoxBR = GLPoint2f( maxCorner.x, maxCorner.y - 0.5*(imageHeight - mapHeight) );
	} else {
		// Fit to height:
		double imageWidth = mapHeight / screenAspect;

		// Set the ortho box height equal to the map height, and center the
		// width in the box:
		orthoBoxTL = GLPoint2f( minCorner.x - 0.5*(imageWidth - mapWidth), minCorner.y );
		orthoBoxBR = GLPoint2f( maxCorner.x + 0.5*(imageWidth - mapWidth), maxCorner.y );
	}

	// gluOrtho2D(left, right, bottom, top); (In world-space coords.)
	gluOrtho2D(orthoBoxTL.x, orthoBoxBR.x, orthoBoxBR.y, orthoBoxTL.y);
	glViewport(0, 0, (GLint) sz.GetWidth(), (GLint) sz.GetHeight());

	// Store minCorner and maxCorner for use in mouse handler:
	minCorner = orthoBoxTL;
	maxCorner = orthoBoxBR; 

	// Set the model matrix:
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
}
Ejemplo n.º 7
0
// Insert a line in the line list.
void guiGate::insertLine(float x1, float y1, float x2, float y2) {
	vertices.push_back(GLPoint2f( x1, y1) );
	vertices.push_back(GLPoint2f( x2, y2) );
}
Ejemplo n.º 8
0
void klsMiniMap::setViewport() {
	// Set the projection matrix:	
	glMatrixMode (GL_PROJECTION);
	glLoadIdentity ();

	wxSize sz = GetClientSize();
	float minX = FLT_MAX, minY = FLT_MAX, maxX = -FLT_MAX, maxY = -FLT_MAX;
	hash_map < unsigned long, guiGate* >::iterator gateWalk = gateList->begin();
	while (gateWalk != gateList->end()) {
		float x, y;
		(gateWalk->second)->getGLcoords(x, y);
		if (x < minX) minX = x;
		if (y < minY) minY = y;
		if (x > maxX) maxX = x;
		if (y > maxY) maxY = y;
		gateWalk++;
	}
	if (origin.x < minX) minX = origin.x;
	if (origin.y > maxY) maxY = origin.y;
	if (endpoint.x > maxX) maxX = endpoint.x;
	if (endpoint.y < minY) minY = endpoint.y;

	minCorner = GLPoint2f(minX-5,maxY+5);
	maxCorner = GLPoint2f(maxX+5,minY-5);

	double screenAspect = (double) sz.GetHeight() / (double) sz.GetWidth();
	double mapWidth = maxCorner.x - minCorner.x;
	double mapHeight = minCorner.y - maxCorner.y; // max and min corner's defs are weird...
	
	GLPoint2f orthoBoxTL, orthoBoxBR;
	
	// If the map's width is the limiting factor:
	if( screenAspect * mapWidth >= mapHeight ) {
		// Fit to width:
		double imageHeight = screenAspect * mapWidth;

		// Set the ortho box width equal to the map width, and center the
		// height in the box:
		orthoBoxTL = GLPoint2f( minCorner.x, minCorner.y + 0.5*(imageHeight - mapHeight) );
		orthoBoxBR = GLPoint2f( maxCorner.x, maxCorner.y - 0.5*(imageHeight - mapHeight) );
	} else {
		// Fit to height:
		double imageWidth = mapHeight / screenAspect;

		// Set the ortho box height equal to the map height, and center the
		// width in the box:
		orthoBoxTL = GLPoint2f( minCorner.x - 0.5*(imageWidth - mapWidth), minCorner.y );
		orthoBoxBR = GLPoint2f( maxCorner.x + 0.5*(imageWidth - mapWidth), maxCorner.y );
	}

	// gluOrtho2D(left, right, bottom, top); (In world-space coords.)
	gluOrtho2D(orthoBoxTL.x, orthoBoxBR.x, orthoBoxBR.y, orthoBoxTL.y);
	glViewport(0, 0, (GLint) sz.GetWidth(), (GLint) sz.GetHeight());

	// Store minCorner and maxCorner for use in mouse handler:
	minCorner = orthoBoxTL;
	maxCorner = orthoBoxBR;

	// Set the model matrix:
	glMatrixMode (GL_MODELVIEW);
	glLoadIdentity ();
}