🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: cn.bbs.comp.lang.java
Article #24349

�������ͼ��(ת��)

#24349
From: wooce
Date: Tue, 24 Mar 1998 00:00
357 lines
13136 bytes


//|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//| This file contains the implementation of the Graphic class.  A Graphic is a
//| collection of graphics primitives.
//|________________________________________________t: the applet which owns this scroll bar
        //|_________________________________________________________
        
        LiveScrollBar(int a, int b, int c, int d, int e, java.applet.Applet papplet)
        {
        
                super(a, b, c, d, e);
        
                applet = papplet;
        
        }       //==== method LiveScrollBar of LiveScrollBar() ====\\
        
         public boolean mouseUp(Event ev, int x, int y)
        {
                applet.getAppletContext().showStatus("mouseDrag");
//              return super(ev, x, y);
                return true;
        }
        
}       //==== class LiveScrollBar ====//



class NPoint extends Vector
{

        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method NPoint of NPoint
        //|
        //| Purpose: Initialize a NPoint.
        //|
        //| Parameters: n: the dimension of the point
        //|_________________________________________________________
        
        NPoint(int n)
        {
                super(n);

                // Set the vector to [0, 0, ..., 0]
                int i;
                for (i = 1; i <= n; i++)
                        addElement(new Double(0));
        
        }       //==== method NPoint of NPoint() ====//



        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method NPoint of NPoint
        //|
        //| Purpose: Initialize a NPoint.
        //|
        //| Parameters: x, y: the coordinates of the point
        //|_________________________________________________________
        
        NPoint(double x, double y)
        {
        
                // This is a 2D point
                super(2);

                // Set t Add a zero row
                        int j;
                        for (j = 0; j < n; j++)
                                row.addElement(new Double(0));

                        rows.addElement(row);
                        }

        }       //==== method Matrix of Matrix ====\\


        
        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method setElement of Matrix
        //|
        //| Purpose: This initializes this matrix.
        //|
        //| Parameters: r, c:  the row, column of the element to change
        //|             value: 
        //|_____________________________________________________________________________

        void setElement(int r, int c, double value)
        {

                // Change element r, c
                Vector row = (Vector) rows.elementAt(r);
                row.setElementAt(new Double(value), c);

        }       //==== method setElement of Matrix ====\\
        
        
        
        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method setElement of Matrix
        //|
        //| Purpose: This initializes this matrix.
        //|
        //| Parameters: r, c:  the row, column of the element to change
        //|             value: 
        //|_____________________________________________________________________________

        double getElement(int r, int c) 
        {

                // Get element r, c
                Vector row = (Vector) rows.elementAt(r);
                return ((Double) row.elementAt(c)).doubleValue();

        }       //==== method getElement of Matrix ====\\

}       //==== class Matrix ====//



public class HyperCuber extends java.applet.Applet
{

        NGraphic graphic;
        
        GraphicSlider perspectiveSlider3;
        GraphicSlider angleSlider3_1;
        GraphicSlider angleSlider3_2;

        GraphicSlider perspectiveSlider4;
        GraphicSlider angleSlider4_1;
        GraphicSlider angleSlider4_2;
        GraphicSlider angleSlider4_3;

        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method init of HyperCuber
        //|
        //| Purpose: Initialize a HyperCuber.
        //|
        //| Parameters: none
        //|_________________________________________________________

