3D to 2D object Transform source code in c++ with OpenGL

Here is the implementation of 3d to 2d conversion algorithm in c.

INPUT:




OUTPUT:




SOURCE CODE:

#include <windows.h>

#include <GL/glut.h>

#include <stdlib.h>

#include <stdio.h>

#include <iostream>

#include <math.h>



using namespace std;



int x,y,z,sx[100],sy[100],sz[100],ex,ey,ez;



void drawLine(int x1, int y1,int x2,int y2)

{

    glBegin(GL_LINES);



    glVertex2i(x1,y1);

    glVertex2i(x2,y2);



    glEnd();

}







static void display(void)

{



    int i,dis,xx[100],yy[100],px,py;

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);





    glColor3d(0,255,255);







   /* drawLine(100,200,200,100);

    drawLine(200,100,300,200);

    drawLine(300,200,200,300);

    drawLine(100,200,200,300);*/

    //glReadPixels(200 , 100 , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , boundary_color);



    dis = z;





  /*  xx = dis*sx/(dis + sz); yy = dis*sy/(dis + sz);

    px = dis*ex/(dis + sz); py = dis*ey/(dis + sz);

    cout << dis << " "<<xx<<","<<yy<<"||"<<px<<","<<py<<endl;

    */



    for(i=1;i<=8;i++)

    {

        xx[i] = dis*sx[i]/(dis + sz[i]);

        yy[i] = dis*sy[i]/(dis + sz[i]);

        cout << xx[i] <<" "<<yy[i]<<endl;

    }



    glColor3d(255,0,0);

    drawLine(xx[1],yy[1],xx[2],yy[2]);

    drawLine(xx[1],yy[1],xx[4],yy[4]);

    drawLine(xx[1],yy[1],xx[6],yy[6]);



    drawLine(xx[2],yy[2],xx[3],yy[3]);

    drawLine(xx[2],yy[2],xx[7],yy[7]);



    drawLine(xx[3],yy[3],xx[4],yy[4]);

    drawLine(xx[3],yy[3],xx[8],yy[8]);



    drawLine(xx[4],yy[4],xx[5],yy[5]);



    drawLine(xx[5],yy[5],xx[6],yy[6]);

    drawLine(xx[5],yy[5],xx[8],yy[8]);



    drawLine(xx[6],yy[6],xx[7],yy[7]);



    drawLine(xx[7],yy[7],xx[8],yy[8]);









 //   drawLine(xx,yy,px,py);





    /*drawPoint(200,200);

    glReadPixels(200 , 100 , 1 , 1 , GL_RGB , GL_UNSIGNED_BYTE , fill_color);*/



    //boundaryFill(200,200);



    glutSwapBuffers();

}



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

{

    int i;



    glutInit(&argc, argv);

    glutInitWindowSize(640,600);

    glutInitWindowPosition(10,10);

    glutInitDisplayMode(GLUT_RGB | GLUT_DOUBLE | GLUT_DEPTH);



    cout << "D :"<<endl;

    cin >> z;

    //cout << "Give 2 End point of 3D-line :"<<endl;

    //cin >> sx >> sy >> sz >> ex >> ey >> ez;

    cout << "Input For 3D object"<<endl;

    for(i=1;i<=8;i++)

    {

        cin >> sx[i] >> sy[i] >> sz[i];

        sx[i] *= 250;

        sy[i] *= 250;

        sz[i] *= 250;

        sx[i] += 100;

        sy[i] += 100;

        sz[i] += 100;



    }

    glutCreateWindow("3D to 2D");





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



    glutDisplayFunc(display);





    glutMainLoop();



    return EXIT_SUCCESS;

}





/*

50



0 0 0

1 0 0

1 1 0

0 1 0

0 1 1

0 0 1

1 0 1

1 1 1





*/

Client Server MineSweeper source code in Java with remote method invocation

First Create a project with these 3 class.
1.game.java
2.RmiClient.java
3.ReceiveMessageInterface.java


/**
 * @(#)game.java

 *

 *

 * @author sharma

 * @version 1.00 2011/5/5

 */

 import java.rmi.*;

