コード例 #1
0
ファイル: RenderUtils.java プロジェクト: nemtos/Planets
 public static void init(int width, int height) {
   setupView(width, height);
   sphere = new Sphere();
   sphere.setDrawStyle(GLU_FILL);
   sphere.setTextureFlag(true);
   sphere.setNormals(GLU_SMOOTH);
 }
コード例 #2
0
  public static void renderSphereGeometry() {
    if (displayListSphere == -1) {
      displayListSphere = glGenLists(1);

      Sphere sphere = new Sphere();

      glNewList(displayListSphere, GL11.GL_COMPILE);

      sphere.draw(1, 8, 8);

      glEndList();
    }

    glCallList(displayListSphere);
  }
コード例 #3
0
  private void render(Entity e) {
    Vector pos = e.getPosition();
    // System.out.println(e.getId() + ": ( " + pos.getVar(0) + ", " + pos.getVar(1) + " )");
    glLoadIdentity();

    double x = pos.getVar(0);
    double y = (pos.getDimensions() > 1) ? pos.getVar(1) : 0;
    glTranslated(x, y, 100.0f);

    Color c = getColor(e);
    glColor3b((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue());

    Sphere s = new Sphere();
    s.draw((float) e.getRadius(), 20, 16);
  }
コード例 #4
0
ファイル: RenderUtils.java プロジェクト: nemtos/Planets
 public static int prepareSphere(int texId, float size) {
   int list = glGenLists(1);
   glNewList(list, GL_COMPILE);
   glBindTexture(GL_TEXTURE_2D, texId);
   sphere.draw(size, Config.details, Config.details);
   glEndList();
   return list;
 }
コード例 #5
0
ファイル: SphereModel.java プロジェクト: Tamaran/Game
 /** Applys the Material and renders the Sphere */
 public void render() {
   m.apply();
   s.draw(1, slices, stacks);
 }
コード例 #6
0
ファイル: Testesala.java プロジェクト: yuripourre/exemplwjgl
  protected void render() {

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer

    glLoadIdentity();

    camera.look();

    // Each frame we calculate the new frustum.  In reality you only need to
    // calculate the frustum when we move the camera.
    GameCore.gFrustum.calculateFrustum();

    // Initialize the total node count that is being draw per frame
    Octree.totalNodesDrawn = 0;

    glPushMatrix();
    // Here we draw the octree, starting with the root node and recursing down each node.
    // This time, we pass in the root node and just the original world model.  You could
    // just store the world in the root node and not have to keep the original data around.
    // This is up to you.  I like this way better because it's easy, though it could be
    // more error prone.
    octree.drawOctree(octree, g_World);
    glPopMatrix();

    // Render the cubed nodes to visualize the octree (in wire frame mode)
    if (g_bDisplayNodes) Octree.debug.drawBoundingBox();

    glPushMatrix();
    // If there was a collision, make the Orange ball Red.
    if (octree.isObjectColliding()) {
      glColor3f(1.0f, 0.0f, 0.0f);
    } else {
      glColor3f(1.0f, 0.5f, 0.0f); // Disable Lighting.
    }
    // Move the Ball into place.
    glTranslatef(g_BallEntity.x, g_BallEntity.y, g_BallEntity.z);

    glDisable(GL_LIGHTING);
    // Draw the Ground Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 1);
    glVertex3f(g_vGroundISector[0].x, g_vGroundISector[0].y, g_vGroundISector[0].z);
    glVertex3f(g_vGroundISector[1].x, g_vGroundISector[1].y, g_vGroundISector[1].z);
    glEnd();

    // Draw the Forward Intersection Line.
    glBegin(GL_LINES);
    glColor3f(1, 1, 0);
    glVertex3f(
        g_vForwardISector[0].x * 10.0f, g_vForwardISector[0].y, g_vForwardISector[0].z * 10.0f);
    glVertex3f(
        g_vForwardISector[1].x * 10.0f, g_vForwardISector[1].y, g_vForwardISector[1].z * 10.0f);
    glEnd();

    // Re-enable lighting.
    glEnable(GL_LIGHTING);

    // System.out.println("x " + g_BallEntity.x + " y " + g_BallEntity.y);
    // Draw it!
    pObj.draw(g_BallEntity.fRadius, 20, 20);

    glPopMatrix();

    screen.setTitle(
        "Triangles: "
            + Octree.maxTriangles
            + "  -Total Draw: "
            + Octree.totalNodesDrawn
            + "  -Subdivisions: "
            + Octree.maxSubdivisions
            + "  -FPS: "
            + FPSCounter.get()
            + "  -Node Collisions: "
            + Octree.numNodesCollided
            + "  -Object Colliding? "
            + octree.isObjectColliding());
  }
コード例 #7
0
ファイル: Testesala.java プロジェクト: yuripourre/exemplwjgl
  @Override
  public void init() throws IOException {

    super.init();
    camera = new Camera(true);
    camera.setPosition(-17f, 20f, 17f, 0, 0, 0, 0, 1, 0);
    float df = 100.0f;

    // Precalculate the Sine and Cosine Lookup Tables.
    // Basically, loop through 360 Degrees and assign the Radian
    // value to each array index (which represents the Degree).
    for (int i = 0; i < 360; i++) {
      g_fSinTable[i] = (float) Math.sin(AR_DegToRad(i));
      g_fCosTable[i] = (float) Math.cos(AR_DegToRad(i));
    }

    pObj = new Sphere();
    pObj.setOrientation(GLU_OUTSIDE);

    Octree.debug = new BoundingBox();
    // Turn lighting on initially
    Octree.turnLighting = true;

    // The current amount of end nodes in our tree (The nodes with vertices stored in them)
    Octree.totalNodesCount = 0;

    // This stores the amount of nodes that are in the frustum
    Octree.totalNodesDrawn = 0;

    // The maximum amount of triangles per node.  If a node has equal or less
    // than this, stop subdividing and store the face indices in that node
    Octree.maxTriangles = 800;

    // The maximum amount of subdivisions allowed (Levels of subdivision)
    Octree.maxSubdivisions = 5;

    // The number of Nodes we've checked for collision.
    Octree.numNodesCollided = 0;

    // Wheter the Object is Colliding with anything in the World or not.
    octree.setObjectColliding(false);

    // Wheter we test the whole world for collision or just the nodes we are in.
    Octree.octreeCollisionDetection = true;

    LoadWorld();

    // for(int i=0; i < g_World.getNumOfMaterials(); i++)
    // {
    //	System.out.println(g_World.getMaterials(i).getName() + " indice " + i);

    // }

    // for(int i=0; i < g_World.getNumOfObjects(); i++)
    // {
    //	System.out.println(g_World.getObject(i).getName());
    //	System.out.println(g_World.getObject(i).getMaterialID());
    // System.out.println(g_World.getPObject(i).getMaterialID());
    // }

    // System.out.println(g_World.getPMaterials(12).getColor()[0] + " " +
    // g_World.getPMaterials(12).getColor()[1]
    //                    + " " + g_World.getPMaterials(12).getColor()[2]);
    // System.out.println(g_World.getPMaterials(g_World.getPObject(6).getMaterialID()));

    inputManager = new InputManager();

    createGameActions();

    posLuz1F = Conversion.allocFloats(posLuz1);

    // Define a cor de fundo da janela de visualização como preto
    glClearColor(0, 0, 0, 1);

    // Ajusta iluminação
    glLight(GL_LIGHT0, GL_AMBIENT, Conversion.allocFloats(luzAmb1));
    glLight(GL_LIGHT0, GL_DIFFUSE, Conversion.allocFloats(luzDif1));
    glLight(GL_LIGHT0, GL_SPECULAR, Conversion.allocFloats(luzEsp1));

    // Habilita todas as fontes de luz
    glEnable(GL_LIGHT0);

    glEnable(GL_LIGHTING);
    // Agora posiciona demais fontes de luz
    glLight(GL_LIGHT0, GL_POSITION, posLuz1F);

    // Habilita Z-Buffer
    glEnable(GL_DEPTH_TEST);

    // Seleciona o modo de GL_COLOR_MATERIAL
    // glColorMaterial(GL_FRONT, GL_DIFFUSE);
    glEnable(GL_COLOR_MATERIAL);
    glMaterial(GL_FRONT, GL_SPECULAR, Conversion.allocFloats(spec));
    glMaterialf(GL_FRONT, GL_SHININESS, df);
  }