    public void init()
    {
    
        // Set up to display a three-dimensional object
//      graphic = new Cube();
        e
        //|
        //| Purpose: This creates a new HyperCube.
        //|
        //| Parameters: none
        //|_____________________________________________________________________________
        
        HyperCube()
        {
        
                // Initialize this as a 4D NGraphic
                super(4);
        
        }       //==== method HyperCube of HyperCube ====\\
        

        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method build of HyperCube
        //|
        //| Purpose: This builds the graphic.  It fills in the vertex list, and
        //|          adds paths to the object.
        //|
        //| Parameters: none
        //|__________________________________________________________________________
        
    public void build()
        {

                // Use the vertices of a cube as our vertices
                Vector fourDPoints = (Vector) vertexArrays.elementAt(4);
                fourDPoints.addElement(new NPoint( 0,  0,  0,  0));
                fourDPoints.addElement(new NPoint(-1, +1, -1, +1));
                fourDPoints.addElement(new NPoint(-1, +1, +1, +1));
                fourDPoints.addElement(new NPoint(+1, +1, +1, +1));
                fourDPoints.addElement(new NPoint(+1, +1, -1, +1));
                
                fourDPoints.addElement(new NPoint(-1, -1, -1, +1));
                fourDPoints.addElement(new NPoint(-1, -1, +1, +1));
                fourDPoints.addElement(new NPoint(+1, -1, +1, +1));
                fourDPoints.addElement(new NPoint(+1, -1, -1, +1));

                fourDPoints.addElement(new NPoint(-th.addElement(new Integer(7));
                path.addElement(new Integer(15));
                paths.addElement(path);

                path = new Path(Color.blue);
                path.addElement(new Integer(8));
                path.addElement(new Integer(16));
                paths.addElement(path);

        }       //==== method build of HyperCube ====\\

}       //==== class HyperCube ====//



class NGraphic extends Canvas
{

        // The primitives in this graphic
        Vector paths;
        
        // This is a list of lists.  The nth list contains the vertex positions in n-space.
        Vector vertexArrays;

        Vector rotationMatrices;                                //  The rotation matrices.  The nth element in this
                                                                                        //    list is a handle to the rotation matrix used
                                                                                        //    to rotate n-space.

        Vector stereoMatrices;                                  //  This is the list of rotation matrices used for
                                                                                        //    the second image used in stereo.  Note that all
                                                                                        //    the matrices except the 3D->2D matrix are aliases
                                                                                        //    of the matrices in the "rotationMatrices" list.

        Vector perspectiveParams;                               //  The perspective paramaters.  The nth element in
                                                                                        //    this array is the perspective parameter for
                                                                                        //    n-space (an int).
                                                                                        
        Vector  angleArrays;                                    //  The sines of the viewing angles.
        
        Vector screenPoints;
        
        //============================= Constants ==============================//
        double  Pi      = 3.14159265358979323846;
        int dimension = 3;      
        

        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method NGraphic of NGraphic
        //|
        //| Purpose: This creates a new NGraphic.
        //|
         none
        //|__________________________________________________________________________
        
    public void paint(Graphics g)
        {

                // Project the object down to 2-space
                Project(dimension);

                // Draw a rectangle
                Dimension ourSize = size();
                g.fillRect(0, 0, ourSize.width - 1, ourSize.height - 1);
                
                //  Draw all paths
                int i;
                for (i = 0; i < paths.size(); i++)                                              
                        {
                        //  Get this path
                        Path path = (Path) paths.elementAt(i);

                        // Draw this primitive                  
                        path.Draw(g, screenPoints);
                        }
        
        ngePerspective of NGraphic() ====\\


                
        //|~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        //| method Project of NGraphic
        //|
        //| Purpose: Project the the vertices from the n-dimensional vertex list 
        //|          to the (n-1)-dimensional vertex list.  This also propagates
        //|          downward to (n-2), etc, down to 2D and the screen points.
        //|
        //| Parameters: n: dimension to project from
        //|__________________________________________________________________________
        
        v               THUMB_SIZE * 2 + 1, height - 2 * BUFFER - TEXT_HEIGHT,
                     true);
        
        g.setColor(slashColor_);
        g.drawLine(pixel_, TEXT_HEIGHT + BUFFER + 1,
                   pixel_, height - 2 * BUFFER);

        g.setColor(textColor_);
        g.setFont(font_);               
        String str = String.valueOf(value_);
        g.drawString(str, pixel_ -
                     (int)(getFontMetrics(font_).stringWidth(str) / 2),
                     TEXT_HEIGHT - TEXT_BUFFER);
    }

    void HandleMouse(int x) {
        double percent;
        int width = size().width;
        pixel_ = Math.max(x, pixelMin_);
        pixel_ = Math.min(pixel_, pixelMax_);

        if (pixel_ != pixelMin_)
            percent = (((double)pixel_ - pixelMin_) /
                       (pixelMax_ - pixelMin_));
        else
            percent = 0;
        
        value_ = (int)(Math.round(percent * (double)(max_ - min_))) + min_;
        
        paint(getGraphics());
    }
    
/**
 * An internal method used to handle mouse down events.
 */
    public boolean mouseDown (Event e, int x, int y) {
        HandleMouse(x);
        Motion();
        return true;
    }

/**
 * An internal method used to handle mouse drag events.
 */
    public boolean mouseDrag (Event e, int x, int y) {
        HandleMouse(x);
        Motion();       
        return true;
    }

/**
 * An internal method used to handle mouse up events.
 */
    public boolean mouseUp (Event e, int x, int y) {
        HandleMouse(x);
        Release();
        return true;
    }

/**
 * An internal method used to handle resizing.
 */
    public void reshape(int x, int y, int width, int height) {
        super.reshape(x, y, width, height);
        pixelMin_ = THUMB_SIZE + BUFFER;
        pixelMax_ = width - THUMB_SIZE - BUFFER - 1;
        if (value_ != min_)
            pixel_ = (int)(Math.round(Math.abs((double)(value_ - min_) /
                                               (double)(max_ - min_)) *
                                      (double)(pixelMax_ - pixelMin_)) +
                           pixelMin_);
        else
            pixel_ = pixelMin_;
    }
    
}

--
�� ��Դ:���������� BBS bbs.nease.net��[FROM: 202.96.174.34]
Technical Details
Message-ID: <3Nc8Sg$80a@bbs.nease.net>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: f6cb0,a793540721d4c616,start
X-Google-Attributes: gidf6cb0,public
From: wooce.bbs@bbs.nease.net (wooce)
Subject: �������ͼ��(ת��)
Date: 1998/03/24
Message-ID: <3Nc8Sg$80a@bbs.nease.net>
X-Deja-AN: 337112689
X-Filename: Java/M.890727786.A
Organization: Net Ease
Newsgroups: cn.bbs.comp.lang.java,