import java.awt.BorderLayout;

import java.awt.Color;

import javax.swing.JFrame;

import javax.swing.JTabbedPane;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.SwingConstants;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.Transparency;

import javax.swing.event.*;

import java.sql.*;

import java.util.*;

import java.net.URL;

import javax.imageio.ImageIO;

import java.lang.*;





import java.io.*;

import javax.swing.BoxLayout;



public class game extends JFrame {

    

    RmiClient rm;

    JLabel name = new JLabel();

    JPanel jPanel1 = new JPanel();

    JLabel jLabel4 = new JLabel();

    JLabel jLabel5 = new JLabel();

    JLabel jLabel6 = new JLabel();

    JLabel jLabel7 = new JLabel();

    JLabel jLabel8 = new JLabel();

    JTextField takip = new JTextField();

    JTextField scor = new JTextField();

    

    JButton sig = new JButton();

    JButton close = new JButton();

//    JButton l[] = new JButton(100);

    JButton l1 = new JButton();

    JButton l2 = new JButton();

    JButton l3 = new JButton();

    JButton l4 = new JButton();

    JButton l5 = new JButton();

    JButton l6 = new JButton();

    JButton l7 = new JButton();

    JButton l8 = new JButton();

    JButton l9 = new JButton();

    JButton l10 = new JButton();

    JButton l11 = new JButton();

    JButton l12 = new JButton();

    JButton l13 = new JButton();

    JButton l14 = new JButton();

    JButton l15 = new JButton();

    JButton l16 = new JButton();

    JButton l17 = new JButton();

    JButton l18 = new JButton();

    JButton l19 = new JButton();

    JButton l20 = new JButton();

    JButton l21 = new JButton();

    JButton l22 = new JButton();

    JButton l23 = new JButton();

    JButton l24 = new JButton();

    JButton l25 = new JButton();

    JButton l26 = new JButton();

    JButton l27 = new JButton();

    JButton l28 = new JButton();

    JButton l29 = new JButton();

    JButton l30 = new JButton();

    JButton l31 = new JButton();

    JButton l32 = new JButton();

    int real = 0;

    public game() {

        

        setTitle("Game");

        setSize(600,453);

        setLocation(220,100);

        

        setUndecorated(true);

        getRootPane().setWindowDecorationStyle(JRootPane.FRAME);

        setVisible(true);

        jbinit();

        

    }

    

    void jbinit()

