home *** CD-ROM | disk | FTP | other *** search
/ Java Developer's Companion / Java Developer's Companion.iso / Javacup / IN231VFD.TAR / internet / IN231VFD / Camera.java < prev    next >
Encoding:
Java Source  |  1996-05-21  |  1.3 KB  |  57 lines

  1. //    Camera.java - Onscreen Camera object
  2. //
  3. //    Copyright (C) 1996 by Dale Gass
  4. //    Non-exclusive license granted to MKS, Inc.
  5. //
  6.  
  7. import java.lang.*;
  8. import java.util.*;
  9. import java.awt.*;
  10. import java.net.*;
  11. import java.applet.*;
  12.  
  13. // Onscreen Camera object
  14.  
  15. public class Camera {
  16.     int x, y, angle;
  17.     String describe;
  18.  
  19.     final static int camx[] = { -20,  20,  20, -20, -20,   0, -20,  20,   0 };
  20.     final static int camy[] = { -10, -10,  10,  10, -10, -10, -30, -30, -10 };
  21.  
  22.     // Create the object with given position, angle, rotation, description
  23.  
  24.     public Camera(int x_, int y_, int angle_, String describe_) {
  25.     x = x_;
  26.     y = y_;
  27.     angle = angle_;
  28.     describe = describe_;
  29.     }
  30.  
  31.     // Draw the object in given colour
  32.  
  33.     void draw(Graphics g, Color color) {
  34.     int rotx[], roty[];
  35.     double ran = angle * (2*Math.PI/360);
  36.  
  37.     rotx = new int[camx.length];
  38.     roty = new int[camy.length];
  39.  
  40.     for (int i=0; i<camx.length; i++) {
  41.         rotx[i] = (int) (Math.cos(ran) * camx[i] - 
  42.                  Math.sin(ran) * camy[i]) + x;
  43.         roty[i] = (int) (Math.cos(ran) * camy[i] +
  44.                  Math.sin(ran) * camx[i]) + y;
  45.     }
  46.  
  47.     g.setColor(color);
  48.     g.drawPolygon(rotx, roty, camx.length);
  49.     }
  50.  
  51.     // Retrieve the description
  52.  
  53.     public String toString() {
  54.         return describe;
  55.     }
  56. }
  57.