Cubo en java

Páginas: 2 (349 palabras) Publicado: 28 de octubre de 2010
import java.applet.*;

import java.awt.*;

import java.awt.event.*;

import java.lang.Math;

import java.awt.Polygon;

class Point{

public double x;

public double y;

public doublez;

Point(){ this.x=0; this.y=0; this.z=0; }

Point(double x,double y, double z){ this.x=x; this.y=y; this.z=z; }

/* for move it at origin */

int getXCoordinate(){return Cube.origin +(int)this.x;}

int getYCoordinate(){return Cube.origin - (int)this.y;}

int getZCoordinate(){return 0;} /* projection on XY plane*/

}

class Face{

Point p1,p2,p3,p4;

Polygon side= newPolygon();

Face(){}

Face(Point p1,Point p2,Point p3,Point p4){

this.p1=p1;this.p2=p2;this.p3=p3;this.p4=p4;

this.side.addPoint(p1.getXCoordinate(),p1.getYCoordinate());this.side.addPoint(p2.getXCoordinate(),p2.getYCoordinate());

this.side.addPoint(p3.getXCoordinate(),p3.getYCoordinate());

this.side.addPoint(p4.getXCoordinate(),p4.getYCoordinate());

}

public voiddrawFace(Graphics g){ g.fillPolygon(side); }

public boolean isVisible(){

Point aux1, aux2;

aux1 = new Point(p2.x-p1.x, p2.y-p1.y, p2.z-p1.z); // p1->p2

aux2 = new Point(p4.x-p1.x, p4.y-p1.y, p4.z-p1.z);// p1->p4

if((aux1.x*aux2.y - aux1.y*aux2.x) > 0)

return true;

return false;

}

}

public class Cube extends Applet implements

Runnable, MouseMotionListener{

Thread luxury;static Point[] vertex = new Point[8]; // Cube vertexes

static int maxSize =300; // screen size

static int origin = maxSize/2; // (0,0)

static int xMouseP=0, yMouseP =0; // X and Y mouse'spositions

int xAux , yAux ; // old X and Y mouse's positions

int module = 50; // length of lines of cube.

Image canvasAux;

Graphics backBuffer;

public void init(){setSize(maxSize,maxSize);

setBackground( new Color(0.2f,0.6f,0.1f,1.0f) );

addMouseMotionListener(this);

/*Initial coordinates of eight vertex

module is half the length of the cube*/

int[] coordX = new...
Leer documento completo

Regístrate para leer el documento completo.

Estos documentos también te pueden resultar útiles

  • cubos
  • Cuba
  • CUBA
  • Cuba
  • cuba
  • Cubo
  • Cuba
  • cuba

Conviértase en miembro formal de Buenas Tareas

INSCRÍBETE - ES GRATIS