    {

         this.setResizable(false);

         this.getContentPane().setLayout(null);

         

         takip.setText("");

         takip.setFont(new java.awt.Font("Dialog", 1, 14));

         takip.setBounds(new Rectangle(8, 18,184, 21));

        

         sig.setText("Start");

         sig.setBounds(new Rectangle(258, 18,106, 21));

         sig.addActionListener(new st_actionAdapter(this)); 

         

         close.setText("Reset");

         close.setBounds(new Rectangle(408, 18,106, 21));

         close.addActionListener(new cl_actionAdapter(this)); 

         

         name.setText("Score :");

         name.setFont(new java.awt.Font("Dialog", 1, 14));

         name.setBounds(new Rectangle(258, 68,184, 21));

         

         scor.setText("");

         scor.setFont(new java.awt.Font("Dialog", 1, 14));

         scor.setBounds(new Rectangle(320, 68,184, 21));

         

         l1.setText("a");

         l1.setFont(new java.awt.Font("Dialog", 1, 12));

         l1.setBounds(new Rectangle(8,48,50,28));

         l1.addActionListener(new but_actionAdapter(this));

         

         l2.setText("b");

         l2.setFont(new java.awt.Font("Dialog", 1, 12));

         l2.setBounds(new Rectangle(58,48,50,28));

         l2.addActionListener(new but_actionAdapter(this));

         

         l3.setText("c");

         l3.setFont(new java.awt.Font("Dialog", 1, 12));

         l3.setBounds(new Rectangle(108,48,50,28));

         l3.addActionListener(new but_actionAdapter(this));

         

         l4.setText("d");

         l4.setFont(new java.awt.Font("Dialog", 1, 12));

         l4.setBounds(new Rectangle(158,48,50,28));

         l4.addActionListener(new but_actionAdapter(this));

         

         l5.setText("e");

         l5.setFont(new java.awt.Font("Dialog", 1, 12));

         l5.setBounds(new Rectangle(8,78,50,28));

         l5.addActionListener(new but_actionAdapter(this));

  

         l6.setText("f");

         l6.setFont(new java.awt.Font("Dialog", 1, 12));

         l6.setBounds(new Rectangle(58,78,50,28)); 

         l6.addActionListener(new but_actionAdapter(this));

         

         l7.setText("g");

         l7.setFont(new java.awt.Font("Dialog", 1, 12));

         l7.setBounds(new Rectangle(108,78,50,28));

         l7.addActionListener(new but_actionAdapter(this));

         

         l8.setText("h");

         l8.setFont(new java.awt.Font("Dialog", 1, 12));

         l8.setBounds(new Rectangle(158,78,50,28));            

         l8.addActionListener(new but_actionAdapter(this));

         

         l9.setText("i");

         l9.setFont(new java.awt.Font("Dialog", 1, 12));

         l9.setBounds(new Rectangle(8,108,50,28));

         l9.addActionListener(new but_actionAdapter(this));

         

         l10.setText("j");

         l10.setFont(new java.awt.Font("Dialog", 1, 12));

         l10.setBounds(new Rectangle(58,108,50,28));

         l10.addActionListener(new but_actionAdapter(this));

         

         l11.setText("k");

         l11.setFont(new java.awt.Font("Dialog", 1, 12));

         l11.setBounds(new Rectangle(108,108,50,28));

         l11.addActionListener(new but_actionAdapter(this));

         

         l12.setText("l");

         l12.setFont(new java.awt.Font("Dialog", 1, 12));

         l12.setBounds(new Rectangle(158,108,50,28));

         l12.addActionListener(new but_actionAdapter(this));

         

         l13.setText("m");

         l13.setFont(new java.awt.Font("Dialog", 1, 12));

         l13.setBounds(new Rectangle(8,138,50,28));

         l13.addActionListener(new but_actionAdapter(this));

         

         l14.setText("n");

         l14.setFont(new java.awt.Font("Dialog", 1, 12));

         l14.setBounds(new Rectangle(58,138,50,28));

         l14.addActionListener(new but_actionAdapter(this));

         

         l15.setText("o");

         l15.setFont(new java.awt.Font("Dialog", 1, 12));

         l15.setBounds(new Rectangle(108,138,50,28));

         l15.addActionListener(new but_actionAdapter(this));

         

         l16.setText("p");

         l16.setFont(new java.awt.Font("Dialog", 1, 12));

         l16.setBounds(new Rectangle(158,138,50,28));

         l16.addActionListener(new but_actionAdapter(this));

         

         l17.setText("q");

         l17.setFont(new java.awt.Font("Dialog", 1, 12));

         l17.setBounds(new Rectangle(8,168,50,28));

         l17.addActionListener(new but_actionAdapter(this));

         

         l18.setText("r");

         l18.setFont(new java.awt.Font("Dialog", 1, 12));

         l18.setBounds(new Rectangle(58,168,50,28));

         l18.addActionListener(new but_actionAdapter(this));

         

         l19.setText("s");

         l19.setFont(new java.awt.Font("Dialog", 1, 12));

         l19.setBounds(new Rectangle(108,168,50,28));

         l19.addActionListener(new but_actionAdapter(this));

         

         l20.setText("t");

         l20.setFont(new java.awt.Font("Dialog", 1, 12));

         l20.setBounds(new Rectangle(158,168,50,28));

         l20.addActionListener(new but_actionAdapter(this));

         

         l21.setText("u");

         l21.setFont(new java.awt.Font("Dialog", 1, 12));

         l21.setBounds(new Rectangle(8,198,50,28));

           l21.addActionListener(new but_actionAdapter(this));

          

         l22.setText("v");

         l22.setFont(new java.awt.Font("Dialog", 1, 12));

         l22.setBounds(new Rectangle(58,198,50,28)); 

         l22.addActionListener(new but_actionAdapter(this));

         

         l23.setText("w");

         l23.setFont(new java.awt.Font("Dialog", 1, 12));

         l23.setBounds(new Rectangle(108,198,50,28));

         l23.addActionListener(new but_actionAdapter(this));

         

         l24.setText("x");

         l24.setFont(new java.awt.Font("Dialog", 1, 12));

         l24.setBounds(new Rectangle(158,198,50,28));            

         l24.addActionListener(new but_actionAdapter(this));

         

         l25.setText("y");

         l25.setFont(new java.awt.Font("Dialog", 1, 12));

         l25.setBounds(new Rectangle(8,228,50,28));

         l25.addActionListener(new but_actionAdapter(this));

         

         l26.setText("z");

         l26.setFont(new java.awt.Font("Dialog", 1, 12));

         l26.setBounds(new Rectangle(58,228,50,28));

         l26.addActionListener(new but_actionAdapter(this));

         

         l27.setText("A");

         l27.setFont(new java.awt.Font("Dialog", 1, 12));

         l27.setBounds(new Rectangle(108,228,50,28));

         l27.addActionListener(new but_actionAdapter(this));

         

         l28.setText("B");

         l28.setFont(new java.awt.Font("Dialog", 1, 12));

         l28.setBounds(new Rectangle(158,228,50,28));

         l28.addActionListener(new but_actionAdapter(this));

         

         l29.setText("C");

         l29.setFont(new java.awt.Font("Dialog", 1, 12));

         l29.setBounds(new Rectangle(8,258,50,28));

         l29.addActionListener(new but_actionAdapter(this));

         

         l30.setText("D");

         l30.setFont(new java.awt.Font("Dialog", 1, 12));

         l30.setBounds(new Rectangle(58,258,50,28));

         l30.addActionListener(new but_actionAdapter(this));

         

         l31.setText("E");

         l31.setFont(new java.awt.Font("Dialog", 1, 12));

         l31.setBounds(new Rectangle(108,258,50,28));

         l31.addActionListener(new but_actionAdapter(this));

         

         l32.setText("F");

         l32.setFont(new java.awt.Font("Dialog", 1, 12));

         l32.setBounds(new Rectangle(158,258,50,28));

         l32.addActionListener(new but_actionAdapter(this));

         

         this.getContentPane().add(scor,null);

         this.getContentPane().add(name,null);

         this.getContentPane().add(takip,null);

         this.getContentPane().add(sig,null);

         this.getContentPane().add(close,null);

         this.getContentPane().add(l1,null);

         this.getContentPane().add(l2,null);

         this.getContentPane().add(l3,null);

         this.getContentPane().add(l4,null);

         this.getContentPane().add(l5,null);

         this.getContentPane().add(l6,null);

         this.getContentPane().add(l7,null);

         this.getContentPane().add(l8,null);

         this.getContentPane().add(l9,null);

         this.getContentPane().add(l10,null);

         this.getContentPane().add(l11,null);

         this.getContentPane().add(l12,null);

         this.getContentPane().add(l13,null);

         this.getContentPane().add(l14,null);

         this.getContentPane().add(l15,null);

         this.getContentPane().add(l16,null);

         this.getContentPane().add(l17,null);

         this.getContentPane().add(l18,null);

         this.getContentPane().add(l19,null);

         this.getContentPane().add(l20,null);

         this.getContentPane().add(l21,null);

         this.getContentPane().add(l22,null);

         this.getContentPane().add(l23,null);

         this.getContentPane().add(l24,null);

         this.getContentPane().add(l25,null);

         this.getContentPane().add(l26,null);

         this.getContentPane().add(l27,null);

         this.getContentPane().add(l28,null);

         this.getContentPane().add(l29,null);

         this.getContentPane().add(l30,null);

         this.getContentPane().add(l31,null);

         this.getContentPane().add(l32,null);

             

    }

    

