Skip to main content

Object Transformation source code in c++ with Glut/opengl

In this algorithm one rectangle has been transformed 30-degree angle and it also
move from the current object by x 100 and y 100. Here the white rectangle is input
and red one is output. 
 
 
 
 
INPUT:
 
 
 
 
 
 
OUTPUT:
 
 
 
#include <windows.h>

#include <GL/glut.h>

#include <stdlib.h>

#include <iostream>

#include <string>

#include <string>

#include <ctype.h>

#include <math.h>

#include <stdio.h>

#include <map>

#include <vector>

using namespace std;



int trans_x,trans_y;

#define pi 2.0*acos(0)









long x_min,x_max,y_min,y_max;





vector <int>x_cor;

vector <int>y_cor;







long draw_line(long x_start , long y_start , long x_end, long y_end)

{



    glBegin(GL_LINES);

    glVertex2f(x_start,y_start); //start points

    glVertex2f(x_end,y_end); // end points

    glEnd();



    return 0;



}





// draw point or pixel by sending cordinate

long  draw_point(long X , long Y)

{



    glBegin(GL_POINTS);

    glVertex2f(X,Y);

    glEnd();



    return 0;



}











int translate(int org_x, int org_y)

{

    int i ,j;

    for(i =0;i<x_cor.size(); ++i)

    {

        x_cor[i] -= org_x;

        y_cor[i] -= org_y;

    }





    for(i=0;i<x_cor.size();++i)

    {

        //draw_point(x_cor[i],y_cor[i]);

    }





    return 0;

}



int scale(int s_x,int s_y)

{

    int i ,j;



    for(i=0;i<x_cor.size();++i)

    {

        x_cor[i] *= s_x;

        y_cor[i] *= s_y;

    }





    return 0;

}



int anti_translate(int org_x , int org_y)

{

    glColor3d(1,0,0);

    int i,j;



    for(i=0;i<x_cor.size();++i)

    {

        x_cor[i] += org_x;

        y_cor[i] += org_y;

    }





    for(i=1;i<x_cor.size();++i)

    {

        draw_line(x_cor[i-1],y_cor[i-1],x_cor[i],y_cor[i]);



    }



    draw_line(x_cor[0],y_cor[0],x_cor[x_cor.size()-1],y_cor[x_cor.size()-1]);



    return 0;

}





int rotate(int angle)

{

    glColor3d(0,1,0);

    int i , j;



    for(i=0;i<x_cor.size();++i)

    {

        double angle_rad = pi / 180.0;

        x_cor[i] = x_cor[i] * cos(angle_rad * angle) - y_cor[i]*sin(angle_rad * angle);

        y_cor[i] = x_cor[i] * sin(angle_rad * angle) + y_cor[i]*cos(angle_rad * angle);

     //   draw_point(x_cor[i] ,y_cor[i]);

    }



    return 0;

}







static void display(void)

{



    int i;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    glColor3d(1,1,1); // set pixel color;



     for(i=1;i<x_cor.size();i++){

        draw_line(x_cor[i-1],y_cor[i-1],x_cor[i],y_cor[i]);

    }





    draw_line(x_cor[0],y_cor[0],x_cor[x_cor.size()-1],y_cor[x_cor.size()-1]);



    // for scale the object by any cordinate //

/*



    translate(trans_x,trans_y);



    int s_x = 2 ,s_y = 2;

    scale(s_x,s_y);



    anti_translate(trans_x,trans_y);

*/





    // for rotate the object by any cordinate //





    translate(trans_x,trans_y);



    int angle = 30;

    rotate(angle);



    anti_translate(trans_x,trans_y);







    //rotate_point(30,1,2);







    glutSwapBuffers();

}





/*





4

300 300

350 300

350 350

300 350





3

100 100

150 100

125 150







*/



/* Program entry point */



int main(int argc, char *argv[])

{

    int i,x,y,n;

    glutInit(&argc, argv);

    glutInitWindowSize(640,480);

    glutInitWindowPosition(10,10);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);





    cin>>n;

    for(i=0;i<n;i++){

        cin>>x>>y;

        x_cor.push_back(x);

        y_cor.push_back(y);

    }





    cin>>trans_x>>trans_y;





    glutCreateWindow("TRANSFORMATION");



    glOrtho(0,640,0,480,0,1);

    glutDisplayFunc(display);





    glutMainLoop();

    return EXIT_SUCCESS;

}


Comments

Popular posts from this blog

UDP server client in c

Server #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <stdlib.h> int main() {         int sock;         int addr_len, bytes_read;         char recv_data[1024],send_data[1024];         struct sockaddr_in server_addr , client_addr;         if ((sock = socket(AF_INET, SOCK_DGRAM, 0)) == -1) {             perror("Socket");             exit(1);         }         server_addr.sin_family = AF_INET;         server_addr.sin...

My favourite writer Humayun Ahmed

There is none who can replace him.At least the standard which he create in is life time in the running literature it never be replaceable.The new generation which is all the time busy in playing PC games,chatting ,bands etc. only his writing makes them to take a glance on the literature.For example Himu and Misir ali all the time keep them on track by anti-logic and logic.They also have show-down on the novel.I myself read all of the books of Himu and Misir ali and wait for the new one to come every year.Now I have to wait for life time. Except books he makes our dirty film industry pure by his heart warming ,well versed film.Following him many new producer try to make well and good film (not the dirty one) .He also contribute our drama by his dashing drama's. In writing except romance ,logic ,anti-logic ,he also write many science fiction.His brother Sir Dr. Md. Zafar Iqbal is the man who started science fiction in bangla. The list of books: Selected novels • Lilaboti (2...

[ASTERIK] configure: error: *** uuid support not found (this typically means the uuid development package is missing)

ISSUE: Build error on Asterik , when you want test webrtc feature :) checking for uuid_generate_random in -luuid... no checking for uuid_generate_random in -le2fs-uuid... no checking for uuid_generate_random... no configure: error: *** uuid support not found (this typically means the uuid development package is missing) Fix: This issue arises due to missing of UUID generator specified by rfc4122 . +Linux sudo apt-get install uuid-dev  @Unix yum -y install libuuid-devel Asterik comes with lots of helpful script available on - asterisk/contrib/scripts/ folder of your ASTERIK source. So just use the following command on UNIX console to run the asterik pre-requisite script. contrib/scripts/install_prereq install And you are done! configuring. Now -- Make Asterik.