Пример #1
0
 public void setWireframeRender(boolean on) {
   if (wireframe != on) {
     if (on) {
       GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
     } else {
       GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
     }
     wireframe = on;
   }
 }
Пример #2
0
  @Override
  protected void render() {
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);
    glRotatef(1, 1, 0, 0);

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    glDrawElements(GL_QUAD_STRIP, brickIndices);
    glPolygonMode(GL_FRONT, GL_FILL);
    glDrawElements(GL_QUADS, paintedWall);
  }
  public boolean renderWorldBlock(
      IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {

    GL11.glPushAttrib(GL11.GL_TEXTURE_BIT);
    Tessellator t = Tessellator.instance;
    t.draw();
    GL11.glBindTexture(GL11.GL_TEXTURE_2D, YC_Constants.TreeCrystalTextureID);
    GL11.glPushMatrix();
    double t1 = 0, t2 = 0, t3 = 0;
    if (!YC_Options.EnableOptifineCompability) {
      ResetTranslation(x, y, z);
      GL11.glTranslatef(x, y, z);
      t1 = Tessellator.instance.xOffset;
      t2 = Tessellator.instance.yOffset;
      t3 = Tessellator.instance.zOffset;
      Tessellator.instance.setTranslation(0, 0, 0);
    } else {
      GL11.glTranslated(
          x + Tessellator.instance.xOffset,
          y + Tessellator.instance.yOffset,
          z + Tessellator.instance.zOffset);
    }
    GL11.glColor4f(1f, 1f, 1f, 1f);
    // {
    int md = world.getBlockMetadata(x, y, z);
    GL11.glTranslatef(0.5f, 0.5f, 0.5f);
    GL11.glRotatef(GetRotationXFromMD(md), 1, 0, 0);
    GL11.glRotatef(GetRotationZFromMD(md), 0, 0, 1);
    GL11.glTranslatef(-0.5f, -0.5f, +0.5f);
    YC_Mod.m_TreeCrystal.DrawWOTranslation();
    if (YC_Options.RenderContourSecondPass) {
      GL11.glBindTexture(
          GL11.GL_TEXTURE_2D, Minecraft.getMinecraft().renderEngine.getTexture("/YC/blank.png"));
      GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
      GL11.glColor3f(0f, 0f, 0f);
      YC_Mod.m_TreeCrystal.DrawWOTranslation();
      GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    }
    // }
    if (!YC_Options.EnableOptifineCompability) {
      Tessellator.instance.setTranslation(t1, t2, t3);
    }
    GL11.glPopMatrix();
    GL11.glColor4f(1f, 1f, 1f, 1f);
    GL11.glPopAttrib();

    t.startDrawingQuads();

    return true;
  }
Пример #4
0
  @Override
  public void draw() {

    if (m != null) {
      Vector3f min = b.getMin();
      Vector3f max = b.getMax();
      glPushMatrix();
      glTranslatef(origin.getX() + min.x, origin.getY() + min.y, origin.getZ() + min.z);
      glRotatef(angle, 0, 1, 0);
      m.draw();
      glPopMatrix();
      glDisable(GL_CULL_FACE);
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glBegin(GL_QUADS);

      glVertex3f(min.getX(), min.getY(), min.getZ());
      glVertex3f(max.getX(), min.getY(), min.getZ());
      glVertex3f(max.getX(), max.getY(), min.getZ());
      glVertex3f(min.getX(), max.getY(), min.getZ());

      glVertex3f(min.getX(), min.getY(), max.getZ());
      glVertex3f(max.getX(), min.getY(), max.getZ());
      glVertex3f(max.getX(), max.getY(), max.getZ());
      glVertex3f(min.getX(), max.getY(), max.getZ());

      glVertex3f(min.getX(), min.getY(), min.getZ());
      glVertex3f(min.getX(), min.getY(), max.getZ());
      glVertex3f(min.getX(), max.getY(), max.getZ());
      glVertex3f(min.getX(), max.getY(), min.getZ());

      glVertex3f(max.getX(), min.getY(), min.getZ());
      glVertex3f(max.getX(), min.getY(), max.getZ());
      glVertex3f(max.getX(), max.getY(), max.getZ());
      glVertex3f(max.getX(), max.getY(), min.getZ());

      glVertex3f(max.getX(), min.getY(), min.getZ());
      glVertex3f(min.getX(), min.getY(), min.getZ());
      glVertex3f(min.getX(), min.getY(), max.getZ());
      glVertex3f(max.getX(), min.getY(), max.getZ());

      glVertex3f(max.getX(), max.getY(), min.getZ());
      glVertex3f(min.getX(), max.getY(), min.getZ());
      glVertex3f(min.getX(), max.getY(), max.getZ());
      glVertex3f(max.getX(), max.getY(), max.getZ());

      glEnd();
      glEnable(GL_CULL_FACE);
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
    }
  }
Пример #5
0
  public static void main(String[] args) {

    Main main = new Main();
    Viewer viewer;
    try {
      viewer = new Viewer();
      GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);

      Scene scene = viewer.getScene();

      // viewer.setProjection(new OrthogonalProjection(0, 800, 600, 0, 1, -1));

      // GL11.glMatrixMode(GL11.GL_MODELVIEW);
      // GL11.glRectf(100.0f, 150.0f, 150.0f, 100.0f);
      MenuButton m = new MenuButton(250.0f, 50.0f, 600.0f, 100.0f, "Bzinga", 1);

      scene.add(m);
      // scene.render();
      viewer.run();

    } catch (LWJGLException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  @Override
  public void renderGUIInfo(
      Galaxy galaxy,
      SpaceBody spaceBody,
      TileEntityMachineStarMap starMap,
      float partialTicks,
      float opacity) {
    if (spaceBody instanceof Star) {
      RenderUtils.applyColorWithMultipy(Reference.COLOR_HOLO, opacity);
      glEnable(GL_ALPHA_TEST);

      Planet planet = galaxy.getPlanet(starMap.getDestination());
      if (planet != null) {
        if (GalaxyClient.getInstance()
            .canSeePlanetInfo(planet, Minecraft.getMinecraft().thePlayer)) {
          RenderUtils.drawString(planet.getName(), 72, -42, Reference.COLOR_HOLO, opacity);
        } else {
          RenderUtils.drawString(
              Minecraft.getMinecraft().standardGalacticFontRenderer,
              planet.getName(),
              72,
              -42,
              Reference.COLOR_HOLO,
              opacity);
        }

        RenderUtils.applyColorWithMultipy(Reference.COLOR_HOLO, opacity);
        ClientProxy.holoIcons.renderIcon("icon_size", 72, -28);
        RenderUtils.drawString(
            DecimalFormat.getPercentInstance().format(planet.getSize()),
            92,
            -23,
            Reference.COLOR_HOLO,
            opacity);
      }

      glDisable(GL_TEXTURE_2D);
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      Tessellator.instance.startDrawingQuads();
      for (int i = 0; i < 10; i++) {
        double step = 64d / 10d;
        double x = step * i;
        double y = -10;
        double height = 64 * (0.5 * random.nextGaussian() + 1d) / 2d;
        Tessellator.instance.addVertex(x, y, 0);
        Tessellator.instance.addVertex(x + step - 1, y, 0);
        Tessellator.instance.addVertex(x + step - 1, y - height, 0);
        Tessellator.instance.addVertex(x, y - height, 0);
      }
      Tessellator.instance.draw();
      glEnable(GL_TEXTURE_2D);
    }
  }
  public boolean renderWorldBlock(
      IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer) {
    YC_DelayedUpdatesManager.AddOre(x, y, z);

    if (Math.abs(mc.thePlayer.posX - x)
            + Math.abs(mc.thePlayer.posY - y)
            + Math.abs(mc.thePlayer.posZ - z)
        > YC_Options.RenderDistance) return true;

    // TODO color gradience
    GL11.glPushAttrib(GL11.GL_TEXTURE_BIT);
    Tessellator.instance.draw();
    GL11.glPushMatrix();
    if (!YC_Options.EnableOptifineCompability) {
      ResetTranslation(x, y, z);
      // GL11.glTranslatef(x, y+0.001f, z+1);
    }

    GL11.glColor4f(1f, 1f, 1f, 1f);

    YC_Mod.m_Ore.Draw(YC_Constants.RemainsTextureID, x, y + 0.001f, z + 1);
    if (YC_Options.RenderContourSecondPass) {
      GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_LINE);
      GL11.glColor3f(0.25f, 0.25f, 0.25f);
      YC_Mod.m_Ore.Draw(YC_Constants.RemainsTextureID, x, y, z + 1);
      GL11.glPolygonMode(GL11.GL_FRONT, GL11.GL_FILL);
    }

    GL11.glPopMatrix();
    GL11.glPopAttrib();

    Tessellator.instance.startDrawingQuads();

    GL11.glColor3f(1f, 1f, 1f);
    return true;
  }
 private void drawPlanetOrbit(Planet planet, double radius) {
   glDisable(GL_TEXTURE_2D);
   glPolygonMode(GL_FRONT, GL_LINE);
   Tessellator.instance.startDrawing(GL_LINES);
   Tessellator.instance.setColorRGBA_F(
       Planet.getGuiColor(planet).getFloatR() * 0.1f,
       Planet.getGuiColor(planet).getFloatG() * 0.1f,
       Planet.getGuiColor(planet).getFloatB() * 0.1f,
       Planet.getGuiColor(planet).getFloatA() * 0.1f);
   for (int i = 0; i < 32; i++) {
     double angleStep = (Math.PI * 2) / 32;
     Tessellator.instance.addVertex(
         Math.sin(angleStep * i) * radius, 0, Math.cos(angleStep * i) * radius);
     Tessellator.instance.addVertex(
         Math.sin(angleStep * (i + 1)) * radius, 0, Math.cos(angleStep * (i + 1)) * radius);
   }
   Tessellator.instance.draw();
 }
Пример #9
0
  // TODO: considering this is all really GL code perhaps we could instead call a 'visualize'
  // function in a drawer and pass it the fft.
  public void visualizer() {
    glEnable(GL_BLEND);
    glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
    glColor4d(1, 1, 1, .2);
    glPolygonMode(GL_FRONT, GL_FILL);
    int w = (int) getFftLog().specSize() / bands;
    int q = Constants.VIEW_HEIGHT;

    for (int i = 0; i < getFftLog().avgSize(); i++) {
      glBegin(GL_POLYGON);
      glVertex2d(i * w, q);
      glVertex2d(i * w + w, q);
      glVertex2d(i * w + w, q - (getFftLog().getAvg(i) * 1));
      glVertex2d(i * w, q - (getFftLog().getAvg(i) * 1));
      glEnd();
    }

    glDisable(GL_BLEND);
  }
Пример #10
0
  public void drawLineBox(int x0, int y0, int x1, int y1, boolean stippled) {
    //    glPushMatrix();
    glPushAttrib(GL_ENABLE_BIT);
    glPushAttrib(GL_POLYGON_BIT);
    glPushAttrib(GL_CURRENT_BIT);
    glDisable(GL_LIGHTING);
    if (stippled) {
      glLineStipple(1, (short) 0xAAAA);
      glEnable(GL_LINE_STIPPLE);
    }
    glDisable(GL_TEXTURE_2D);
    glColor3d(1.0, 1.0, 1.0); // White is nice

    glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
    // GL11.glRecti(iMouseX, iMouseY, mouseX , mouseY);
    glRecti(x0, y0, x1, y1);

    glPopAttrib();
    glPopAttrib();
    glPopAttrib();
  }
  @Override
  public void renderBody(
      Galaxy galaxy,
      SpaceBody spaceBody,
      TileEntityMachineStarMap starMap,
      float partialTicks,
      float distance) {
    if (spaceBody instanceof Star) {

      Star star = (Star) spaceBody;
      random.setSeed(star.getSeed());

      double time = Minecraft.getMinecraft().theWorld.getWorldTime();

      glPushMatrix();
      glScaled(star.getSize(), star.getSize(), star.getSize());

      bindTexture(ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
      Tessellator.instance.startDrawingQuads();
      RenderUtils.tessalateParticle(
          Minecraft.getMinecraft().renderViewEntity,
          star_icon,
          star.getSize(),
          Vec3.createVectorHelper(0, 0, 0),
          Reference.COLOR_HOLO_YELLOW.getFloatR() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatG() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatB() * 0.1f,
          Reference.COLOR_HOLO_YELLOW.getFloatA() * 0.1f);
      Tessellator.instance.draw();

      RenderUtils.applyColorWithMultipy(new GuiColor(star.getColor()), 0.25f * (1f / distance));
      glPolygonMode(GL_FRONT, GL_LINE);
      glDisable(GL_TEXTURE_2D);
      double s = 0.9 + Math.sin(time * 0.01) * 0.1;
      glScaled(s, s, s);
      sphere_model.renderAll();
      glPolygonMode(GL_FRONT, GL_POINT);
      glPointSize(10 / (float) Math.max(0.1, distance));

      sphere_model.renderAll();
      if (Minecraft.getMinecraft().theWorld.getWorldTime() % 120 > 80) {
        double t = ((Minecraft.getMinecraft().theWorld.getWorldTime() % 120) - 80) / 40d;
        RenderUtils.applyColorWithMultipy(
            Reference.COLOR_HOLO_YELLOW, (float) MOMathHelper.easeIn(1 - t, 0, 0.1, 1));
        s = MOMathHelper.easeIn(t, 0.0, 10, 1);
        glScaled(1 + s, 1 + s, 1 + s);
        sphere_model.renderAll();
      }
      glPopMatrix();
      glPolygonMode(GL_FRONT, GL_LINE);

      int planetID = 0;
      for (Planet planet : star.getPlanets()) {
        float sizeMultiply = 1;
        if (starMap.getDestination().equals(planet)) {
          sizeMultiply = 1.2f;
        }

        glDisable(GL_ALPHA_TEST);
        GuiColor planetColor = Planet.getGuiColor(planet);
        random.setSeed(planet.getSeed());

        glPushMatrix();
        double axisRotation = random.nextInt(30) - 15;
        glRotated(axisRotation, 1, 0, 0);
        double radius = planet.getOrbit() * 2 + (star.getSize() / 2 + 0.1);
        float planetSize = planet.getSize();
        drawPlanetOrbit(planet, radius);

        glTranslated(
            Math.sin(time * 0.001 + 10 * planetID) * radius,
            0,
            Math.cos(time * 0.001 + 10 * planetID) * radius);

        glPolygonMode(GL_FRONT, GL_FILL);
        glEnable(GL_TEXTURE_2D);

        if (starMap.getDestination().equals(planet)) {
          bindTexture(
              ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
          Tessellator.instance.startDrawingQuads();
          RenderUtils.tessalateParticle(
              Minecraft.getMinecraft().renderViewEntity,
              selectedIcon,
              planet.getSize() * 0.15f * sizeMultiply,
              Vec3.createVectorHelper(0, 0, 0),
              planetColor);
          Tessellator.instance.draw();
        }

        if (starMap.getGalaxyPosition().equals(planet)) {
          bindTexture(
              ClientProxy.renderHandler.getRenderParticlesHandler().getAdditiveTextureSheet());
          Tessellator.instance.startDrawingQuads();
          RenderUtils.tessalateParticle(
              Minecraft.getMinecraft().renderViewEntity,
              currentIcon,
              planet.getSize() * 0.25f,
              Vec3.createVectorHelper(0, 0, 0),
              planetColor);
          Tessellator.instance.draw();
        }

        glPushMatrix();
        glRotated(-axisRotation, 1, 0, 0);
        RenderUtils.rotateTo(Minecraft.getMinecraft().renderViewEntity);
        drawPlanetInfo(planet);
        glPopMatrix();
        glPolygonMode(GL_FRONT, GL_LINE);
        glDisable(GL_TEXTURE_2D);

        RenderUtils.applyColorWithMultipy(planetColor, 0.3f * (1f / distance));
        glRotated(100, 1, 0, 0);
        glRotated(time * 2, 0, 0, 1);
        sphere.draw(
            planetSize * 0.1f * sizeMultiply,
            (int) (16 + planetSize * 2),
            (int) (8 + planetSize * 2));
        planetID++;
        glPopMatrix();
      }
      glEnable(GL_TEXTURE_2D);
      glPolygonMode(GL_FRONT, GL_FILL);
    }
  }
Пример #12
0
  @Override
  public void update(Engine engine, double time, double dt) {
    Window window = engine.getGlobal(Window.class);
    window.closing = Display.isCloseRequested();
    if (Display.wasResized()) {
      window.width = Display.getWidth();
      window.height = Display.getHeight();
    }

    KeyboardComponent keyboard = engine.getGlobal(KeyboardComponent.class);
    Keyboard.poll();
    for (int i = 0; i < keyboard.down.length; i++) {
      keyboard.pressed[i] = false;
      keyboard.released[i] = false;
      keyboard.down[i] = Keyboard.isKeyDown(i);
    }
    while (Keyboard.next()) {
      int key = Keyboard.getEventKey();
      keyboard.pressed[key] = Keyboard.getEventKeyState();
      keyboard.released[key] = !keyboard.pressed[key];
    }

    MouseComponent mouse = engine.getGlobal(MouseComponent.class);
    Mouse.poll();
    for (int i = 0; i < Mouse.getButtonCount(); i++) {
      mouse.pressed[i] = false;
      mouse.pressed[i] = false;
      mouse.down[i] = Mouse.isButtonDown(i);
      mouse.dx = 0;
      mouse.dy = 0;
    }
    while (Mouse.next()) {
      int btn = Mouse.getEventButton();
      if (btn != -1) {
        mouse.pressed[btn] = Mouse.getEventButtonState();
        mouse.released[btn] = !mouse.pressed[btn];
      } else {
        mouse.dx += Mouse.getEventDX();
        mouse.dy += Mouse.getEventDY();
      }
      mouse.x = Mouse.getEventX();
      mouse.y = Mouse.getEventY();
    }
    mouse.nx = ((float) mouse.x / (float) window.width) * 2.0f - 1.0f;
    mouse.ny = ((float) mouse.y / (float) window.height) * 2.0f - 1.0f;

    Vec3[] mp = MouseUtils.mouseToWorld(window, engine.getGlobal(Camera.class), mouse);

    mouse.near = mp[0];
    mouse.far = mp[1];

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    for (Map m : objects.values()) {
      m.clear();
    }

    // calculate the world matrix of each renderable,
    // and add them to their respective "shader buckets"
    for (RenderNode node : engine.getNodeList(RenderNode.class)) {
      ID<Entity> id = node.getEntity().getId();
      worlds.put(id, StateUtils.getMatrix(node.state));

      Program program = resourceManager.getProgram(node.renderable.shader);
      Map<ID<Entity>, RenderNode> renderables = objects.get(program);
      if (renderables == null) {
        renderables = new HashMap<>();
        objects.put(program, renderables);
      }
      renderables.put(id, node);
    }

    for (ViewportNode vpnode : engine.getNodeList(ViewportNode.class)) {
      Camera camera = vpnode.camera;
      glViewport(
          (int) (window.width * vpnode.viewport.x),
          (int) (window.height * vpnode.viewport.y),
          (int) (window.width * vpnode.viewport.width),
          (int) (window.height * vpnode.viewport.height));

      // for each shader, draw each object that uses that shader
      for (Map.Entry<Program, Map<ID<Entity>, RenderNode>> e : objects.entrySet()) {
        Program program = e.getKey();
        program.use();
        program.setView(camera.viewMatrix);
        program.setProjection(camera.projection);
        program.setSun(engine.getGlobal(Sun.class).location);
        program.setEye(camera.eye);
        for (Map.Entry<ID<Entity>, RenderNode> e2 : e.getValue().entrySet()) {
          RenderNode node = e2.getValue();
          program.setWorld(worlds.get(e2.getKey()));
          program.setColour(node.renderable.colour);
          program.setOpacity(node.renderable.opacity);
          Mesh mesh = resourceManager.getMesh(node.mesh);
          mesh.draw();
        }
      }

      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      glDisable(GL_CULL_FACE);

      Program program = resourceManager.getProgram("passthrough");
      program.use();
      program.setView(camera.viewMatrix);
      program.setProjection(camera.projection);
      for (BBoxNode node : engine.getNodeList(BBoxNode.class)) {
        program.setWorld(node.bbox.getMatrix());

        Vec3 e = node.bbox.getExtents();

        glBegin(GL_QUADS);
        {
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(e.getX(), e.getY(), -e.getZ());

          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), -e.getY(), -e.getZ());
          glColor3f(1, 0, 1);
          glVertex3f(-e.getX(), e.getY(), -e.getZ());
        }
        glEnd();
      }
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      glEnable(GL_CULL_FACE);
    }

    Display.update();
  }
Пример #13
0
  public void applyRenderState(RenderState state) {
    if (state.isWireframe() && !context.wireframe) {
      glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
      context.wireframe = true;
    } else if (!state.isWireframe() && context.wireframe) {
      glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
      context.wireframe = false;
    }

    if (state.isDepthTest() && !context.depthTestEnabled) {
      glEnable(GL_DEPTH_TEST);
      glDepthFunc(GL_LEQUAL);
      context.depthTestEnabled = true;
    } else if (!state.isDepthTest() && context.depthTestEnabled) {
      glDisable(GL_DEPTH_TEST);
      context.depthTestEnabled = false;
    }

    if (state.isAlphaTest()) {
      setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, state.getAlphaFallOff());
    } else {
      setFixedFuncBinding(FixedFuncBinding.AlphaTestFallOff, 0f); // disable it
    }

    if (state.isDepthWrite() && !context.depthWriteEnabled) {
      glDepthMask(true);
      context.depthWriteEnabled = true;
    } else if (!state.isDepthWrite() && context.depthWriteEnabled) {
      glDepthMask(false);
      context.depthWriteEnabled = false;
    }

    if (state.isColorWrite() && !context.colorWriteEnabled) {
      glColorMask(true, true, true, true);
      context.colorWriteEnabled = true;
    } else if (!state.isColorWrite() && context.colorWriteEnabled) {
      glColorMask(false, false, false, false);
      context.colorWriteEnabled = false;
    }

    if (state.isPointSprite()) {
      logger.log(Level.WARNING, "Point Sprite unsupported!");
    }

    if (state.isPolyOffset()) {
      if (!context.polyOffsetEnabled) {
        glEnable(GL_POLYGON_OFFSET_FILL);
        glPolygonOffset(state.getPolyOffsetFactor(), state.getPolyOffsetUnits());
        context.polyOffsetEnabled = true;
        context.polyOffsetFactor = state.getPolyOffsetFactor();
        context.polyOffsetUnits = state.getPolyOffsetUnits();
      } else {
        if (state.getPolyOffsetFactor() != context.polyOffsetFactor
            || state.getPolyOffsetUnits() != context.polyOffsetUnits) {
          glPolygonOffset(state.getPolyOffsetFactor(), state.getPolyOffsetUnits());
          context.polyOffsetFactor = state.getPolyOffsetFactor();
          context.polyOffsetUnits = state.getPolyOffsetUnits();
        }
      }
    } else {
      if (context.polyOffsetEnabled) {
        glDisable(GL_POLYGON_OFFSET_FILL);
        context.polyOffsetEnabled = false;
        context.polyOffsetFactor = 0;
        context.polyOffsetUnits = 0;
      }
    }
    if (state.getFaceCullMode() != context.cullMode) {
      if (state.getFaceCullMode() == RenderState.FaceCullMode.Off) {
        glDisable(GL_CULL_FACE);
      } else {
        glEnable(GL_CULL_FACE);
      }

      switch (state.getFaceCullMode()) {
        case Off:
          break;
        case Back:
          glCullFace(GL_BACK);
          break;
        case Front:
          glCullFace(GL_FRONT);
          break;
        case FrontAndBack:
          glCullFace(GL_FRONT_AND_BACK);
          break;
        default:
          throw new UnsupportedOperationException(
              "Unrecognized face cull mode: " + state.getFaceCullMode());
      }

      context.cullMode = state.getFaceCullMode();
    }

    if (state.getBlendMode() != context.blendMode) {
      if (state.getBlendMode() == RenderState.BlendMode.Off) {
        glDisable(GL_BLEND);
      } else {
        glEnable(GL_BLEND);
        switch (state.getBlendMode()) {
          case Off:
            break;
          case Additive:
            glBlendFunc(GL_ONE, GL_ONE);
            break;
          case AlphaAdditive:
            glBlendFunc(GL_SRC_ALPHA, GL_ONE);
            break;
          case Color:
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_COLOR);
            break;
          case Alpha:
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
            break;
          case PremultAlpha:
            glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
            break;
          case Modulate:
            glBlendFunc(GL_DST_COLOR, GL_ZERO);
            break;
          case ModulateX2:
            glBlendFunc(GL_DST_COLOR, GL_SRC_COLOR);
            break;
          default:
            throw new UnsupportedOperationException(
                "Unrecognized blend mode: " + state.getBlendMode());
        }
      }

      context.blendMode = state.getBlendMode();
    }

    if (state.isStencilTest()) {
      throw new UnsupportedOperationException(
          "OpenGL 1.1 doesn't support two sided stencil operations.");
    }
  }