    public static void main (String[] args) {

        

        game gm = new game();

}



void clik_action(ActionEvent e)

{

    System.out.println(""+e.getActionCommand());

    //rm.all(e.getActionCommand());

  

    String pc="",rp="",mp="",gp="";

    int i,j=0,l=0;

    char c;

    mp += e.getActionCommand();

    

    for(i=97;i<=122;i++)

    {

       rp = "";

       c = (char)i;

       rp += c;

       l = i - 96;

       if(rp.equals(mp))

       {

           j = 1;

           System.out.println(l+" "+rp);

           break;

       }

       

    }

    

    if(j != 1)

    for(i=65;i<=70;i++)

    {

       rp = "";

       c = (char)i;

       rp += c;

       l = i - 38;

       if(rp.equals(mp))

       {

           System.out.println(l+" "+rp);

           break;

       }

       

    }

    

        

    pc = Integer.toString(l);

    gp = rm.all(pc);

    

    if(gp.equals(":)"))

    {

    

        l1.setText(rm.all("1"));l2.setText(rm.all("2"));l3.setText(rm.all("3"));l4.setText(rm.all("4"));

        l5.setText(rm.all("5"));l6.setText(rm.all("6"));l7.setText(rm.all("7"));l8.setText(rm.all("8"));

        l9.setText(rm.all("9"));l10.setText(rm.all("10"));l11.setText(rm.all("11"));l12.setText(rm.all("12"));

        l13.setText(rm.all("13"));l14.setText(rm.all("14"));l15.setText(rm.all("15"));l16.setText(rm.all("16"));

        l17.setText(rm.all("17"));l18.setText(rm.all("18"));l19.setText(rm.all("19"));l20.setText(rm.all("20"));

        l21.setText(rm.all("21"));l22.setText(rm.all("22"));l23.setText(rm.all("23"));l24.setText(rm.all("24"));

        l25.setText(rm.all("25"));l26.setText(rm.all("26"));l27.setText(rm.all("27"));l28.setText(rm.all("28"));

        l29.setText(rm.all("29"));l30.setText(rm.all("30"));l31.setText(rm.all("31"));l32.setText(rm.all("32"));

    }

    if(l == 1){l1.setBackground(Color.cyan);l1.setText(gp);}if(l == 17){l17.setText(gp);setBackground(Color.cyan);}

    if(l == 2){l2.setBackground(Color.cyan);l2.setText(gp);}if(l == 18){l18.setBackground(Color.cyan);l18.setText(gp);}

    if(l == 3){l3.setBackground(Color.cyan);l3.setText(gp);}if(l == 19){l19.setText(gp);l19.setBackground(Color.cyan);}

    if(l == 4){l4.setBackground(Color.cyan);l4.setText(gp);}if(l == 20){l20.setBackground(Color.cyan);l20.setText(gp);}

    if(l == 5){l5.setBackground(Color.cyan);l5.setText(gp);}if(l == 21){l21.setBackground(Color.cyan);l21.setText(gp);}

    if(l == 6)l6.setText(gp);if(l == 22)l22.setText(gp);

    if(l == 7)l7.setText(gp);if(l == 23)l23.setText(gp);

    if(l == 8)l8.setText(gp);if(l == 24)l24.setText(gp);

    if(l == 9)l9.setText(gp);if(l == 25)l25.setText(gp);

    if(l == 10)l10.setText(gp);if(l == 26)l26.setText(gp);

    if(l == 11)l11.setText(gp);if(l == 27)l27.setText(gp);

    if(l == 12)l12.setText(gp);if(l == 28)l28.setText(gp);

    if(l == 13)l13.setText(gp);if(l == 29)l29.setText(gp);

    if(l == 14)l14.setText(gp);if(l == 30)l30.setText(gp);

    if(l == 15)l15.setText(gp);if(l == 31)l31.setText(gp);

    if(l == 16)l16.setText(gp);if(l == 32)l32.setText(gp);

    

    if(!gp.equals(":)"))

    {

     int m = Integer.parseInt(gp); 

     String iq ="";

     real += m;

     iq = Integer.toString(real);

     scor.setText(iq);

    }

    if(gp.equals(":)"))

    {

        for(i=1;i<=32;i++)

        {

        //    if()

        }

        scor.setText("You Lose!");

    }

   

    

    //System.out.println(""+sp);

    

}

    

void st_action(ActionEvent e)

{

   String st = "";

   st = takip.getText();

   System.out.println(""+st);    

    rm = new RmiClient(st);

}   



void cl_action(ActionEvent e)

{

    

    try

    {

    rm.rmiServer.receiveMessage("Connect");

    }

    catch(RemoteException ee)

    {

    }

    

    real = 0;

    l1.setText("a");l17.setText("q");

    l2.setText("b");l18.setText("r");

    l3.setText("c");l19.setText("s");

    l4.setText("d");l20.setText("t");

    l5.setText("e");l21.setText("u");

    l6.setText("f");l22.setText("v");

    l7.setText("g");l23.setText("w");

    l8.setText("h");l24.setText("x");

    l9.setText("i");l25.setText("y");

    l10.setText("j");l26.setText("z");

    l11.setText("k");l27.setText("A");

    l12.setText("l");l28.setText("B");

    l13.setText("m");l29.setText("C");

    l14.setText("n");l30.setText("D");

    l15.setText("o");l31.setText("E");

    l16.setText("p");l32.setText("F");

    scor.setText("");

}    

    

}





