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...

[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.

Video Conferencing Project in Java Source Code

My video conferencing project was completed as 300 project for 3rd year.It is not totally completed. There is some bug in here.To solve these bugs and to help other students this project is open.It is first try to make a project open source in this way so it can be modified.Any kind of question against this project will be answered. As this project was created in 3rd year 1st semester and now i nearly completed my BSc. so there will be little description about this.I will try to describe every class and function later when i get the chance.   For more details and how to build and run go to this link   in github.com . Latest code and binary release : VideoConference-v1.1 Older code and binary release : VideoConference-v1.0 Fix: 1. When in Video chat the Text chat option hanged for good. ################################################################################# FEATURE #############################################################################...