예제 #1
0
// Generate the Graphics
void displayFcn(void)
{
	// Clear display window.
	glClear(GL_COLOR_BUFFER_BIT);

	// Draw 3 different rectangles
	drawRectangles();

	// Draw triangles
	drawTriangles();

	// Draw house
	drawHouse();
	
	// Draw square
	drawSquare();

	// Execute
	glFlush();
}
예제 #2
0
    void display()
    {
            SDL_FillRect(screen,NULL,0);
            b2Body* tmp=world->GetBodyList();
            b2Vec2 points[4];
            while(tmp)
            {
                    for(int i=0;i<4;i++)
                    {
                            points[i]=((b2PolygonShape*)tmp->GetFixtureList()->GetShape())->GetVertex(i);
                            rotateTranslate(points[i],tmp->GetWorldCenter(),tmp->GetAngle());
                    }
                    char* usr1 = static_cast<char*>(tmp->GetFixtureList()->GetBody()->GetUserData());
                    if (std::string(usr1).compare("cuadrado") == 0)
//                        printf("[%f, %f][%f, %f][%f, %f][%f, %f]\n", points[0].x, points[0].y, points[1].x, points[1].y, points[2].x, points[2].y, points[3].x, points[3].y );
                
                    drawSquare(points,tmp->GetWorldCenter(),tmp->GetAngle());
                    tmp=tmp->GetNext();
            }
    }
예제 #3
0
void glButton::draw()
{
	if (!m_bShow) return;
	if (m_state != BTN_NORMAL) 
	{
		crrtFrame++;
		if (crrtFrame >= animateFrames) 
		{
			m_state = BTN_NORMAL;
			m_x += m_dx;
			m_y += m_dy;
		}
		if (m_state == BTN_MOVEING)
		{
			float t = (float)crrtFrame / animateFrames - 1.0;
			m_rate = 1.0 - t*t*t*t;
		}
	}
	glBindTexture(GL_TEXTURE_2D, m_tex);
	drawSquare(getX(), getY(), getR());
}
예제 #4
0
//! [32]
void QrfeKeyBoard::showNextPiece()
{
    if (!nextPieceLabel)
        return;

    int dx = nextPiece.maxX() - nextPiece.minX() + 1;
    int dy = nextPiece.maxY() - nextPiece.minY() + 1;

    QPixmap pixmap(dx * squareWidth(), dy * squareHeight());
    QPainter painter(&pixmap);
    painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background());

    for (int i = 0; i < 4; ++i) {
        int x = nextPiece.x(i) - nextPiece.minX();
        int y = nextPiece.y(i) - nextPiece.minY();
        drawSquare(painter, x * squareWidth(), y * squareHeight(),
                   nextPiece.shape());
    }
    nextPieceLabel->setPixmap(pixmap);