class but_actionAdapter implements java.awt.event.ActionListener {

  game adaptee;



  but_actionAdapter(game adaptee) {

    this.adaptee = adaptee;

  }

  public void actionPerformed(ActionEvent e) {

    adaptee.clik_action(e);

  }

}



class st_actionAdapter implements java.awt.event.ActionListener {

  game adaptee;



    st_actionAdapter(game adaptee) {

    this.adaptee = adaptee;

  }

  public void actionPerformed(ActionEvent e) {

    adaptee.st_action(e);

  }

}



class cl_actionAdapter implements java.awt.event.ActionListener {

  game adaptee;



  cl_actionAdapter(game adaptee) {

    this.adaptee = adaptee;

  }

  public void actionPerformed(ActionEvent e) {

    adaptee.cl_action(e);

  }

}



***********************************************************************************
import java.rmi.*;

import java.rmi.registry.*;

import java.net.*;

import java.io.*;

import java.awt.BorderLayout;

import java.awt.Color;

import javax.swing.JFrame;

import javax.swing.JTabbedPane;

import javax.swing.JLabel;

import javax.swing.JPanel;

import javax.swing.JButton;

import javax.swing.SwingConstants;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.Transparency;

import javax.swing.event.*;

import java.sql.*;

import java.util.*;

