예제 #1
0
 public static void setCelestialPosition() {
   // This is called when the current matrix is the modelview matrix based on the celestial angle.
   // The sun is at (0, 100, 0), and the moon is at (0, -100, 0).
   FloatBuffer modelView = BufferUtils.createFloatBuffer(16);
   glGetFloat(GL_MODELVIEW_MATRIX, modelView);
   float[] mv = new float[16];
   modelView.get(mv, 0, 16);
   float[] sunPos = multiplyMat4xVec4(mv, new float[] {0.0F, 100.0F, 0.0F, 0.0F});
   sunPosition = sunPos;
   float[] moonPos = multiplyMat4xVec4(mv, new float[] {0.0F, -100.0F, 0.0F, 0.0F});
   moonPosition = moonPos;
 }
예제 #2
0
  public static void setCamera(float f) {
    EntityLiving viewEntity = mc.renderViewEntity;

    double x = viewEntity.lastTickPosX + (viewEntity.posX - viewEntity.lastTickPosX) * f;
    double y = viewEntity.lastTickPosY + (viewEntity.posY - viewEntity.lastTickPosY) * f;
    double z = viewEntity.lastTickPosZ + (viewEntity.posZ - viewEntity.lastTickPosZ) * f;

    if (isShadowPass) {
      glViewport(0, 0, shadowMapWidth, shadowMapHeight);

      glMatrixMode(GL_PROJECTION);
      glLoadIdentity();

      if (shadowMapIsOrtho) {
        glOrtho(
            -shadowMapHalfPlane,
            shadowMapHalfPlane,
            -shadowMapHalfPlane,
            shadowMapHalfPlane,
            0.05f,
            256.0f);
      } else {
        // just backwards compatibility. it's only used when SHADOWFOV is set in the shaders.
        gluPerspective(
            shadowMapFOV, (float) shadowMapWidth / (float) shadowMapHeight, 0.05f, 256.0f);
      }

      glMatrixMode(GL_MODELVIEW);
      glLoadIdentity();
      glTranslatef(0.0f, 0.0f, -100.0f);
      glRotatef(90.0f, 1.0f, 0.0f, 0.0f);
      float angle = -mc.theWorld.getCelestialAngle(f) * 360.0f;
      if (angle < -90.0 && angle > -270.0) {
        // night time
        glRotatef(angle + 180.0f, 0.0f, 0.0f, 1.0f);
      } else {
        // day time
        glRotatef(angle, 0.0f, 0.0f, 1.0f);
      }
      if (shadowMapIsOrtho) {
        // reduces jitter
        glTranslatef((float) x % 5.0f, (float) y % 5.0f, (float) z % 5.0f);
      }

      shadowProjection = BufferUtils.createFloatBuffer(16);
      glGetFloat(GL_PROJECTION_MATRIX, shadowProjection);
      shadowProjectionInverse = invertMat4x(shadowProjection);

      shadowModelView = BufferUtils.createFloatBuffer(16);
      glGetFloat(GL_MODELVIEW_MATRIX, shadowModelView);
      shadowModelViewInverse = invertMat4x(shadowModelView);
      return;
    }

    previousProjection = projection;
    projection = BufferUtils.createFloatBuffer(16);
    glGetFloat(GL_PROJECTION_MATRIX, projection);
    projectionInverse = invertMat4x(projection);

    previousModelView = modelView;
    modelView = BufferUtils.createFloatBuffer(16);
    glGetFloat(GL_MODELVIEW_MATRIX, modelView);
    modelViewInverse = invertMat4x(modelView);

    previousCameraPosition[0] = cameraPosition[0];
    previousCameraPosition[1] = cameraPosition[1];
    previousCameraPosition[2] = cameraPosition[2];

    cameraPosition[0] = x;
    cameraPosition[1] = y;
    cameraPosition[2] = z;
  }