Пример #14
0
  /** Boucle de rendu 3D. */
  @Override
  public final void run() {
    // Initialisation
    initGL();
    // Boucle du thread de rendu 3D

    matrice.addInterPoint();
    while (Setting.getView3DStart()) {
      // Si la fenêtre n'est pas fermée
      if (!Display.isCloseRequested()) {

        GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
        GL11.glClearColor(0.6f, 0.9f, 1.0f, 1.0f);
        GL11.glLoadIdentity();

        Sys.initialize();
        time = Sys.getTime();

        dt = (time - lastTime) / 1000.0f;
        setLastInput(getLastInput() + (time - lastTime) / 1000.0f);
        lastTime = time;

        // Positionne la camera avant d'afficher le rendu
        camera.lookThrough();

        // Si le rendu n'est pas en pause
        if (!Setting.getView3DPause()) {
          int colonne = 0, ligne = 0;

          // Affichage de la matrice
          for (ligne = 0; ligne < Setting.getSide(); ligne++) {
            for (colonne = 0; colonne < Setting.getSide(); colonne++) {

              GL11.glColor3f(1.0f, 1.0f, 1.0f);
              // Si le mode Wireframe est activé
              if (Setting.getWireframe()) {
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
              } else {
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_FILL);
              }

              if (Setting.getGradient()) {
                GL11.glBegin(GL11.GL_TRIANGLE_FAN);
                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getAltitude() / Setting.getAltitudeMax(),
                    ((Setting.getAltitudeMax() / this.echelle)
                            - (matrice.getSquare(ligne, colonne).getAltitude() / this.echelle))
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    matrice.getSquare(ligne, colonne).getAltitude() / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());

                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1]
                        / Setting.getAltitudeMax(),
                    (Setting.getAltitudeMax()
                            - matrice.getSquare(ligne, colonne).getCooHautGauche()[1])
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);

                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[1]
                        / Setting.getAltitudeMax(),
                    (Setting.getAltitudeMax()
                            - matrice.getSquare(ligne, colonne).getCooHautDroite()[1])
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);

                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[1]
                        / Setting.getAltitudeMax(),
                    (Setting.getAltitudeMax()
                            - matrice.getSquare(ligne, colonne).getCooBasDroite()[1])
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);

                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[1]
                        / Setting.getAltitudeMax(),
                    (Setting.getAltitudeMax()
                            - matrice.getSquare(ligne, colonne).getCooBasGauche()[1])
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);

                GL11.glColor3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1]
                        / Setting.getAltitudeMax(),
                    (Setting.getAltitudeMax()
                            - matrice.getSquare(ligne, colonne).getCooHautGauche()[1])
                        / Setting.getAltitudeMax(),
                    0);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);
                GL11.glEnd();
              }

              if (Setting.getTexture()) {
                GL11.glEnable(GL11.GL_TEXTURE_2D);
                GL11.glBindTexture(GL11.GL_TEXTURE_2D, matrice.getTextImgFile().getTextureID());
                GL11.glTexParameteri(
                    GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
                GL11.glTexParameteri(
                    GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
                GL11.glEnable(GL11.GL_ALPHA);
                GL11.glEnable(GL11.GL_BLEND);
                GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
                GL11.glBegin(GL11.GL_TRIANGLES);

                float middlePointTextRow =
                    (1.0f / (float) (Setting.getSide() + 1)) * ligne
                        + ((1.0f / (float) (Setting.getSide() + 1)) / 2.0f);
                float middlePointTextCol =
                    (1.0f / (float) (Setting.getSide() + 1)) * (Setting.getSide() + 1 - colonne)
                        - ((1.0f / (float) (Setting.getSide() + 1)) / 2.0f);
                float percent = (1.0f / (float) (Setting.getSide() + 1));

                // Milieu
                GL11.glTexCoord2f(middlePointTextRow, middlePointTextCol);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    matrice.getSquare(ligne, colonne).getAltitude() / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());
                // bas gauche
                GL11.glTexCoord2f(percent * ligne, percent * (Setting.getSide() + 1 - colonne));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);
                // bas droite
                GL11.glTexCoord2f(
                    percent * ligne, percent * (Setting.getSide() + 1 - (colonne + 1)));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);

                // milieu
                GL11.glTexCoord2f(middlePointTextRow, middlePointTextCol);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    matrice.getSquare(ligne, colonne).getAltitude() / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());
                // bas droite
                GL11.glTexCoord2f(
                    percent * ligne, percent * (Setting.getSide() + 1 - (colonne + 1)));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);
                // haut droite
                GL11.glTexCoord2f(
                    percent * (ligne + 1), percent * (Setting.getSide() + 1 - (colonne + 1)));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);

                // milieu
                GL11.glTexCoord2f(middlePointTextRow, middlePointTextCol);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    matrice.getSquare(ligne, colonne).getAltitude() / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());
                // haut droite
                GL11.glTexCoord2f(
                    percent * (ligne + 1), percent * (Setting.getSide() + 1 - (colonne + 1)));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);
                // haut gauche
                GL11.glTexCoord2f(
                    percent * (ligne + 1), percent * (Setting.getSide() + 1 - colonne));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);

                // milieu
                GL11.glTexCoord2f(middlePointTextRow, middlePointTextCol);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    matrice.getSquare(ligne, colonne).getAltitude() / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());
                // haut gauche
                GL11.glTexCoord2f(
                    percent * (ligne + 1), percent * (Setting.getSide() + 1 - colonne));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);
                // bas gauche
                GL11.glTexCoord2f(percent * ligne, percent * (Setting.getSide() + 1 - colonne));
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);

                GL11.glEnd();

              } else {
                GL11.glDisable(GL11.GL_TEXTURE_2D);
              }

              /*
              if (Setting.getTexture()) {
              	GL11.glEnable(GL11.GL_TEXTURE_2D);
              	GL11.glBindTexture(GL11.GL_TEXTURE_2D, textures.getTextureByName(
              		terrains.getTerrainByName(matrice.getSquare(ligne, colonne).getTerrain()).getTexture()).getTextureID());
              	GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
               GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
               GL11.glEnable(GL11.GL_ALPHA);
               GL11.glEnable(GL11.GL_BLEND);
               GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
              	GL11.glBegin(GL11.GL_TRIANGLES);

              	GL11.glTexCoord2f(0.5f, 0.5f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getHauteur(),
              	matrice.getSquare(ligne, colonne).getAltitude(),
              	matrice.getSquare(ligne, colonne).getLargeur());

              	GL11.glTexCoord2f(0.0f, 0.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
              	matrice.getSquare(ligne, colonne).getCooHautGauche()[1],
              	matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);

              	GL11.glTexCoord2f(0.0f, 1.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
              	matrice.getSquare(ligne, colonne).getCooHautDroite()[1],
              	matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);

              	GL11.glTexCoord2f(0.5f, 0.5f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getHauteur(),
              	matrice.getSquare(ligne, colonne).getAltitude(),
              	matrice.getSquare(ligne, colonne).getLargeur());
              	GL11.glTexCoord2f(0.0f, 1.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
              	matrice.getSquare(ligne, colonne).getCooHautDroite()[1],
              	matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);

              	GL11.glTexCoord2f(1.0f, 1.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
              	matrice.getSquare(ligne, colonne).getCooBasDroite()[1],
              	matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);

              	GL11.glTexCoord2f(0.5f, 0.5f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getHauteur(),
              	matrice.getSquare(ligne, colonne).getAltitude(),
              	matrice.getSquare(ligne, colonne).getLargeur());
              	GL11.glTexCoord2f(1.0f, 1.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
              	matrice.getSquare(ligne, colonne).getCooBasDroite()[1],
              	matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);

              	GL11.glTexCoord2f(1.0f, 0.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
              	matrice.getSquare(ligne, colonne).getCooBasGauche()[1],
              	matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);

              	GL11.glTexCoord2f(0.5f, 0.5f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getHauteur(),
              	matrice.getSquare(ligne, colonne).getAltitude(),
              	matrice.getSquare(ligne, colonne).getLargeur());
              	GL11.glTexCoord2f(1.0f, 0.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
              	matrice.getSquare(ligne, colonne).getCooBasGauche()[1],
              	matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);

              	GL11.glTexCoord2f(0.0f, 0.0f);
              	GL11.glVertex3f(matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
              	matrice.getSquare(ligne, colonne).getCooHautGauche()[1],
              	matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);

              	GL11.glEnd();

              }else {
              	GL11.glDisable(GL11.GL_TEXTURE_2D);
              }
               */

              if (Setting.getWind()) {
                GL11.glBegin(GL11.GL_TRIANGLES);
                double[][] tempWind =
                    wind.getLocalWind(ligne, colonne)
                        .trianglevent(
                            ligne * Setting.getSideUnit(),
                            1,
                            colonne * Setting.getSideUnit(),
                            camera.getZoom());

                GL11.glColor3f(
                    Setting.getColorWind().x, Setting.getColorWind().y, Setting.getColorWind().z);
                GL11.glVertex3d(
                    tempWind[0][0],
                    matrice.getSquare(ligne, colonne).getAltitude() + tempWind[0][1],
                    tempWind[0][2]);
                GL11.glVertex3d(
                    tempWind[1][0],
                    matrice.getSquare(ligne, colonne).getAltitude() + tempWind[1][1],
                    tempWind[1][2]);
                GL11.glVertex3d(
                    tempWind[2][0],
                    matrice.getSquare(ligne, colonne).getAltitude() + tempWind[2][1],
                    tempWind[2][2]);
                GL11.glEnd();
              }

              if (matrice.getSquare(ligne, colonne).getActive()) {
                GL11.glPolygonMode(GL11.GL_FRONT_AND_BACK, GL11.GL_LINE);
                GL11.glBegin(GL11.GL_TRIANGLE_FAN);
                GL11.glColor3f(
                    Setting.getColorActive().x,
                    Setting.getColorActive().y,
                    Setting.getColorActive().z);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getHauteur(),
                    (matrice.getSquare(ligne, colonne).getAltitude() + 1) / this.echelle,
                    matrice.getSquare(ligne, colonne).getLargeur());
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautDroite()[2]);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[0],
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasDroite()[2]);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooBasGauche()[2]);
                GL11.glVertex3f(
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[0],
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[1] / this.echelle,
                    matrice.getSquare(ligne, colonne).getCooHautGauche()[2]);
                GL11.glEnd();
              }
            }
          }
        }
        input();

        origin();

        Display.update();

        try {
          Renderer3D.sleep(30);
        } catch (InterruptedException e) {
          e.printStackTrace();
        }
      } else {
        Setting.setView3DStart(false);
        Display.destroy();
      }
    }
  }