import java.net.URL;

import javax.imageio.ImageIO;

import java.lang.*;

import javax.swing.BoxLayout;



public class RmiClient

{

       ReceiveMessageInterface rmiServer;

       Registry registry;

       String sp="";

       String serverPort="8000";

       String line="some thing";

   

    public RmiClient(String serverAddress)

    {

      

         try

         {

           // get the “registry”

           registry=LocateRegistry.getRegistry(serverAddress,(new Integer(serverPort)).intValue());

           // look up the remote object

           rmiServer =(ReceiveMessageInterface)(registry.lookup("rmiServer"));

           rmiServer.receiveMessage("Connect");

           System.out.println("Connected to :"+serverAddress);

           

         }

            catch(RemoteException e){

           e.printStackTrace();

       }

          catch(NotBoundException e){

           e.printStackTrace();

       }



         

     }

     

     public String all(String gp)

     {

         try{

         

           // call the remote method

           rmiServer.receiveMessage(gp);

           sp = rmiServer.sendMessage();

           

           System.out.println("Sending :"+gp);

           System.out.println("From Server "+sp);

     

       }

       catch(RemoteException e){

           e.printStackTrace();

       }

       return sp;

    }

}


***********************************************************************************
import java.rmi.*;



public interface ReceiveMessageInterface extends Remote

{



   void receiveMessage(String x) throws RemoteException;

    public String sendMessage() throws RemoteException;



}


***********************************************************************************

