All tutorials in one place.

Friday, July 15, 2016

7. Transformimet gjeometrike, zhvendosja

Deri tani kemi pare vetem ndertimin e objekteve te ndryshme, ndersa ne shembujt ne vazhdim do te shohim transformimin e tyre, zhvendosjen, zmadhimin ose zvogelimin dhe animacionin per te dizenjuar skenen tone 2D. Veprimet si zhvendosja, rrotullimi dhe shfromimi quhen transformime gjeometrike.
 Ushtrim: Ndertoni nje drejtkendesh dhe zhvendoseni ate me 100 njesi ne boshtin x

#include<gl/glut.h>
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  glTranslatef(100,0.0,0.0);
    glRectf(10.,0.,20.,10.);
  glFlush();
}
void init()
{
  glClearColor(1.0,0.0,0.0,1.0);
  glViewport(0,0,320,240);
  gluOrtho2D(0.0,160.0,0.0,120.0);
}
int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(320,240);
  glutCreateWindow("Zhvendosje dhe Rrotullim");
  init();
  glutDisplayFunc(Display);
  glutMainLoop();
}
Ushtrim: Ndertoni nje program qe nderton nje drejtkendesh dhe e zhvendos ate 5 here me 10 njesi ne boshtin x
#include<gl/glut.h>
void Display()
{
  glClear(GL_COLOR_BUFFER_BIT);
  int x=10;
  for(int i=0;i<5;i++)
  {
  glTranslatef(3*x,0,0);
  glRectf(10.,0.,20.,10.);
    }
    glFlush();
}
void init()
{
  glClearColor(1.0,0.0,0.0,1.0);
  glViewport(0,0,320,240);
  gluOrtho2D(0.0,160.0,0.0,120.0);
}
int main(int argc, char* argv[])
{
  glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);
  glutInitWindowSize(320,240);
  glutCreateWindow("Test");
  init();
  glutDisplayFunc(Display);
  glutMainLoop();
}

Share:

0 comments:

Post a Comment

Popular Posts

Categories

Tutorials House. Powered by Blogger.

Labels