Package ponkOut.graphics

Source Code of ponkOut.graphics.PaddleGO

/* Copyright 2010 Christian Matt
*
* This file is part of PonkOut.
*
* PonkOut is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* PonkOut is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with PonkOut.  If not, see <http://www.gnu.org/licenses/>.
*/

package ponkOut.graphics;

import org.lwjgl.opengl.GL11;
import org.lwjgl.util.glu.Cylinder;
import org.lwjgl.util.glu.Sphere;
import org.lwjgl.util.vector.Vector2f;
import org.lwjgl.util.vector.Vector3f;

import ponkOut.logic.Paddle;

public class PaddleGO extends WorldObject {
  private final static Material[] PADDLE_MATERIAL = {
      new Material(0.2f, 0.2f, 1.0f, 0.1f, 0.1f, 0.5f, 0.9f, 0.9f, 0.5f, 1.0f, 20.0f),
      new Material(1.0f, 0.2f, 0.2f, 0.5f, 0.1f, 0.1f, 0.5f, 0.9f, 0.9f, 1.0f, 20.0f),
      new Material(0.2f, 1.0f, 0.2f, 0.1f, 0.5f, 0.1f, 0.9f, 0.5f, 0.9f, 1.0f, 20.0f),
      new Material(1.0f, 1.0f, 0.2f, 0.5f, 0.5f, 0.1f, 0.5f, 0.5f, 0.9f, 1.0f, 20.0f),
      new Material(1.0f, 0.2f, 1.0f, 0.5f, 0.1f, 0.5f, 0.5f, 0.9f, 0.5f, 1.0f, 20.0f),
      new Material(0.2f, 1.0f, 1.0f, 0.1f, 0.5f, 0.5f, 0.9f, 0.5f, 0.5f, 1.0f, 20.0f) };

  private Paddle paddle;

  private Cylinder c;
  private Sphere sphere;

  public PaddleGO(Paddle paddle, Material material, GraphicsObjectsManager goManager) {
    super(material, goManager);
    this.paddle = paddle;

    c = new Cylinder();
    sphere = new Sphere();
  }

  public static Material getMaterial(int index) {
    return PADDLE_MATERIAL[index];
  }

  @Override
  public void draw() {
    // store current transformation matrix
    GL11.glPushMatrix();

    float length = paddle.getLength();
    Vector2f pos = paddle.getPosition();

    // move and rotate paddle
    switch (paddle.getPlace()) {
    case LEFT:
    case RIGHT:
      GL11.glTranslatef(pos.x, pos.y - length / 2.0f, 0.0f);
      GL11.glRotatef(90.0f, 0.0f, 0.0f, 1.0f);
      GL11.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
      break;

    case TOP:
    case BOTTOM:
      GL11.glTranslatef(pos.x - length / 2.0f, pos.y, 0.0f);
      GL11.glRotatef(90.0f, 0.0f, 1.0f, 0.0f);
      break;
    }

    // enable lighting
    Lighting.enable(false);

    // set material
    appearance.use();

    // draw it
    // do not use display lists because length can change
    float radius = paddle.getRadius();
    c.draw(radius, radius, length, 8, 1);
    sphere.draw(radius, 8, 8);
    GL11.glTranslatef(0.0f, 0.0f, length);
    sphere.draw(radius, 8, 8);

    // disable lighting
    Lighting.disable();

    // restore transformation matrix
    GL11.glPopMatrix();
  }

  @Override
  public Vector3f getPosition() {
    Vector2f pos = paddle.getPosition();
    return new Vector3f(pos.x, pos.y, 0.0f);
  }
}
TOP

Related Classes of ponkOut.graphics.PaddleGO

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.