For server side.....
Create project with 2 java class
1.ReceiveMessageInterface.java
2.RmiServer.java


import java.rmi.*;



public interface ReceiveMessageInterface extends Remote

{



   void receiveMessage(String x) throws RemoteException;

    public String sendMessage() throws RemoteException;



}




***********************************************************************************
import java.rmi.*;

import java.rmi.registry.*;

import java.rmi.server.*;

import java.net.*;

import java.io.*;

import java.util.Random;





public class RmiServer extends java.rmi.server.UnicastRemoteObject implements ReceiveMessageInterface

{



    int thisPort,c = 0,p=0;

    String thisAddress,st="";

    Registry registry;    // rmi registry for lookup the remote objects.

    char[][] input = new char[100][100];

    int[][] val = new int[100][100];

    Random generator = new Random();



    // This method is called from the remote client by the RMI.



    // This is the implementation of the “ReceiveMessageInterface”.



    public void receiveMessage(String x) throws RemoteException

    {

        st = ""; 

        System.out.println(x);

        if(x.equals("Connect"))

        {

            int i,j,k,l=0,mo,r=0,g;

            k = 2;

             mo = generator.nextInt( 7 );

            for(i=0;i<8;i++)

            {

                ++r;

                g = mo % r;

                System.out.print(""+r);

                for(j=0;j<4;j++)

                {

                    if(l == k+g)

                    {

                        l = 0;

                        input[i][j] = '*';

                    }

                    else

                    {

                        input[i][j] = '.';

                    }    

                        ++l;

                }

            }

            

            // calculate

            int p,xx,yy,v;

            int px[] = {-1,-1,-1,0,0,1,1,1};

            int py[] = {0,1,-1,-1,1,-1,0,1};

            for(i=0;i<8;i++)

            {

                for(j=0;j<4;j++)

                {

                    if(input[i][j] == '.')

                    {

                        v = 0;

                        for(p=0;p<8;p++)

                        {

                            xx = i + px[p];

                            yy = j + py[p];

                            if(xx >=0 && xx <= 8 && yy >=0 && yy <= 3)

                            {

                                if(input[xx][yy] == '*')

                                {

                                    ++v;

                                }    

                            }

                        }

                        val[i][j] = v;

                    }

                    if(input[i][j] == '*')

                    {

                        val[i][j] = -1;

                    }

                }

            }

            

        }

        st += x;



    }

    

   

    public String sendMessage() throws RemoteException

    {

  

       

       int i,j,k;

       k = Integer.parseInt(st);

       k = k-1;

       j = k % 4;

       i = k/4;

       

       if(val[i][j] == -1)

       {

              st = ":)";

       }

       else

       {

              st = Integer.toString(val[i][j]);

       }

       return st;

    }







    public RmiServer() throws RemoteException

    {



        try{



            // get the address of this host.



            thisAddress= (InetAddress.getLocalHost()).toString();



        }



        catch(Exception e){



            throw new RemoteException("can't get inet address.");



        }



              thisPort=8000;  // this port(registry’s port)



        System.out.println("this address="+thisAddress+",port="+thisPort);



        try{



        // create the registry and bind the name and object.



            registry = LocateRegistry.createRegistry( thisPort );



            registry.rebind("rmiServer", this);



        }



        catch(RemoteException e){



        throw e;



        }



    }



   



    static public void main(String args[])

    {



        try

        {



        RmiServer s=new RmiServer();



       }



    catch (Exception e) {



           e.printStackTrace();



           System.exit(1);



    }



     }



}



***********************************************************************************




Image Downloader source code in Java and Manga downloader

import java.io.BufferedOutputStream;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.InputStream;

import java.io.OutputStream;

import java.net.URL;



public class ImagesDownloader {

    public static void main(String[] args) throws IOException {

        getImages();

    }

    