Пример #15
0
  public void checkGameInput() {

    if (drawMode.isPressed()) {
      octree.setRenderMode(!octree.isRenderMode());
      octree.setObjectColliding(false);
      if (octree.isRenderMode()) {
        glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); // Render the triangles in fill mode
      } else {
        glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); // Render the triangles in wire frame mode
      }
      octree.createDisplayList(octree, g_World, octree.getDisplayListID());
    }

    if (fullScreen.isPressed()) {
      setFullScreen(!isFullScreen());
    }

    if (enter.isPressed()) {
      Octree.octreeCollisionDetection = !Octree.octreeCollisionDetection;
    }

    if (left.isPressed()) {
      camera.strafe(-SPEED / 10 * elapsedTime);
    }

    if (right.isPressed()) {

      camera.strafe(SPEED / 10 * elapsedTime);
    }

    if (zoomIn.isPressed()) {
      camera.move(+SPEED / 10 * elapsedTime);
    }
    if (zoomOut.isPressed()) {

      camera.move(-SPEED / 10 * elapsedTime);
    }

    if (moveLeft.isPressed()) {
      g_BallEntity.fAngle += (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    if (moveRight.isPressed()) {

      // Rotate the Ball Angle Counter Clockwise.
      g_BallEntity.fAngle -= (float) AR_DegToRad(g_BallEntity.fTurnRate) * elapsedTime;
    }

    // Clamp values above 2 * PI or 360 Deg's.
    if (g_BallEntity.fAngle >= AR_2PI) g_BallEntity.fAngle = g_BallEntity.fAngle - AR_2PI;

    // Clamp values below 0.
    if (g_BallEntity.fAngle < 0.0f) g_BallEntity.fAngle = AR_2PI + g_BallEntity.fAngle;

    if (debug.isPressed()) {
      g_bDisplayNodes = !g_bDisplayNodes;
    }

    if (moveUp.isPressed()) {
      if (g_BallEntity.fVelX + (g_BallEntity.fAccel * elapsedTime) < g_BallEntity.fMaxVel) {
        g_BallEntity.fVelX += g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ += g_BallEntity.fAccel * elapsedTime;
      }
    }
    if (moveDown.isPressed()) {

      // Move the Ball Backwards.
      if (g_BallEntity.fVelX - (g_BallEntity.fAccel * elapsedTime) > g_BallEntity.fMinVel) {
        g_BallEntity.fVelX -= g_BallEntity.fAccel * elapsedTime;
        g_BallEntity.fVelZ -= g_BallEntity.fAccel * elapsedTime;
      }
    }

    // Apply Gravity to this Entity (using time based motion) if he's not colliding with anything.
    if (!octree.isObjectColliding()) g_BallEntity.fVelY += (GRAVITY * elapsedTime);

    // Apply (spherical based) motion.

    g_BallEntity.x +=
        (g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelX) * elapsedTime;
    g_BallEntity.y += g_BallEntity.fVelY * elapsedTime;
    g_BallEntity.z +=
        (g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fVelZ) * elapsedTime;

    // Adjust the Forward I-Sectors Endpoint.
    g_vForwardISector[1].x =
        g_fSinTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;
    g_vForwardISector[1].y = 0.0f;
    g_vForwardISector[1].z =
        g_fCosTable[(int) AR_RadToDeg(g_BallEntity.fAngle)] * g_BallEntity.fRadius * 0.2f;

    // Slow this guy down (friction).
    if (g_BallEntity.fVelX > g_fFriction * elapsedTime) {
      g_BallEntity.fVelX -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ > g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ -= g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelX < g_fFriction * elapsedTime) {
      g_BallEntity.fVelX += g_fFriction * elapsedTime;
    }

    if (g_BallEntity.fVelZ < g_fFriction * elapsedTime) {
      g_BallEntity.fVelZ += g_fFriction * elapsedTime;
    }

    // If this Ball falls outside the world, drop back from the top.
    if (g_BallEntity.y < -30) {
      g_BallEntity.x = g_BallEntity.z = 0.0f;
      g_BallEntity.y = 5.0f;
      g_BallEntity.fVelX = g_BallEntity.fVelY = g_BallEntity.fVelZ = 0.0f;
    }

    Vector3f[] vGroundLine = {new Vector3f(), new Vector3f()};
    Vector3f[] vForwardLine = {new Vector3f(), new Vector3f()};

    // Prepare a Temporary line transformed to the Balls exact world position.
    vGroundLine[0].x = g_BallEntity.x + g_vGroundISector[0].x;
    vGroundLine[0].y = g_BallEntity.y + g_vGroundISector[0].y;
    vGroundLine[0].z = g_BallEntity.z + g_vGroundISector[0].z;

    vGroundLine[1].x = g_BallEntity.x + g_vGroundISector[1].x;
    vGroundLine[1].y = g_BallEntity.y + g_vGroundISector[1].y;
    vGroundLine[1].z = g_BallEntity.z + g_vGroundISector[1].z;

    // Prepare a Temporary line transformed to the Balls exact world position.
    vForwardLine[0].x = g_BallEntity.x + g_vForwardISector[0].x;
    vForwardLine[0].y = g_BallEntity.y + g_vForwardISector[0].y;
    vForwardLine[0].z = g_BallEntity.z + g_vForwardISector[0].z;

    vForwardLine[1].x = g_BallEntity.x + g_vForwardISector[1].x;
    vForwardLine[1].y = g_BallEntity.y + g_vForwardISector[1].y;
    vForwardLine[1].z = g_BallEntity.z + g_vForwardISector[1].z;

    // A temporary Vector holding the Intersection Point of our Intersection Check.
    vIntersectionPt = new Vector3f();

    // Reset the Status of the Object (wheter it is colliding or not).
    octree.setObjectColliding(false);

    // Reset the Nodes collided to zero so we can start with a fresh count.
    Octree.numNodesCollided = 0;

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vGroundLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }

    // Test the line for an intersection with the Octree Geometry.
    if (octree.intersectLineWithOctree(octree, g_World, vForwardLine, vIntersectionPt)) {
      // Move the Ball up from the point at which it collided with the ground. This is what
      // ground clamping is!
      g_BallEntity.x = vIntersectionPt.x;
      // NOTE: Make sure it is above the surface, AND half it's height (so it isn't half
      // underground).
      // This would only apply if you placed entity's by their exact center.
      g_BallEntity.y = vIntersectionPt.y + g_BallEntity.fRadius;
      g_BallEntity.z = vIntersectionPt.z;

      // Stop your up-down velocity.
      g_BallEntity.fVelY = 0.0f;
    }
  }