//! [32] //! [33]
}
예제 #5
0
void TetrisBoard::showNextPiece()
{
    if (!nextPieceLabel)
        return;

    const Tetronimo& nextPiece = gameModel.getNextPiece();
    int dx = nextPiece.maxX() - nextPiece.minX() + 1;
    int dy = nextPiece.maxY() - nextPiece.minY() + 1;

    QPixmap pixmap(dx * squareWidth(), dy * squareHeight());
    QPainter painter(&pixmap);
    painter.fillRect(pixmap.rect(), nextPieceLabel->palette().background());

    for (int i = 0; i < 4; ++i) {
        int x = nextPiece.x(i) - nextPiece.minX();
        int y = nextPiece.y(i) - nextPiece.minY();
        drawSquare(painter, x * squareWidth(), y * squareHeight(),
                   nextPiece.shape());
    }
    nextPieceLabel->setPixmap(pixmap);
}
예제 #6
0
void drawCorners(ImgRGB& img_show, const Mat_i& corners, uchar r, uchar g,
		uchar b, uchar sym) {
	int nc = corners.rows;
	//draw corners
	int i;
	for (i = 0; i < nc; ++i) {
		int x0 = corners.data[2 * i];
		int y0 = corners.data[2 * i + 1];

		switch (sym) {
		case 'c':
			drawCross(img_show, x0, y0, r, g, b);
			break;
		case 's':
			drawSquare(img_show, x0, y0, r, g, b);
			break;
		case '.':
			drawPoint(img_show, x0, y0, r, g, b);
			break;
		}
	}
}
예제 #7
0
/**
 * @brief Draws the final box with the computed colour.
 *
*/
void drawFinalBox()
{
	//outR = alphaR,
	//outG = alphaG,
	//outB = alphaB
	//..

	//The resulting channel's colour is simply the intensity for each box
	float calcR = a[0];
	float calcG = a[1];
	float calcB = a[2];

	//Draw the square with this colour
	drawSquare(0.0, 0.0, calcR, calcG, calcB, 1.0f, 0.08f);

	//Draw the text underneath. First set up a string
	stringstream str;
	str << fixed << setprecision(2) << "(" << calcR << ", " << calcG << ", " << calcB << ", " << "100%)";

	//And then draw underneath
	Fonts::drawText(0.04, -0.03, str.str(), Fonts::ALIGNMENT_CENTER);
}
예제 #8
0
static void sudoku_draw_grid(UINT8 row, UINT8 col)
{
    UINT8 pos;
    UINT8 WStyle;

    pos = row*BOARD_COLS+col;
    if(IS_FIXED(pos))
        WStyle = WSTL_GAME_BG_FIX;
    else if((row%6<3&&col%6<3)||(row%6>=3&&col%6>=3))
        WStyle = WSTL_GAMESUDOKU_NORMAL1_HD;
    else
        WStyle = WSTL_GAMESUDOKU_NORMAL2_HD;

    drawSquare(BK_X_OFFSET+col*GRID_WIDTH-2, BK_Y_OFFSET+row*GRID_WIDTH-2,\
               GRID_WIDTH+4, GRID_WIDTH+4, WStyle);

    if(pboard[pos]!=' ')
    {
        OSD_MoveObject((POBJECT_HEAD)&txt_Grid,BK_X_OFFSET+col*GRID_WIDTH,BK_Y_OFFSET+row*GRID_WIDTH,FALSE);
        OSD_SetTextFieldContent(&txt_Grid,STRING_NUMBER, (UINT32)(pboard[pos]-'0'));
        OSD_DrawObject((POBJECT_HEAD)&txt_Grid,C_UPDATE_ALL);
    }
}
예제 #9
0
void Billboard::Draw(ModelviewStack* ms)
{
	if (!Utility::isVisible(_transform.position, *_cameraPosition, *_cameraDirection))
		return;

	useTexture(_textureID);
	setColour(1.0, 1.0, 1.0);

	useLighting(0);

	ms->Push();
	{
		float height =  _transform.position.y + _transform.scale.y / 4;
		ms->Translate(vec3(_transform.position.x,
						   height,
						   _transform.position.z));

		ms->Rotate(_rotationAngle, vec3(0.0, 1.0, 0.0));
		ms->Scale(vec3(_transform.scale.x / 2, _transform.scale.y / 2, 1.0));
		
		drawSquare(*ms);
	}
	ms->Pop();
}
예제 #10
0
/*------------------------------------------------------------*/
void drawAllObj( void )
{
    MyObject* t;
    t=head;

    while( t != NULL ) {
        switch( t->type ) {
        case OBJ_CIRCLE:
        case OBJ_ELLIPSE:
        case OBJ_SUPER_E:
        case OBJ_RECTANGLE:
            drawRectangle(t);
            break;
        case OBJ_SQUARE:
            drawSquare(t);
            break;
        default:
            drawRectangle(t);
            break;
        };

        t = t->next;
    }
}
예제 #11
0
/**
 * @brief Draws a coloured box, with text underneath and an optional symbol to the right-hand side.
 *
*/
void drawColorBox(float r, float g, float b, float a, string extraSymbol, string box)
{
	//Draw the actual box with the stuff passed
	drawSquare(0.0, 0.0, r, g, b, a, 0.08f);

	//Build a string showing the intensity of this channel
	stringstream str;
	str << fixed << setprecision(1) << "(" << (a * 100) << "%)";

	//Set up the font colour to whatever colour this is, as well as a large font.
	Fonts::setColor(r, g, b);
	Fonts::setFont(GLUT_BITMAP_HELVETICA_18);
	
	//Draw text above the box.
	Fonts::drawText(0.04f, 0.1f, box, Fonts::ALIGNMENT_CENTER);

	//Set to white, draw the additional symbol to the right.
	Fonts::setColor(1, 1, 1);
	Fonts::drawText(0.1f, 0.03f, extraSymbol, Fonts::ALIGNMENT_LEFT);
	
	//Make the font smaller, draw the intensity underneath.
	Fonts::setFont(GLUT_BITMAP_HELVETICA_12);	
	Fonts::drawText(0.04f, -0.03f, str.str(), Fonts::ALIGNMENT_CENTER);	
}
예제 #12
0
void RCDraw::paintEvent ( QPaintEvent * )
{
	QString s;
	QPainter painter ( this );
	painter.setRenderHint(QPainter::HighQualityAntialiasing);

        if(onSelection)
                drawSquare((iniCoorSelected+endCoorSelected)/2, abs(endCoorSelected.x()-iniCoorSelected.x()),abs(endCoorSelected.y()-iniCoorSelected.y()), Qt::green );

        if ( qimg != NULL )
        {
                painter.drawImage ( QRectF(0., 0., imageScale*width, imageScale*height), *qimg, QRectF(0, 0, width, height) );
        }

	painter.setWindow (effWin.toRect() );

	if ( DRAW_PERIMETER )
	{
		painter.setPen ( Qt::blue );
		painter.drawRect ( 0,0,width-1,height-1 );
	}
	if ( DRAW_AXIS )
	{
		drawAxis(Qt::blue, 2);
	}

	//Draw lines
	while ( !lineQueue.isEmpty() )
	{
		TLine l = lineQueue.dequeue();
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}

	//Draw gradient
	while ( !gradQueue.isEmpty() )
	{
		TGrad g = gradQueue.dequeue();
		linGrad.setColorAt ( 0, g.color );
		linGrad.setColorAt ( 1, g.color1 );
		painter.setBrush ( linGrad );
		painter.setPen ( QPen ( linGrad, 2, Qt::SolidLine, Qt::RoundCap, Qt::RoundJoin ) );
		painter.drawLine ( g.line );
	}

	//Draw ellipses
	while ( !ellipseQueue.isEmpty() )
	{
		TEllipse e = ellipseQueue.dequeue();
		if ( e.fill == true )
			painter.setBrush ( e.color );
		else
			painter.setBrush ( Qt::transparent );
		painter.setPen ( e.color );
		if (fabs(e.ang) > 0.1)
		{
			painter.setPen ( e.color );
			painter.translate( e.center );
			painter.rotate( e.ang );
			painter.drawEllipse ( QPointF(0,0), e.rx, e.ry );
			painter.rotate( -e.ang );
			painter.translate( -e.center );
		}
		else
			painter.drawEllipse( e.center, e.rx, e.ry);
		if ( e.id>=0 )
		{
			painter.drawText ( e.rect, Qt::AlignCenter, s.setNum ( e.id ) );
		}
	}

	//Draw squares
	{
		QPen pen = painter.pen();
		int penwidth = pen.width();
		while ( !squareQueue.isEmpty() )
		{
			TRect r = squareQueue.dequeue();
			if ( r.fill == true )
				painter.setBrush ( r.color );
			else
				painter.setBrush ( Qt::transparent );
			pen.setColor(r.color);
			pen.setWidth(r.width);
			painter.setPen(pen);
			if (fabs(r.ang) > 0.01 )
			{
				QPoint center = r.rect.center();
				painter.translate( center );
				painter.rotate( r.ang );
				painter.drawRoundedRect ( QRect( r.rect.topLeft() - center, r.rect.size() ) , 40 , 40 );
				painter.rotate( -r.ang );
				painter.translate( -center );
			}
			else
				painter.drawRect( r.rect );
			if ( r.id>=0 )
				painter.drawText ( QPointF ( r.rect.x(), r.rect.y() ),  s.setNum ( r.id ) );
		}
		pen.setWidth(penwidth);
		painter.setPen(pen);
	}


	while ( !lineOnTopQueue.isEmpty() )
	{
		TLine l = lineOnTopQueue.dequeue();
		painter.setPen ( QPen ( QBrush ( l.color ),l.width ) );
		painter.drawLine ( l.line );
	}


	//Draw text
	while ( !textQueue.isEmpty() )
	{
		TText t = textQueue.dequeue();
		painter.setBrush ( Qt::transparent );
		painter.setPen ( t.color );
		painter.setWindow ( effWin.normalized().toRect() );
		QFont ant = painter.font();
		QFont temp ( "Helvetica", t.size );
		painter.setFont ( temp );
		painter.drawText( QRect(t.pos.x(), t.pos.y(), 0.82*t.text.size()*t.size, 1.2*t.size), Qt::AlignCenter, t.text);

		painter.setFont ( ant );
		painter.setWindow ( effWin.toRect() );
	}


}
예제 #13
0
void PicrossBoard::displayBoard()
{
	int mostGroups[2] = {0,0};
	for(int i = 0; i < 2; ++i)
	{
		for(groupsList::iterator j = boardDefinition[i].begin(); j != boardDefinition[i].end(); ++j)
		{
			
			if(mostGroups[i] < (*j).size())
			{
				mostGroups[i] = (*j).size();
			}
		}
	}
	//std::cout << "Most groups column: " << mostGroups[column] << "; row: " << mostGroups[row] << std::endl;

	//write the column numbers
	for(int line = 0; line < mostGroups[column]; ++line)
	{
		for(int j = 0; j < mostGroups[row]; ++j)
		{
			std::cout << " ";
		}

		for(groupsList::iterator i = boardDefinition[column].begin(); i != boardDefinition[column].end(); ++i)
		{		
			if((mostGroups[column] - line)<=(*i).size())
			{
				std::cout << (*i).at(line - (mostGroups[column] - (*i).size()));
			}
			else
			{
				std::cout << " ";
			}
		}

		std::cout << std::endl;
	}

	//write the row numbers
	for(groupsList::iterator i = boardDefinition[row].begin(); i != boardDefinition[row].end(); ++i)
	{
		//include row gap
		for(int j = 0; j < mostGroups[row] - ((*i).size()); ++j)
		{
			std::cout << " ";
		}
		
		//add the row numbers
		for(blockGroups::iterator j = (*i).begin(); j != (*i).end(); ++j)
		{
			std::cout << *j;
		}
		
		//display row contents
		for(int j = 0; j < boardDefinition[column].size(); ++j)
		{
			drawSquare(boardContents[((i - boardDefinition[row].begin()) * boardDefinition[column].size()) + j].blockState);
		}

		std::cout << std::endl;
	}
	
		
	
}
예제 #14
0
파일: Goti.cpp 프로젝트: cravindra/OpenGL
void mouse(int bin, int state , int x , int y) 
{
    if(bin==GLUT_LEFT_BUTTON&&state==GLUT_DOWN)
                                               drawSquare(x,y);

}
예제 #15
0
static void lvDisplay(void) {
    glClear(GL_COLOR_BUFFER_BIT);


    applyTransforms();


    glScalef(scale, scale, scale);
	glColor3f(0.25f, 0.25f, 0.25f);
	glLineWidth(2);
	drawLine(-lvWidth-lvTransX, 0, lvWidth-lvTransX, 0);
	drawLine(0, -lvHeight-lvTransY, 0, lvHeight-lvTransY);
	glLineWidth(1);

	lsystem.Draw();		

	// Draw image planes
	glColor3f(1.0, 0.0, 1.0);
	glLineWidth(2);
	drawLine(lsystem.iPlane, lsystem.maxAperture()/2, lsystem.iPlane, -lsystem.maxAperture()/2); 
	drawText(lsystem.iPlane - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "I");
	drawLine(zDist, lsystem.maxAperture()/2, zDist, -lsystem.maxAperture()/2);
	drawText(zDist - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "O");

	// Trace rays through lens system
	glColor3f(0.0, 0.0, 1.0);
	glLineWidth(1);
	
	for (int i = -9; i < 10; i++)
	{
        Ray rayv = Ray(Point(0, iPlaneY, lsystem.iPlane), Vector(0, lsystem.pupil.y/2 * (float) i/9 - iPlaneY, lsystem.pupil.z - lsystem.iPlane));
        Ray& rays = rayv;
        lsystem.Trace(rays, new Ray());
	}
	

	//lsystem.findExitPupil();
	//lsystem.recalAper();
	//lsystem.findF();
	//lsystem.findFp();
	//lsystem.refocus(zDist, -1);

	//Draw principal axes
	glColor3f(0.0, 1.0, 0.0);
	glLineWidth(2);
	drawLine(lsystem.pupil.z, lsystem.pupil.y/2, lsystem.pupil.z, (lsystem.pupil.y+lsystem.maxAperture()) / 2);
	drawLine(lsystem.pupil.z, -lsystem.pupil.y/2, lsystem.pupil.z, (-lsystem.pupil.y-lsystem.maxAperture()) / 2);
	drawText(lsystem.pupil.z, (-lsystem.pupil.y-lsystem.maxAperture()) / 2 - 5, SBFONT, "ep");

	//Draw principal axes
	glColor3f(1.0, 0.0, 0.0);
	glLineWidth(2);
	drawLine(lsystem.p2, lsystem.maxAperture()/2, lsystem.p2, -lsystem.maxAperture()/2);
	drawText(lsystem.p2 - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "P'");
	drawLine(lsystem.p1, lsystem.maxAperture()/2, lsystem.p1, -lsystem.maxAperture()/2);
	drawText(lsystem.p1 - 1, -lsystem.maxAperture()/2 - 5, SBFONT, "P");

	//Draw focal planes
	glColor3f(1.0, 1.0, 0.0);
	drawPoint(5, lsystem.f1, 0);
	drawText(lsystem.f1 - 1, -5, SBFONT, "F");
	drawPoint(5, lsystem.f2, 0);
	drawText(lsystem.f2 - 1, -5, SBFONT, "F'");
	
	glMatrixMode(GL_PROJECTION); glPushMatrix();
	glLoadIdentity();
	gluOrtho2D(0, lvWidth, lvHeight, 0);
	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    drawSquare(0.25f, 0.25f, 0.25f, 0, 0, lvWidth, BARH);
	drawSquare(0.25f, 0.25f, 0.25f, 0, lvHeight, lvWidth, lvHeight-BARH);
	glLoadIdentity();

	gluOrtho2D(-lvWidth, lvWidth, lvHeight, -lvHeight);
	glColor3f(0, 1, 1);
	drawText(-lvWidth + 15, -lvTransY*lvZoom - 8, SBFONT, "+z");
	drawText(lvWidth - 50, -lvTransY*lvZoom - 8, SBFONT, "-z");
	drawText(-lvTransX*lvZoom, -lvHeight + 75, SBFONT, "+y");
	drawText(-lvTransX*lvZoom, lvHeight - 65, SBFONT, "-y");
	
    glColor3f(1, 1, 1);
    const char* mode = lsystem.M == precise ? "precise" : "thick";
	lvText(9, lvHeight-16, SBFONT, 0, "fstop %1.1f (aperture %1.1fmm) | "
		                              "object %1.1fmm | image %1.1fmm | mode: %s", 
									  lsystem.fstop,lsystem.getAperture()->aper,zDist,lsystem.iPlane, mode); 

	lvText(9, 8, SBFONT, 0, "F %1.1fmm | F' %1.1fmm | P %1.1fmm | "
		                    "P' %1.1fmm | exit pupil (%1.1fmm, %1.1fmm)", 
							lsystem.f1,lsystem.f2,lsystem.p1,lsystem.p2,lsystem.pupil.z,lsystem.pupil.y);

	glPopMatrix();
	glutSwapBuffers();
}
void mouse(int btn, int state, int x, int y)
{
    static int count;
    int where;
    static int xp[2],yp[2];
    if(btn==GLUT_LEFT_BUTTON && state==GLUT_DOWN) 
    {
       glPushAttrib(GL_ALL_ATTRIB_BITS);
       
       where = pick(x,y);
       glColor3f(r, g, b);
       if(where != 0)
       {
          count = 0;
          draw_mode = where;
       }
       else switch(draw_mode)
       {
         case(LINE):
          if(count==0)
          {
              count++;
              xp[0] = x;
              yp[0] = y;
          }
          else 
          {
              glBegin(GL_LINES); 
                 glVertex2i(x,wh-y);
                 glVertex2i(xp[0],wh-yp[0]);
              glEnd();
              draw_mode=0;
              count=0;
          }
          break;
        case(RECTANGLE):
          if(count == 0)
          {
              count++;
              xp[0] = x;
              yp[0] = y;
          }
          else 
          {
              if(fill) glBegin(GL_POLYGON);
              else glBegin(GL_LINE_LOOP);
                 glVertex2i(x,wh-y);
                 glVertex2i(x,wh-yp[0]);
                 glVertex2i(xp[0],wh-yp[0]);
                 glVertex2i(xp[0],wh-y);
              glEnd();
              draw_mode=0;
              count=0;
          }
          break;
        case (TRIANGLE):
          switch(count)
          {
            case(0):
              count++;
              xp[0] = x;
              yp[0] = y;
              break;
            case(1):
              count++;
              xp[1] = x;
              yp[1] = y;
              break;
            case(2): 
              if(fill) glBegin(GL_POLYGON);
              else glBegin(GL_LINE_LOOP);
                 glVertex2i(xp[0],wh-yp[0]);
                 glVertex2i(xp[1],wh-yp[1]);
                 glVertex2i(x,wh-y);
              glEnd();
              draw_mode=0;
              count=0;
          }
          break;
        case(POINTS):
          {
             drawSquare(x,y);
             count++;
          }
		  break;
		case(TEXT):
		  {
			 rx=x;
			 ry=wh-y;
			 glRasterPos2i(rx,ry); 
			 count=0;
		  }
       }

       glPopAttrib();
       glFlush();
     }
}
예제 #17
0
int main()
{
	signal(SIGINT, INThandler);

	int  xres,yres,x;

	int Xsamples[20];
	int Ysamples[20];

	int screenXmax, screenXmin;
	int screenYmax, screenYmin;

	float scaleXvalue, scaleYvalue;

	int rawX, rawY, rawPressure, scaledX, scaledY;

	int Xaverage = 0;
	int Yaverage = 0;


	if (openTouchScreen() == 1)
		perror("error opening touch screen");


	getTouchScreenDetails(&screenXmin,&screenXmax,&screenYmin,&screenYmax);

	framebufferInitialize(&xres,&yres);

	scaleXvalue = ((float)screenXmax-screenXmin) / xres;
	printf ("X Scale Factor = %f\n", scaleXvalue);
	scaleYvalue = ((float)screenYmax-screenYmin) / yres;
	printf ("Y Scale Factor = %f\n", scaleYvalue);




	int h;


	int sample;

	while(1){
		for (sample = 0; sample < SAMPLE_AMOUNT; sample++){
			getTouchSample(&rawX, &rawY, &rawPressure);
			Xsamples[sample] = rawX;
			Ysamples[sample] = rawY;
		}

		Xaverage  = 0;
		Yaverage  = 0;

		for ( x = 0; x < SAMPLE_AMOUNT; x++ ){
			Xaverage += Xsamples[x];
			Yaverage += Ysamples[x];
		}

		Xaverage = Xaverage/SAMPLE_AMOUNT;
		Yaverage = Yaverage/SAMPLE_AMOUNT;

		scaledX = 	Xaverage / scaleXvalue;
		scaledY = 	Yaverage / scaleYvalue;
		drawSquare(scaledX, scaledY,5,5,WHITE);
	}
}
예제 #18
0
파일: main.c 프로젝트: LightYourselfUp/MG2
void main(void) {

    unsigned char i,j;

    /* Output configurations */

    ADCON1 |= 0x0F;    // All possible analog input pins config as digital I/O
    CMCON = 0x07;    // Comparators disabled

    /* Natural interaction expansion port configuration    */
    TRISAbits.TRISA4 = 1;    // A4 Botton 3
    TRISAbits.TRISA3 = 1;    // A3 Botton 2
    TRISAbits.TRISA2 = 1;    // A2 Botton 1
    TRISAbits.TRISA1 = 1;    // A1 Potentiometer 2
    TRISAbits.TRISA0 = 1;    // A0 Potentiometer 1

    TRISB = 0;    // B0..B6    Serial input for the Shift Registers
    TRISD = 0;    // D0..D3    Shift Registers control inputs: SCK, RCK, _SCL, _G
    TRISEbits.TRISE0 = 1; //Input button PORTEbits.RE0

    LATA = 0;    // Disable expansion port
    _SCL = 1;    // Disable Shift Register _SCL (Global Clear)
    _G = 0;        // Enables Shift Regusters outputs _G

    // Resetting variables
    for (i = 0; i <= MAX_INDEX_G_BUFFER_GREYSCALE; i++) {
        gBufferGreyscale[i] = 0;
        gPreBufferGreyscale[i] = 0;
    }
    for (i = 0; i <= MAX_INDEX_M_BUFFER_MATRIX; i++) {
        mBufferMatrix[i] = RESET_M_BUFFER_MATRIX;
    }
    iGreyscale = 0;
    iTimer1 = 0;
    iMenu = 0;
    FIRST = 0;
    SECOND = 0;
    THIRD = 0;
    FOURTH = 0;
    FIFTH = 0;
    SIXTH = 0;
    pwm = 0;

    /* Timer 0 Configuration */
    // Used to trigger the refresh matrix printed data routine
    OpenTimer0(TIMER_INT_ON & T0_8BIT & T0_SOURCE_INT & T0_PS_1_1);
    WriteTimer0(0);

    /* Timer 1 Configuration */
    // Used to periodically check the input data (external buttons)
    OpenTimer1(TIMER_INT_ON & T1_SOURCE_INT &  T1_PS_1_8 & T1_OSC1EN_OFF & T1_SYNC_EXT_OFF);
    WriteTimer1( 0x00 & 0x00 );

    /* Timer 3 Configuration */
    // Used to create delays within the different menus without blocking with delays
    OpenTimer3( TIMER_INT_ON & T3_16BIT_RW & T3_SOURCE_INT & T3_PS_1_8 & T3_SYNC_EXT_OFF);
    WriteTimer3( 0x00 & 0x00 );

    /* A/D configuration */
    //ADCON1
    ADCON1bits.VCFG1 = 0;    // Voltage Reference Configuration bit (Vref-) = Vss
    ADCON1bits.VCFG0 = 0;    // Voltage Reference Configuration bit (Vref+) = Vdd
    ADCON1bits.PCFG3 = 1;    // PCFG = "1110" enables AN0 and AN1
    ADCON1bits.PCFG2 = 1;
    ADCON1bits.PCFG1 = 1;
    ADCON1bits.PCFG0 = 0;

    //ADCON0
    ADCON0bits.ADON = 1;    // A/D converter module is enabled
    ADCON0bits.CHS0 = 0;    // CHS = "0000" AN0 selected
    ADCON0bits.CHS1 = 0;
    ADCON0bits.CHS2 = 0;
    ADCON0bits.CHS3 = 0;

    //ADCON2
    ADCON2bits.ADCS0 = 0;    // A/D Adquisition Clock Select bits
    ADCON2bits.ADCS1 = 1;    // Tad = conversion time per bit. The A/D conversion requires 11 Tad
    ADCON2bits.ADCS2 = 0;    // "010" = 32 * Tosc

    ADCON2bits.ACQT0 = 0;    // A/D Adquisition time bits    "000" = Manual adquisition
    ADCON2bits.ACQT1 = 0;
    ADCON2bits.ACQT2 = 0;
    ADCON2bits.ADFM = 0;    // Left justified     . . .ADRESH . . : . . ADRESL. . .
    //                    7 6 5 4 3 2 1 0 : 7 6 5 4 3 2 1 0
    //                    X X X X X X X X . X X . . . . . . <-Left Justified


    /* Enabling interrups */
    INTCONbits.TMR0IE = 1;    // Enables interrupts for TIMER0
    PIE1bits.TMR1IE = 1;    // Enables interrupts for TIMER1
    PIE2bits.TMR3IE = 1;    // Enables interrupts for TIMER3
    INTCONbits.PEIE = 1;    // Peripherial interrupt enabled
    INTCONbits.GIE = 1;    // Global interrupt enabled


    /* Main Loop */
    while(1)
    {

        /*    Main MENU includes the different modes that the table can show
            Switching between menus is done using external button(RE0):

                0 - Fixed light dimmed with external control
                1 - Slow square
                2 - Slow chess board
                3 - Message
                4 - Invaders
                5 - Party (Dirty)

        */
        switch(iMenu) {

        /******************************************************************/
        /* 0 - Fixed light dimmed with external control                   */
        /******************************************************************/
        case 0:
            if (FIRST == 0) {
                deleteMatrix();
                (FIRST = 1);
            }
            drawLine(1,1,1,5,pwm);    //dirty way to draw the all pixels at the same time
            drawLine(2,1,2,5,pwm);
            drawLine(3,1,3,5,pwm);
            drawLine(4,1,4,5,pwm);
            drawLine(5,1,5,5,pwm);
            break;

        /******************/
        /* 1- Slow square */
        /******************/
        case 1:
            if (SECOND == 0) {
                deleteMatrix();
                (SECOND = 1);
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,j);
                drawSquare(2,2,4,4,i);
                drawPoint(3,3,j);
                Delay10KTCYx(100);
                if(iMenu != 1) {
                    break;
                }
            }
            if(iMenu != 1) {
                break;
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,i);
                drawSquare(2,2,4,4,j);
                drawPoint(3,3,i);
                Delay10KTCYx(100);
                if(iMenu != 1) {
                    break;
                }
            }
            if(iMenu != 1) {
                break;   // It allows to break the case during the executation
            }

        /***********************/
        /* 2- Slow Chess board */
        /***********************/
        case 2:
            if (THIRD == 0) {
                deleteMatrix();
                (THIRD = 1);
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawPoint(1,5,j);
                drawLine(1,3,3,5,j);
                drawLine(1,1,5,5,j);
                drawLine(3,1,5,3,j);
                drawPoint(5,1,j);

                drawLine(1,4,2,5,i);
                drawLine(1,2,4,5,i);
                drawLine(2,1,5,4,i);
                drawLine(4,1,5,2,i);
                Delay10KTCYx(100);
                if(iMenu != 2) {
                    break;
                }
            }
            if(iMenu != 2) {
                break;
            }
            for(j = 130, i = 254; j<=254; j++, i--) {
                drawPoint(1,5,i);
                drawLine(1,3,3,5,i);
                drawLine(1,1,5,5,i);
                drawLine(3,1,5,3,i);
                drawPoint(5,1,i);

                drawLine(1,4,2,5,j);
                drawLine(1,2,4,5,j);
                drawLine(2,1,5,4,j);
                drawLine(4,1,5,2,j);
                Delay10KTCYx(100);
                if(iMenu != 2) {
                    break;
                }
            }
            if(iMenu != 2) {
                break;   // It allows to break the case during the executation
            }


        /**************/
        /* 3- Message */
        /**************/
        case 3:
            if (FOURTH == 0) {
                deleteMatrix();
                (FOURTH = 1);
            }
            //knightRider(4);
            scrollText((rom unsigned char *)&Nino[0], TRANS_RIGHT_2_LEFT);

            break;



        /***************/
        /* 4- Invaders */
        /***************/
        case 4:
            if (FIFTH == 0) {
                deleteMatrix();
                (FIFTH = 1);
            }
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[0]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[1]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[2]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[3]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for
            for(i = 1; i <= INVADERS_PAIR_REPETITIONS; i++) {
                drawFrame((rom unsigned char *)&invaders[4]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
                drawFrame((rom unsigned char *)&invaders[5]);
                Delay10KTCYx(DELAY_INVADERS);
                if(iMenu != 4) {
                    break;
                }
            }// end for

            break;


        /********************/
        /* 5- Party (Dirty) */
        /********************/
        case 5:
            if (SIXTH == 0) {
                deleteMatrix();
                drawLine(1,5,5,5,254);
            }
            for(j = 100, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,j);
                drawSquare(2,2,4,4,i);
                drawPoint(3,3,j);
                if(iMenu != 5) {
                    break;
                }
            }
            if(iMenu != 5) {
                break;
            }
            for(j = 100, i = 254; j<=254; j++, i--) {
                drawSquare(1,1,5,5,i);
                drawSquare(2,2,4,4,j);
                drawPoint(3,3,i);
                if(iMenu != 5) {
                    break;
                }
            }

            if(iMenu != 5) {
                break;    // It allows to break the case during the executation
            }

            //SOLVES A BUG: because when TMR1F is called from this case, FIFTH is
            //reset but when we come back is set one because we are in case 4 not 1,
            if (iMenu == 5)(SIXTH = 1);
            break;

        default:
            drawPoint(3,3, 180);

        }// End switch iMenu
    }// End while

    CloseTimer0();
    CloseTimer1();
}//end main
void linepath(float x1,float y1,float x2,float y2)//function tht generates points on a straight line 
{                                                 // through (x1,y1) and (x2,y2) for the shapes to move  
 static int shapeDecider=0;                       //using digital differential analyser algorithm 
 struct randomnumbers r;
 radius=7;
 r=generateRandomColor();
 float steps,dx,dy,xinc,yinc,k,x,y,ang=0;
 dx=x2-x1;
 dy=y2-y1;
 
if(abs(dx)>abs(dy))
 steps=abs(dx);
 else
 steps=abs(dy);
 xinc=(float)dx/(float)steps;
 yinc=(float)dy/(float)steps;
 x=x1;
 y=y1;
 //shapeDecider is a variable that decides which shape will appear when on the screen

 for(k=0;k<steps;k++)
 {
  glClear(GL_COLOR_BUFFER_BIT);
  if(shapeDecider%3==0)
  { 
   teamTheme();  // to display the team theme
  drawCircle(x,y,r.redc,r.greenc,r.bluec,0);// to draw circle along the line (x1,y1) to (x2,y2)
  glutSwapBuffers();
  drawSquare(-x,-y,r.reds,r.greens,r.blues,0);
  glutSwapBuffers();
  }
  else if(shapeDecider%3==1)
  {
   teamTheme();
  glutSwapBuffers();
  drawSquare(x,y,r.reds,r.greens,r.blues,0);
  glutSwapBuffers();
  drawCircle(-x,-y,r.redc,r.greenc,r.bluec,0.25);
  smallDelay();
  glutSwapBuffers();
  //smallDelay();
  }
  else
  {
  teamTheme();
  glutSwapBuffers();
  drawTriangle(x,y,1,1,1,ang);
  glutSwapBuffers();
  drawCircle(-x,-y,r.redc,r.greenc,r.bluec,0);
  glutSwapBuffers();
  smallDelay();
  
  } 
  x+=xinc;
  y+=yinc;  
  ang+=100; // this parameter is to rotate the triangle 
 } 
 if(shapeDecider<25)
 shapeDecider++;
 else
 shapeDecider=0;
}
예제 #20
0
void RCDraw::drawPerimeter ( const QColor &c, int width, int margin )
{
	QRect perim ( effWin.x(), effWin.y(), effWin.width()-margin, effWin.height() +margin );
	drawSquare(effWin.toRect(), c);
	width=width;
}
예제 #21
0
파일: rubiks.cpp 프로젝트: idea-3/Rubiks
void drawCube(int i, int j, int k) {
	GLfloat initialPoint[] = {-3,-3,3};
	GLfloat x = i*squareSize + initialPoint[0];
	GLfloat y = j*squareSize + initialPoint[1];
	GLfloat z = initialPoint[2] - k*squareSize;
	// Sisi depan
	GLfloat P1[] = {x,y,z};
	GLfloat P2[] = {x+squareSize,y,z};
	GLfloat P3[] = {x+squareSize,y+squareSize,z};
	GLfloat P4[] = {x,y+squareSize,z};
	if (k == 0) {
		drawSquare(P1,P2,P3,P4,0);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
	// Sisi belakang
	P1[2] -= squareSize;
	P2[2] -= squareSize;
	P3[2] -= squareSize;
	P4[2] -= squareSize;
	if (k == 2) {
		drawSquare(P1,P2,P3,P4,1);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
	// Sisi atas
	P1[1] += squareSize;
	P1[2] += squareSize;
	P2[1] += squareSize;
	P2[2] += squareSize;
	if (j == 2) {
		drawSquare(P1,P2,P3,P4,2);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
	// Sisi bawah
	P1[1] -= squareSize;
	P2[1] -= squareSize;
	P3[1] -= squareSize;
	P4[1] -= squareSize;
	if (j == 0) {
		drawSquare(P1,P2,P3,P4,3);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
	// Sisi kiri
	P2[1] += squareSize;
	P2[0] -= squareSize;
	P3[1] += squareSize;
	P3[0] -= squareSize;
	if (i == 0) {
		drawSquare(P1,P2,P3,P4,4);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
	// Sisi kanan
	P1[0] += squareSize;
	P2[0] += squareSize;
	P3[0] += squareSize;
	P4[0] += squareSize;
	if (i == 2) {
		drawSquare(P1,P2,P3,P4,5);
	} else {
		drawSquare(P1,P2,P3,P4,6);
	}
}
예제 #22
0
// display callback
//
// This gets called by the event handler to draw
// the scene, so this is where you need to build
// your scene -- make your changes and additions here.
// All rendering happens in this function.  For Assignment 1,
// updates to geometry should happen in the "animate" function.
void display(void)
{
    // glClearColor (red, green, blue, alpha)
    // Ignore the meaning of the 'alpha' value for now
    glClearColor(0.7f,0.7f,0.9f,1.0f);

    // OK, now clear the screen with the background colour
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);  

    // Setup the model-view transformation matrix
    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();

    ///////////////////////////////////////////////////////////
    // TODO:
    //   Modify this function draw the scene
    //   This should include function calls to pieces that
    //   apply the appropriate transformation matrice and
    //   render the individual body parts.
    ///////////////////////////////////////////////////////////

    // Draw our hinged object
    const float BODY_WIDTH = 30.0f;
    const float BODY_LENGTH = 40.0f;
    const float ARM_LENGTH = 40.0f;
    const float ARM_WIDTH = 20.0f;
    const float HEAD_WIDTH = 30.0f;
    const float HEAD_LENGTH = 30.0f;
    const float UPPER_BEAK_WIDTH = 30.0f;
    const float UPPER_BEAK_LENGTH = 10.0f;
    const float LOWER_BEAK_WIDTH = 30.0f;
    const float LOWER_BEAK_LENGTH = 15.0f;
    const float LEG_WIDTH = 20.0f;
    const float LEG_LENGTH = 40.0f;
    const float FOOT_WIDTH = 20.0f;
    const float FOOT_LENGTH = 40.0f;

    // Push the current transformation matrix on the stack
    glPushMatrix();
        
        // Draw the 'body'
 		glPushMatrix();
            // Scale the size of 'body'
            glScalef(BODY_WIDTH, BODY_LENGTH, 1.0);
            
            // Set the Colour of 'body'
			glColor3f(1.0, 0, 1.0);
			
			// Begin drawing of polygon for 'body'
			glBegin(GL_POLYGON);
				glVertex3f(-0.7f,0.5f,0.0f);//first vertex
				glVertex3f(0.7f,0.5f,0.0f);//second vertex
				glVertex3f(2.0f,-2.5f,0.0f);//third vertex
				glVertex3f(1.0f,-3.5f,0.0f);//fourth vertex
				glVertex3f(-0.7f,-3.5f,0.0f);//fifth vertex
				glVertex3f(-1.7f,-2.5f,0.0f);//sixth vertex
			glEnd();
			// End drawing of polygon for 'body'

        glPopMatrix();
        
        glPushMatrix();
			// Draw the 'head'
			// Fixed and Rotate along the hinge
			glTranslatef(0.0, BODY_LENGTH/2 - 0.2, 0.0);
			glRotatef(head_joint_rot, 0.0, 0.0, 1.0);
				
				glPushMatrix();
			
					// Scale size of 'head'
					glScalef(HEAD_LENGTH, HEAD_WIDTH, 1.0);
					
					// Set the colour of 'head'
					glColor3f(0, 0, 1.0);
					
					// Begin drawing of polygon for 'head'
					glBegin(GL_POLYGON);
						glVertex3f(-0.7f,1.0f,0.0f);//first vertex
						glVertex3f(-0.3f,1.2f,0.0f);//second vertex
						glVertex3f(0.4f,1.0f,0.0f);//third vertex
						glVertex3f(0.9f,-0.2f,0.0f);//fourth vertex
						glVertex3f(-0.9f,-0.2f,0.0f);//fifth vertex
					glEnd();
					// End drawing of polygon for 'head'
				glPopMatrix();				
				
				glPushMatrix();
					// Draw the 'joint'
					glColor3f(0.0, 0.0, 0.0);
					drawCircle(3.0);
				glPopMatrix();
				
				glPushMatrix();
					// Draw the 'eye'
					glTranslatef(-14, 23, 0.0);
					glColor3f(0.0, 0.0, 0.0);
					drawCircle(4.0);
				glPopMatrix();
				
				glPushMatrix();
					// Draw the 'upper beak'
					glTranslatef(0, HEAD_LENGTH/2, 0.0);
					
					// Scale the 'upper beak'
					glScalef(UPPER_BEAK_WIDTH, UPPER_BEAK_LENGTH, 1.0);
					
					// Set the colour of the 'upper beak'
					glColor3f(1.0, 1.0, 0);
					
						// Begin drawing of polygon for 'upper beak'
						glBegin(GL_POLYGON);
							glVertex3f(-0.7f,1.0f,0.0f);//first vertex
							glVertex3f(-0.7f,0.1f,0.0f);//second vertex
							glVertex3f(-2.0f,0.1f,0.0f);//third vertex
							glVertex3f(-2.0f,0.7f,0.0f);//fourth vertex
						glEnd();
						// End drawing of polygon for 'upper beak'
				glPopMatrix();
					
				glPushMatrix();
					// Draw the 'lower beak'
					glTranslatef(0, up_down_lower_beak, 0);
					
					glPushMatrix();
						// Draw the 'lower beak'
						glTranslatef(0, HEAD_LENGTH/2, 0.0);
						
						// Scale the 'lower beak'
						glScalef(LOWER_BEAK_WIDTH, LOWER_BEAK_LENGTH, 0.0);
						
						// Set the colour of the 'lower beak'
						glColor3f(0, 1.0, 0);
						
							// Begin drawing of polygon for 'upper beak'
							glBegin(GL_POLYGON);
								glVertex3f(-0.7f,-0.5f,0.0f);//first vertex
								glVertex3f(-0.7f,-0.9f,0.0f);//second vertex
								glVertex3f(-2.0f,-0.9f,0.0f);//third vertex
								glVertex3f(-2.0f,-0.5f,0.0f);//fourth vertex
							glEnd();
							// End drawing of polygon,upper beak
					glPopMatrix();
					
				glPopMatrix();
				
        glPopMatrix();

        glPushMatrix();
	 
			// Draw the 'arm'

			// Move the arm to the joint hinge
			glTranslatef(BODY_WIDTH/3 -5, -BODY_LENGTH/2, 0.0);

			// Rotate along the hinge
			glRotatef(joint_rot -10, 0.0, 0.0, 1.0);
			
			// Set the color of the arm
			glColor3f(1.0, 0.0, 0.0);
			
			// Scale the size of the arm
			glScalef(ARM_WIDTH, ARM_LENGTH, 1.0);
			
			glBegin(GL_POLYGON);
				glVertex3f(0.5f,0.3f,0.0f);//first vertex
				glVertex3f(0.2f,-1.2f,0.0f);//second vertex
				glVertex3f(-0.2f,-1.2f,0.0f);//third vertex
				glVertex3f(-0.5f,0.3f,0.0f);//fourth vertex
			glEnd();

			glPushMatrix();
					// Draw the 'joint'
					glColor3f(0.0, 0.0, 0.0);
					drawCircle(0.1);
			glPopMatrix();
		glPopMatrix();	
		
		glPushMatrix();
			
			// Draw the front leg
			glTranslatef(-BODY_WIDTH/3 -10, -BODY_LENGTH-80, 0.0);

			// Rotate along the hinge
			glRotatef(front_leg_joint - 10, 0.0, 0.0, 1.0);
				
			glPushMatrix();
				glScalef(LEG_WIDTH, LEG_LENGTH, 1.0);
				glTranslatef(0.0, -0.3, 0.0);
				glColor3f(1.0,1.0,0.0);
				drawSquare(1.0);
				
				glPushMatrix();
					// Draw the 'joint'
					glTranslatef(0.0, 0.3, 0.0);
					glColor3f(0.0, 0.0, 0.0);
					drawCircle(0.1);
				glPopMatrix();
			glPopMatrix();
			
			glPushMatrix();
				
				// Draw the front foot
				glTranslatef(0.0, -FOOT_LENGTH+3, 0.0);
				
				// Rotate along the hinge
				glRotatef(front_foot_joint-70, 0.0, 0.0, 1.0);
				
				glPushMatrix();
					// Set the color of the front foot
					glColor3f(1.0,0.0,0.0);
					
					// Set the scale of the front foot
					glScalef(FOOT_WIDTH, FOOT_LENGTH, 1.0);
					
					glBegin(GL_POLYGON);
						glVertex3f(0.5f,0.3f,0.0f);//first vertex
						glVertex3f(0.5f,-1.0f,0.0f);//second vertex
						glVertex3f(-0.5f,-1.0f,0.0f);//third vertex
						glVertex3f(-0.5f,0.3f,0.0f);//fourth vertex
					glEnd();
					
					glPushMatrix();
						// Draw the 'joint'
						glColor3f(0.0, 0.0, 0.0);
						drawCircle(0.1);
					glPopMatrix();
					
				glPopMatrix();
				
			glPopMatrix();
			
		glPopMatrix();
		
		glPushMatrix();
			
			// Draw the back leg
			glTranslatef(BODY_WIDTH/2+10, -BODY_LENGTH-80, 0.0);

			// Rotate along the hinge
			glRotatef(back_leg_joint+10, 0.0, 0.0, 1.0);
	
			glPushMatrix();
				glScalef(LEG_WIDTH, LEG_LENGTH, 1.0);
				glTranslatef(0.0, -0.3, 0.0);
				glColor3f(1.0,1.0,0.0);
				drawSquare(1.0);
				
				glPushMatrix();
					// Draw the 'joint'
					glTranslatef(0.0, 0.3, 0.0);
					glColor3f(0.0, 0.0, 0.0);
					drawCircle(0.1);
				glPopMatrix();
				
			glPopMatrix();
			
			glPushMatrix();
				// Draw the 'back foot'
				glTranslatef(-1.5, -LEG_LENGTH+8, 1.0);
			
				
				// Rotate along the hinge
				glRotatef(back_foot_joint-60, 0.0, 0.0, 1.0);
				
				glPushMatrix();
					// Set the color of the 'back foot'
					glColor3f(1.0,0.0,0.0);
					
					// Set the scale of the 'back foot'
					glScalef(FOOT_WIDTH, FOOT_LENGTH, 1.0);
					
					glBegin(GL_POLYGON);
						glVertex3f(0.5f,0.3f,0.0f);//first vertex
						glVertex3f(0.5f,-1.0f,0.0f);//second vertex
						glVertex3f(-0.5f,-1.0f,0.0f);//third vertex
						glVertex3f(-0.5f,0.3f,0.0f);//fourth vertex
					glEnd();
					
					glPushMatrix();
						// Draw the 'joint'
						glColor3f(0.0, 0.0, 0.0);
						drawCircle(0.1);
					glPopMatrix();
					
				glPopMatrix();
				
			glPopMatrix();
			
			
		glPopMatrix();
			

    // Retrieve the previous state of the transformation stack
    glPopMatrix();


    // Execute any GL functions that are in the queue just to be safe
    glFlush();

    // Now, show the frame buffer that we just drew into.
    // (this prevents flickering).
    glutSwapBuffers();
}
예제 #23
0
파일: drawings.cpp 프로젝트: reafle/kgps1
void drawBresenhamLine(void) {
    glPushMatrix();

    glColor3f(1.0f, 0.7f, 0.0f);
    glScalef((GLfloat) 2 / MATRIX_SIZE, (GLfloat) 2 / MATRIX_SIZE, 0);

    float m = linex2 != linex1 ? (liney2 - liney1) / (linex2 - linex1) : 0;

    bool first_octant = linex1 < linex2 && m >= 0 && m <= 1;
    bool second_octant = liney1 < liney2 && m > 1;
    bool third_octant = liney1 < liney2 && m < -1;
    bool fourth_octant = linex2 < linex1 && m >= -1 && m <= 0;
    bool fifth_octant = linex2 < linex1 && m > 0 && m <= 1;
    bool sixth_octant = liney2 < liney1 && m > 1;
    bool seventh_octant = liney2 < liney1 && m < -1;
    bool eight_octant = linex1 < linex2 && m < 0 && m >= -1;

    int x1 = linex1, x2 = linex2;
    int y1 = liney1, y2 = liney2;

    if (fifth_octant || sixth_octant || third_octant || fourth_octant) {
        x1 = linex2;
        x2 = linex1;

        y1 = liney2;
        y2 = liney1;
    }

    int w = x2 - x1;
    int h = y2 - y1;

    int dx1 = 0, dy1 = 0, dx2 = 0, dy2 = 0;
    if (w < 0) dx1 = -1;
    else if (w > 0) dx1 = 1;
    if (h < 0) dy1 = -1;
    else if (h > 0) dy1 = 1;
    if (w < 0) dx2 = -1;
    else if (w > 0) dx2 = 1;

    int longest = abs(w);
    int shortest = abs(h);
    if (!(longest > shortest)) {
        longest = abs(h);
        shortest = abs(w);
        if (h < 0) dy2 = -1;
        else if (h > 0) dy2 = 1;
        dx2 = 0;
    }

    int numerator = longest >> 1;
    int x = x1, y = y1;
    
    for (int i = 0; i <= longest; i++) {

        glPushMatrix();

        drawSquare(x, y);
        numerator += shortest;
        if (!(numerator < longest)) {
            numerator -= longest;
            x += dx1;
            y += dy1;
        } else {
            x += dx2;
            y += dy2;
        }

        glPopMatrix();
    }

    glPopMatrix();
}
예제 #24
0
void drawCube(double xSize, double ySize, double zSize
					, double topColor[3], double bottomColor[3]
					, unsigned int topTexture, unsigned int bottomTexture, unsigned int sideTexture
					, bool enableTextures)
{  	
   ErrCheck("Before drawCube");
   //  Save transformation
   glPushMatrix();
   glTranslated(0, -ySize/2.0, 0); //Moves ground below orgin

   glScaled(xSize/2.0, ySize/2.0, zSize/2.0);
   //  Cube
   
   //Front 
  	glPushMatrix(); 
  		glRotated(0,0,0,0);
  		glTranslated(-1,-1, 1); 
  		glScaled(2,2,2);
  		ErrCheck("In DrawCube Front, before drawSquare");  
  		drawSquare(bottomColor,topColor,topColor,bottomColor,sideTexture, 1); 
  	glPopMatrix(); 	
  	//Back
  	glPushMatrix(); 
  		glRotated(180,0,1,0);
  		glTranslated(-1,-1,1); 
  		glScaled(2,2,2); 
  		ErrCheck("In DrawCube Back, before drawSquare");  
  		drawSquare(bottomColor,topColor,topColor,bottomColor,sideTexture, enableTextures); 
  	glPopMatrix(); 
  	//Right
  	glPushMatrix(); 
  		glRotated(90,0,1,0);
  		glTranslated(-1,-1,1); 
  		glScaled(2,2,2);
  		ErrCheck("In DrawCube Right, before drawSquare");   
  		drawSquare(bottomColor,topColor,topColor,bottomColor,sideTexture, enableTextures); 
  	glPopMatrix(); 
  	//Left
  	glPushMatrix(); 
  		glRotated(270,0,1,0);
  		glTranslated(-1,-1,1); 
  		glScaled(2,2,2);
  		ErrCheck("In DrawCube Left, before drawSquare");   
  		drawSquare(bottomColor,topColor,topColor,bottomColor,sideTexture, enableTextures); 
  	glPopMatrix(); 
  	
  	//Top
  	glPushMatrix(); 
  		glRotated(90,1,0,0);
  		glTranslated(-1,-1,-1); 
  		glScaled(2,2,2); 
  		ErrCheck("In DrawCube Top, before drawSquare");  
  		drawSquare(topColor,topColor,topColor,topColor,topTexture, enableTextures); 
  	glPopMatrix(); 
  	
  	//Bottom
  	glPushMatrix(); 
  		glRotated(90,1,0,0);
  		glTranslated(-1,-1,1); 
  		glScaled(2,2,2); 
  		ErrCheck("In DrawCube Bottom, before drawSquare");  
  		drawSquare(bottomColor,bottomColor,bottomColor,bottomColor,bottomTexture, enableTextures); 
  	glPopMatrix(); 
  ErrCheck("In drawCube, before glDisable"); 
  //  Undo transofrmations
  glPopMatrix();
  if(enableTextures)
	{
		glDisable(GL_TEXTURE_2D);
	}
	ErrCheck("after drawCube");
}
예제 #25
0
void GL::drawMapCell(int x, int y, int z)
{
	glLoadIdentity();
	glTranslated(x, y, z);
	drawSquare();
}
예제 #26
0
파일: render.c 프로젝트: tiagosimao/tetris
void drawColoredPiece(int map[4][4][2], int x, int y,int rot, float r, float g, float b){
	drawSquare(r,g,b,x+map[rot][0][0], y+map[rot][0][1]);
	drawSquare(r,g,b,x+map[rot][1][0], y+map[rot][1][1]);
	drawSquare(r,g,b,x+map[rot][2][0], y+map[rot][2][1]);
	drawSquare(r,g,b,x+map[rot][3][0], y+map[rot][3][1]);
}