    private static void getImages() throws IOException {

        String imagesRootPath = "http://somemanga.com/images2/";

  

            // http://somemanga.com/images2/13342848.jpg

            // http://i999.mangareader.net/naruto/538/naruto-2251381.jpg

            for (int i = 13342848; i <= 13342848+9; i++) {

                URL url = new URL(String.format("%s%d.jpg", imagesRootPath, i));

                InputStream in = url.openStream();

                OutputStream out = new BufferedOutputStream(new FileOutputStream(String.format("D:/exam/RMI Assignment update/%d.jpg", i)));

                for (int b; (b = in.read()) != -1; ) {

                    out.write(b);

                }

                out.close();

                in.close();

                System.out.println(String.format("Image %d.jpg from folder %s has been successfully downloaded.", i,imagesRootPath ));

            }

        

    }

}

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;

}


Line Clipping or Liang Bersky Algorithm source code in c++ with openGL

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



double xmin=50,ymin=50,xmax=100,ymax=100;

double xvmin=150,yvmin=150,xvmax=400,yvmax=400;

double x2,y2,x3,y3;



int test(double p,double q,double *t1,double *t2)

{

    double t=q/p;

    if(p<0.0)

    {

        if(t> *t1) *t1=t;

        if(t> *t2) return(false);

    }

    else if(p>0.0)

    {

        if(t< *t2) *t2=t;

        if(t< *t1) return(false);

    }

    else if(p==0.0)

    {

        if(q<0.0) return(false);

    }

    return(true);

}



void LiangBarsky(double x0,double y0,double x1,double y1)

{

    double dx=x1-x0,dy=y1-y0,te=0.0,tl=1.0;



    if(test(-dx,x0-xmin,&te,&tl))

    if(test(dx,xmax-x0,&te,&tl))

    if(test(-dy,y0-ymin,&te,&tl))

    if(test(dy,ymax-y0,&te,&tl))

    {

        if(tl<1.0){x1=x0+tl*dx;y1=y0+tl*dy;}

        if(te>0.0){x0=x0+te*dx;y0=y0+te*dy;}



        double sx=(xvmax-xvmin)/(xmax-xmin);

        double sy=(yvmax-yvmin)/(ymax-ymin);



        double vx0=xvmin+(x0-xmin)*sx;

        double vy0=yvmin+(y0-ymin)*sy;

        double vx1=xvmin+(x1-xmin)*sx;

        double vy1=yvmin+(y1-ymin)*sy;



        glColor3f(1.0,0.0,0.0);

        glBegin(GL_LINE_LOOP);

        glVertex2f(xvmin,yvmin);

        glVertex2f(xvmax,yvmin);

        glVertex2f(xvmax,yvmax);

        glVertex2f(xvmin,yvmax);

        glEnd();

        glColor3f(0.0,0.0,1.0);

        glBegin(GL_LINES);

        glVertex2d(vx0,vy0);

        glVertex2d(vx1,vy1);

        glEnd();

     }

}



/*

 Robel Sharma

*/

void display()

{

    glClear(GL_COLOR_BUFFER_BIT);

    glColor3f(1.0,0.0,0.0);

    glBegin(GL_LINES);

    glVertex2d(x2,y2);

    glVertex2d(x3,y3);

    glEnd();

    glColor3f(0.0,0.0,1.0);

    glBegin(GL_LINE_LOOP);

    glVertex2f(xmin,ymin);

    glVertex2f(xmax,ymin);

    glVertex2f(xmax,ymax);

    glVertex2f(xmin,ymax);

    glEnd();

    LiangBarsky(x2,y2,x3,y3);

    glFlush();

}



void myinit()

{

    glClearColor(1.0,1.0,1.0,1.0);

    glMatrixMode(GL_PROJECTION);

    glLoadIdentity();

    gluOrtho2D(0.0,499.0,0.0,499.0);

}



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

{



    printf("Enter the end points of the line: ");

    scanf("%lf%lf%lf%lf", &x2,&y2,&x3,&y3);

    glutInit(&argc,argv);

    glutInitDisplayMode(GLUT_SINGLE|GLUT_RGB);

    glutInitWindowSize(600,600);

    glutInitWindowPosition(0,0);

    glutCreateWindow("Line Clipping");

    glutDisplayFunc(display);

    myinit();

    glutMainLoop();

}