Example #1
0
 @Override
 public CalcObject divide(CalcObject b) {
   if (b.getType() == CType.INTEGER) {
     IntObject bInt = (IntObject) b;
     return new MatrixObject(matrix.times(1.0 / ((double) bInt.getValue())));
   } else if (b.getType() == CType.MATRIX) {
     MatrixObject bMatrix = (MatrixObject) b;
     throw new UnsupportedOperationException("Have not implemented / for matricies yet");
   } else {
     throw new IllegalArgumentException("Bad object type: " + b.getType());
   }
 }
Example #2
0
 @Override
 public CalcObject add(CalcObject b) {
   if (b.getType() == CType.INTEGER) {
     IntObject bInt = (IntObject) b;
     return scalarAdd(bInt.getValue());
   } else if (b.getType() == CType.MATRIX) {
     MatrixObject bMatrix = (MatrixObject) b;
     return new MatrixObject(this.matrix.plus(bMatrix.matrix));
   } else {
     throw new IllegalArgumentException("Bad object type: " + b.getType());
   }
 }
Example #3
0
 @Override
 public CalcObject multiply(CalcObject b) {
   if (b.getType() == CType.INTEGER) {
     IntObject bInt = (IntObject) b;
     return new MatrixObject(matrix.times(bInt.getValue()));
   } else if (b.getType() == CType.MATRIX) {
     MatrixObject bMatrix = (MatrixObject) b;
     return new MatrixObject(matrix.times(bMatrix.matrix));
   } else {
     throw new IllegalArgumentException("Bad object type: " + b.getType());
   }
 }
Example #4
0
  private void createSet(char[] customCharsArray) {
    // If there are custom chars then I expand the font texture twice
    if (customCharsArray != null && customCharsArray.length > 0) {
      textureWidth *= 2;
    }

    // In any case this should be done in other way. Texture with size 512x512
    // can maintain only 256 characters with resolution of 32x32. The texture
    // size should be calculated dynamicaly by looking at character sizes.

    try {

      BufferedImage imgTemp =
          new BufferedImage(textureWidth, textureHeight, BufferedImage.TYPE_INT_ARGB);
      Graphics2D g = (Graphics2D) imgTemp.getGraphics();

      g.setColor(new Color(0, 0, 0, 1));
      g.fillRect(0, 0, textureWidth, textureHeight);

      int rowHeight = 0;
      int positionX = 0;
      int positionY = 0;

      int customCharsLength = (customCharsArray != null) ? customCharsArray.length : 0;

      for (int i = 0; i < 256 + customCharsLength; i++) {

        // get 0-255 characters and then custom characters
        char ch = (i < 256) ? (char) i : customCharsArray[i - 256];

        BufferedImage fontImage = getFontImage(ch);

        IntObject newIntObject = new IntObject();

        newIntObject.width = fontImage.getWidth();
        newIntObject.height = fontImage.getHeight();

        if (positionX + newIntObject.width >= textureWidth) {
          positionX = 0;
          positionY += rowHeight;
          rowHeight = 0;
        }

        newIntObject.storedX = positionX;
        newIntObject.storedY = positionY;

        if (newIntObject.height > fontHeight) {
          fontHeight = newIntObject.height;
        }

        if (newIntObject.height > rowHeight) {
          rowHeight = newIntObject.height;
        }

        // Draw it here
        g.drawImage(fontImage, positionX, positionY, null);

        positionX += newIntObject.width;

        if (i < 256) { // standard characters
          charArray[i] = newIntObject;
        } else { // custom characters
          customChars.put(new Character(ch), newIntObject);
        }

        fontImage = null;
      }

      fontTextureID = loadImage(imgTemp);

      // .getTexture(font.toString(), imgTemp);

    } catch (Exception e) {
      System.err.println("Failed to create font.");
      e.printStackTrace();
    }
  }
Example #5
0
 public MatrixObject(IntObject i) {
   super(CType.MATRIX);
   matrix = new Matrix(1, 1, (double) i.getValue());
 }