Esempio n. 1
0
//-----------------------------------------------------------------------------
// check if click landed on the map, and if yes move camera
bool MapCodegenState::check_click(int x, int y, float *camX, float *camY)
{
        bool ret = false;

        y = gViewSizeY-y;
        short sw = (short)( (MSX(bbur.x) - MSX(bbll.x))/(2.0*orthoX) * gViewSizeX );
        short sh = (short)( (MSY(bbur.y) - MSY(bbll.y))/(2.0*orthoY) * gViewSizeY );
        short ssx = (short)( (MSX(bbll.x))/(2.0*orthoX) * gViewSizeX + (gViewSizeX/2) );
        short ssy = (short)( (MSY(bbll.y))/(2.0*orthoY) * gViewSizeY + (gViewSizeY/2) );
        short sex = (short)( ssx + sw );
        short sey = (short)( ssy + sh );

        if( (x>=ssx) && (x<=sex) && (y>=ssy) && (y<=sey) ) {
                //cout << " cc in " << (*camX) <<","<<(*camY) << endl; // debug
                ret = true;
        } else {
                if(x<=ssx) x = ssx;
                if(x>=sex) x = sex;
                if(y<=ssy) y = ssy;
                if(y>=sey) y = sey;
        }

        *camX = -(bbur.x-bbll.x) * ((float)(x-ssx)/(float)(sex-ssx));
        *camY = -(bbur.y-bbll.y) * ((float)(y-ssy)/(float)(sey-ssy));

        //cout << " cc " << ssx<<","<<ssy << " - " <<sex<<","<<sey<< endl; // debug
        //cout << " c2 " << x<<","<<y << " - " <<gViewSizeX<<","<<gViewSizeY<< endl; // debug
        return ret;
}
Esempio n. 2
0
void MapCodegenState::begin_node(node_t* node)
{
        double sx = MSX(node->u.coord.x);
        double sy = MSY(node->u.coord.y);

        glColor4f( 0.0, 1.0, 0.0, 0.5*gFade);
        glPointSize( 3.0 );
        glBegin(GL_POINTS);
        glVertex3f( sx,sy, zpos );

        glEnd();
}
Esempio n. 3
0
//-----------------------------------------------------------------------------
// function called by DotVisualizer to display view info
void MapCodegenState::show_view( void )
{
        double sx = MSX(-gCamX);
        double sy = MSY(-gCamY);
        double lsx = MSX(-gLookatX);
        double lsy = MSY(-gLookatY);
        //double cx = gLookatX-gCamX, cy = gLookatY-gCamY, cz = 0.0-gCamZ;

        if(!gMouseIn) {
                glColor4f( 1.0, 0.0, 0.2, 0.25*gFade );
        } else {
                glColor4f( 1.0, 0.0, 0.2, 0.50*gFade );
        }
        glPointSize( 5.0 );
        glBegin(GL_QUADS);
        glVertex3f( MSX(gViewRegion[0].x),MSY(gViewRegion[0].y), 0.0 );
        glVertex3f( MSX(gViewRegion[2].x),MSY(gViewRegion[2].y), 0.0 );
        glVertex3f( MSX(gViewRegion[3].x),MSY(gViewRegion[3].y), 0.0 );
        glVertex3f( MSX(gViewRegion[1].x),MSY(gViewRegion[1].y), 0.0 );
        glEnd();

        /* draw map and viewing region */
        glColor4f( 0.0, 0.0, 0.7, 0.5*gFade);
        glLineWidth( 1.0 );
        glBegin(GL_LINES);
        glVertex3f( sx,sy, zpos );
        glVertex3f( lsx,lsy, zpos );
        glEnd();

        glColor4f( 0.5, 0.5, 1.0, 0.5*gFade);
        glPointSize( 10.0 );
        glBegin(GL_POINTS);
        glVertex3f( sx,sy, zpos );
        glEnd();

        glColor4f( 0.0, 0.0, 0.2, 0.5*gFade);
        glPointSize( 2.0 );
        glBegin(GL_POINTS);
        glVertex3f( lsx,lsy, zpos );
        glEnd();

        //cout << " sv " << sx<<","<<sy << " - " << x <<","<<y << endl; // debug
}
Esempio n. 4
0
void MapCodegenState::begin_graph(graph_t* pGraph, box , point )
{
        // draw map
        double llx = pGraph->u.bb.LL.x;
        double lly = pGraph->u.bb.LL.y;
        double urx = pGraph->u.bb.UR.x;
        double ury = pGraph->u.bb.UR.y;
        double scaleX = (urx-llx);
        double scaleY = (ury-lly);

        //if(scaleY<scaleX) mapScale = (1.0/scaleX)*2.0;
        //else                                                  mapScale = (1.0/scaleY)*2.0;
        //mapScale *= 0.3;      

        if(scaleY<scaleX) {
                mapScale = ( mapDestSize /scaleY);
                if(( scaleX * mapScale )> (orthoX*2.0-mapOffset*2.0) ) {
                        mapScale = ( (orthoX*2.0-mapOffset*2.0)/scaleX);
                }
        } else {
                mapScale = ( mapDestSize /scaleX);
                if(( scaleY * mapScale )> (orthoX*2.0-mapOffset*2.0) ) {
                        mapScale = ((orthoX*2.0-mapOffset*2.0)/scaleY);
                }
        }

        //gMousePosY = gViewSizeY-gMousePosY;
        short sw = (short)( (MSX(bbur.x) - MSX(bbll.x))/(2.0*orthoX) * gViewSizeX );
        short sh = (short)( (MSY(bbur.y) - MSY(bbll.y))/(2.0*orthoY) * gViewSizeY );
        short ssx = (short)( (MSX(bbll.x))/(2.0*orthoX) * gViewSizeX + (gViewSizeX/2) );
        short ssy = (short)( (MSY(bbll.y))/(2.0*orthoY) * gViewSizeY + (gViewSizeY/2) );
        short sex = (short)( ssx + sw );
        short sey = (short)( ssy + sh );
        if( (gMousePosX>=ssx) && (gMousePosX<=sex) && 
                        ((gViewSizeY-gMousePosY)>=ssy) && ((gViewSizeY-gMousePosY)<=sey) ) {
                gMouseIn = true;
                //gFade = 1.0;
                //cout << " in " ; // debug
        } else {
                gMouseIn = false;
        }

        if(!gMouseIn) {
                glColor4f( 0,0, 0.25 , 0.75*gFade);
                //glColor4f( 0.0,0.0,0.0, 0.5*gFade);
        } else {
                //glColor4f( 0.25,0.25, 0.5 , 0.75*gFade);
                glColor4f( 0,0, 0.35 , 0.75*gFade);
                //glColor4f( 0.0,0.0,0.0, 0.5*gFade);
        }
        //glBegin(GL_QUADS);
        box bound;
        bound = pGraph->u.bb;
        //glVertex3f( MSX(bbll.x),MSY(bbll.y), zpos );
        //glVertex3f( MSX(bbur.x),MSY(bbll.y), zpos );
        //glVertex3f( MSX(bbur.x),MSY(bbur.y), zpos );
        //glVertex3f( MSX(bbll.x),MSY(bbur.y), zpos );
        //glEnd();

        //cout << " GL map start " << mapScale << endl;

        // setup stencil buffer display
        glEnable( GL_STENCIL_TEST );
        glStencilFunc( GL_ALWAYS, 0x01, 0x01 );
        glStencilOp( GL_REPLACE, GL_REPLACE, GL_REPLACE );
        
        glBegin(GL_QUADS);
        glVertex3f( MSX(bbll.x),MSY(bbll.y), zpos );
        glVertex3f( MSX(bbur.x),MSY(bbll.y), zpos );
        glVertex3f( MSX(bbur.x),MSY(bbur.y), zpos );
        glVertex3f( MSX(bbll.x),MSY(bbur.y), zpos );
        glEnd();

        glStencilFunc( GL_EQUAL, 0x01, 0x01 );
        glStencilOp( GL_KEEP, GL_KEEP, GL_KEEP );

        // draw the rest
        glLineWidth(1.0);
        if(!gMouseIn) {
                glColor4f( 0.0,0.0,0.0, 0.5*gFade);
        } else {
                glColor4f( 0.0,0.0,1.0, 0.5*gFade);
        }
        glBegin(GL_LINES);
        glVertex3f( MSX(bbll.x),MSY(bbll.y), zpos );
        glVertex3f( MSX(bbur.x),MSY(bbll.y), zpos );
        glVertex3f( MSX(bbur.x),MSY(bbur.y), zpos );
        glVertex3f( MSX(bbll.x),MSY(bbur.y), zpos );
        glVertex3f( MSX(bbll.x),MSY(bbur.y), zpos );
        glEnd();

}
Esempio n. 5
0
void updatePMLHFieldUtilAll(int xStart, int xEnd, int yStart, int yEnd, int zStart, int zEnd, int xBound, int yBound, int zBound, pmlConstStruct cx[], pmlConstStruct cy[], pmlConstStruct cz[], int n){
		
	int i, j, k; // These are the indexes
	int x,y,z;// There are indexes for the pmlConstStruct indexs
	long p;
	int m;
	double bxStore, byStore, bzStore;
	double mu;
// Either this, or make cOnes a bigger array with number of elements which are the max of xLen, yLen, zLen
	for (i=xStart;i<xEnd+1;i++){
		x = abs(xBound - i)%PML_LAYERS;	
	for (j=yStart;j<yEnd+1;j++){
		y = abs(yBound - j)%PML_LAYERS;		
	for (k=zStart;k<zEnd+1;k++){
		z = abs(zBound - k)%PML_LAYERS;
			
		p = PMLINDEX(i,j,k);
		bxStore = BX(p);
		byStore = BY(p);
		bzStore = BZ(p);
	
		mu = MUR(m)*MUNOT;
				
		BX(p)     = cy[y].c1*BX(p) + cy[y].c2*(EY(i,j,k+1) - EY(i,j,k) + EZ(i,j,k) - EZ(i,j+1,k) - MSX(m));
		HX(i,j,k) = cz[z].c3*HX(i,j,k) + cz[z].c4*(cx[x].c5*BX(p)-cx[x].c6*bxStore)/mu; 
		 
		BY(p)     = cz[z].c1*BY(p) + cz[z].c2*(EZ(i+1,j,k) - EZ(i,j,k) + EX(i,j,k) - EX(i,j,k+1) - MSY(m));
		HY(i,j,k) = cx[x].c3*HY(i,j,k) + cx[x].c4*(cy[y].c5*BY(p)-cy[y].c6*byStore)/mu; 
		
		BZ(p)     = cx[x].c1*BZ(p) + cx[x].c2*(EX(i,j+1,k) - EX(i,j,k) + EY(i,j,k) - EY(i+1,j,k) - MSZ(m));
		HZ(i,j,k) = cy[y].c3*HZ(i,j,k) + cy[y].c4*(cz[z].c5*BZ(p)-cz[z].c6*bzStore)/mu; 
	}}} // end for

}// end updatePMLHFieldUtilAll