游戏开发论坛

 找回密码
 立即注册
搜索
查看: 1189|回复: 0

三维立方体wxhzt

[复制链接]

1367

主题

1993

帖子

2118

积分

金牌会员

Rank: 6Rank: 6

积分
2118
发表于 2005-7-24 22:35:00 | 显示全部楼层 |阅读模式
import java.awt.*;
import javax.swing.*;
public class Gr3d4a extends Gr3d1m {

/**
*<br>方法说明:主方法
*<br>输入参数:
*<br>返回类型:
*/
  public static void main(String[] args){
     Gr3d4a G3 = new Gr3d4a();
  }
/**
*<br>方法说明:构造器
*<br>输入参数:
*<br>返回类型:
*/
  public  Gr3d4a() {
    setTitle("3D cube box");
     setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
     addMouseListener(this);
     addMouseMotionListener(this);
     setBackground(new Color(128,128,255));
     setSize(350,350);
     show();
  }
/**
*<br>方法说明:绘制正方体盒子,过载Gr3d1m中的方法
*<br>输入参数:
*<br>返回类型:
*/
  public void drawPG(Graphics g,double []x,double []y,
                     double []z,int xp,int yp,Color co) {
     double x1,y1,z0;
     int len=x.length;
     double [] xw=new double[len];
     double [] yw=new double[len];
     int    [] xx=new int   [len];
     int    [] yy=new int   [len];
     final double RAD=Math.PI/180.0;
     double a=angX*RAD;
     double b=angY*RAD;
     double sinA=Math.sin(a),sinB=Math.sin(b);
     double cosA=Math.cos(a),cosB=Math.cos(b);
     for (int i=0; i<len; i++) {
        x1= x*cosB+z*sinB;
        z0=-x*sinB+z*cosB;
        y1= y*cosA-  z0*sinA;
        xx=xp+(int)Math.rint(x1);
        yy=yp-(int)Math.rint(y1);
        xw=x1; yw=y1;
     }
     if (Hvec(xw,yw) > 0) {
        g.setColor(co);
        g.fillPolygon(xx,yy,len);//填充的多边形
     }
  }
/**
*<br>方法说明:消影处理,如果平面被遮蔽将不被绘制
*<br>输入参数:
*<br>返回类型:
*/
  double Hvec(double []x,double []y) {
    return(x[0]*(y[1]-y[2])+x[1]*(y[2]-y[0])+x[2]*(y[0]-y[1]));
  }
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

作品发布|文章投稿|广告合作|关于本站|游戏开发论坛 ( 闽ICP备17032699号-3 )

GMT+8, 2025-12-26 13:29

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表