Example #1
0
  /**
   * Preprocesses the image. The image must be of LUMINANCE type or an assertion error is thrown.
   *
   * @see com.shavenpuppy.jglib.opengl.GLTexture#preprocess()
   */
  @Override
  protected Image preprocess() {
    int index = 0, srcindex = 0;
    final Vector3f[] vec = new Vector3f[image.getWidth() * image.getHeight()];
    final Vector3f[] dst = new Vector3f[image.getWidth() * image.getHeight()];
    final byte[] nrm = new byte[image.getWidth() * image.getHeight() * 3];

    // Create vector3f array first:
    for (int j = 0; j < image.getHeight(); ++j) {
      for (int i = 0; i < image.getWidth(); ++i) {
        vec[index++] = new Vector3f(i, j, (image.getData().get(srcindex++) & 0xff));
      }
    }

    Vector3f a = new Vector3f();
    Vector3f b = new Vector3f();
    Vector3f c = new Vector3f();

    // Now work out normals
    for (int j = 0; j < image.getHeight(); j++) {
      for (int i = 0; i < image.getWidth(); i++) {
        a.x = 2;
        a.y = 0;
        a.z = vec[index(i + 1, j)].z - vec[index(i - 1, j)].z;
        //			a = vec(i+1,   j) - p(i-1,   j);
        b.x = 0;
        b.y = 2;
        b.z = vec[index(i, j + 1)].z - vec[index(i, j - 1)].z;
        //			b = vec(  i, j+1) - p(  i, j-1);
        Vector3f.cross(a, b, c);
        c.z *= scale;
        c.normalise();
        dst[i + j * image.getWidth()] = new Vector3f(c);
      }
    }
    // Now transform into rgb:
    index = 0;
    srcindex = 0;
    for (int j = 0; j < image.getHeight(); j++) {
      for (int i = 0; i < image.getWidth(); i++) {
        nrm[index++] = (byte) ((dst[srcindex].x + 1f) * 127.5f);
        nrm[index++] = (byte) ((dst[srcindex].y + 1f) * 127.5f);
        nrm[index++] = (byte) ((dst[srcindex++].z + 1f) * 127.5f);
      }
    }

    // Create an SpriteImage out of our bump data
    return new Image(image.getWidth(), image.getHeight(), Image.RGB, nrm);
  }
Example #2
0
 public void drawSphere(int scaleX, int scaleY, int scaleZ, int posX, int posY, int posZ) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawSphere(false, 0, scaleX, scaleY, scaleZ, axe);
 }
Example #3
0
 private void calculateCameraPosition(float horizDistance, float verticDistance) {
   float theta = player.getRotY() + angleAroundPlayer;
   float offsetX = (float) (horizDistance * Math.sin(Math.toRadians(theta)));
   float offsetZ = (float) (horizDistance * Math.cos(Math.toRadians(theta)));
   position.x = player.getPosition().x - offsetX;
   position.z = player.getPosition().z - offsetZ;
   position.y = player.getPosition().y + verticDistance;
 }
 public Vector3f getRGB(int x, int y) {
   Vector3f c = new Vector3f();
   int i = x + y * getWidth();
   c.x = (pixels[i] & 0xff0000) >> 16;
   c.y = (pixels[i] & 0xff00) >> 8;
   c.z = (pixels[i] & 0xff);
   return c;
 }
Example #5
0
 public void fillSphere(
     int texture, int scaleX, int scaleY, int scaleZ, int posX, int posY, int posZ) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawSphere(true, texture, scaleX, scaleY, scaleZ, axe);
 }
  /*
   * A super messy way to initiate the camera position without gameplay-input (meant to be run exactly once,
   * at the beginning of the loading of a level).
   */
  public void findPlayer() {
    boolean lockNS =
        ResourceManager.MANAGER.playerFocusEntity.cameraLockNS(
            GameMap.MAP, GraphicsManager.MANAGER);
    boolean lockEW =
        ResourceManager.MANAGER.playerFocusEntity.cameraLockEW(
            GameMap.MAP, GraphicsManager.MANAGER);

    int mapHeight =
        GameMap.MAP.mapCanvas.get(ResourceManager.MANAGER.playerFocusEntity.mapLevel).mapHeight
            * GameMap.MAP.tileDimensions;
    int mapWidth =
        GameMap.MAP.mapCanvas.get(ResourceManager.MANAGER.playerFocusEntity.mapLevel).mapWidth
            * GameMap.MAP.tileDimensions;

    int screenHeight = GraphicsManager.MANAGER.getHeight();
    int screenWidth = GraphicsManager.MANAGER.getWidth();

    int top = mapHeight - screenHeight + (GraphicsManager.MANAGER.border * 2); // excess height!
    int right = mapWidth - screenWidth + (GraphicsManager.MANAGER.border * 2);

    setPosition(0, 0, 0);

    if (lockNS) position.y = ResourceManager.MANAGER.playerFocusEntity.position.y;
    else {
      if (ResourceManager.MANAGER.playerFocusEntity.position.y > ((mapHeight / 2) - top / 2))
        position.y = mapHeight / 2 + top / 2;
      else position.y = mapHeight / 2 - top / 2;
    }

    if (lockEW) position.x = ResourceManager.MANAGER.playerFocusEntity.position.x;
    else {
      if (ResourceManager.MANAGER.playerFocusEntity.position.x > ((mapWidth / 2) - right / 2))
        position.x = mapWidth / 2 + right / 2;
      else position.x = mapWidth / 2 - right / 2;
    }
  }
Example #7
0
 public void drawColorSphere(
     int texture,
     int scaleX,
     int scaleY,
     int scaleZ,
     int posX,
     int posY,
     int posZ,
     float r,
     float g,
     float b) {
   Vector3f axe = new Vector3f(0, 0, 0);
   axe.x = posX;
   axe.y = posY;
   axe.z = posZ;
   Sphere.drawColorSphere(true, texture, scaleX, scaleY, scaleZ, axe, r, g, b);
 }
 @Override
 public float translateY(float delta) {
   position.y += delta;
   return delta;
 }
Example #9
0
 public void setXYZ(float[] xyz) {
   position.x = xyz[0];
   position.y = xyz[1];
   position.z = xyz[2];
 }