md3.md3view
Class MD3GLCanvas

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Canvas
              |
              +--gl4java.awt.GLCanvas
                    |
                    +--gl4java.awt.GLAnimCanvas
                          |
                          +--md3.md3view.MD3GLCanvas

public class MD3GLCanvas
extends gl4java.awt.GLAnimCanvas

OpenGL Canvas with functionality to render MD3 models and MD3GLTextures.

It will also react to mouseDragged events. If you drag with the first mouse button and don't hold the shift key, you will rotate the model. Dragging the first mouse button while holding down shift will pan the model in the x-y plane. Dragging with the third mouse button scales the model.

Author:
Erwin Vervaet (erwin@cs.kuleuven.ac.be)
See Also:
Serialized Form

Field Summary
static int FLAT_SHADED
          Flat shaded render mode.
static int FLAT_TEXTURED
          Flat textured render mode.
static int MODEL_MODE
          Model rendering mode.
static int SHADED_TEXTURED
          Shaded textured render mode.
static int TEXTURE_MODE
          Texture rendering mode.
static int WIRE_FRAME
          Wire frame render mode.
 
Fields inherited from class gl4java.awt.GLAnimCanvas
dFpsMilli, FramesPerSec, killme, mSecPerFrame, shallWeRender, threadSuspended, useFpsSleep, useRepaint
 
Fields inherited from class gl4java.awt.GLCanvas
_f_dur, cvsInitialized, doubleBuffer, gl, glj, glu, mustResize, needCvsDispose, size, stereoView, topLevelWindow
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Constructor Summary
MD3GLCanvas(int width, int height)
          Constructor that creates a new MD3 OpenGL Canvas with the specified width and height.
 
Method Summary
 void activateRenderMode()
          Activate the current rendering mode.
 void display()
          Override needed when using GLCanvas: render 1 frame, called by paint.
 void dumpCanvasToTGA(java.lang.String filename)
          Dump the image on the canvas to a Targa file.
 MD3Animation getAnimation()
          Return the currently active animation of the canvas.
protected  gl4java.GLFunc getGL()
          Return a GLFunc object that you can use to draw something on this canvas.
protected  gl4java.GLUFunc getGLU()
          Return the canvas's GLUFunc object.
 int getMode()
          Return the current mode of operation of this canvas (TEXTURE_MODE or MODEL_MODE).
 MD3Model getModel()
          Return the top level model rendered on this canvas.
 int getRenderMode()
          Returns the currently used rendering mode.
 MD3GLTexture getTexture()
          Return the current texture (rendered in TEXTURE_MODE) of this canvas.
 void init()
          Override needed when using GLCanvas: create java-stuff and do GL-inits.
 void nextFrame()
          Switch to the next frame in the current animation of the model.
 void previousFrame()
          Switch to the previous frame in the current animation.
 void ReInit()
          Override needed when using GLAnimCanvas: re-initialisation after stop for setSuspended(false).
 void resetManipulations()
          Reset all user manipulations (scaling + panning + rotating) of this model canvas.
 void reshape(int width, int height)
          Override needed when using GLCanvas: resize canvas.
 void rewindAnimation()
          Rewind the animation of the model back to the first frame.
 void setAnimate(boolean b)
          Start or stop the currently selected animation of the displayed model.
 void setAnimation(MD3Animation anim)
          Set the animation of the model that will be displayed on the canvas.
 void setInterpolate(boolean b)
          Enable or disable interpolation between key animation frames.
 void setMode(int mode)
          Set the operation mode of the canvas.
 void setModel(MD3Model model)
          Set the top level model that is rendered on the canvas.
 void setRenderMode(int rendermode)
          Switch the display to the specified render mode.
 void setTexture(MD3GLTexture texture)
          Set the texture that will be rendered on the canvas.
 
Methods inherited from class gl4java.awt.GLAnimCanvas
getFps, getFpsDuration, getFpsFrames, getMaxFps, getUseFpsSleep, getUseRepaint, isAlive, isSuspended, resetFpsCounter, run, setAnimateFps, setAnimateFps, setSuspended, setSuspended, setUseFpsSleep, setUseRepaint, setVerboseFps, start, stop, stopFpsCounter
 
Methods inherited from class gl4java.awt.GLCanvas
componentHidden, componentMoved, componentResized, componentShown, cvsDispose, cvsGetHeight, cvsGetWidth, cvsIsInit, doCleanup, getGLContext, getMinimumSize, getPreferredSize, getTopLevelWindow, paint, preInit, sDisplay, update, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
 
Methods inherited from class java.awt.Canvas
addNotify
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, deliverEvent, disable, disableEvents, dispatchEvent, doLayout, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, paramString, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, processComponentEvent, processEvent, processFocusEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFont, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MODEL_MODE

public static final int MODEL_MODE

Model rendering mode. The current MD3 model will be rendered.


TEXTURE_MODE

public static final int TEXTURE_MODE

Texture rendering mode. The current texture will be rendered.


WIRE_FRAME

public static final int WIRE_FRAME

Wire frame render mode.


FLAT_SHADED

public static final int FLAT_SHADED

Flat shaded render mode.


FLAT_TEXTURED

public static final int FLAT_TEXTURED

Flat textured render mode.


SHADED_TEXTURED

public static final int SHADED_TEXTURED

Shaded textured render mode.

Constructor Detail

MD3GLCanvas

public MD3GLCanvas(int width,
                   int height)

Constructor that creates a new MD3 OpenGL Canvas with the specified width and height. It also sets up the required listeners for the mouseDragged events.

By default, animation and quick manipulations are off, interpolation is on, bone frames or not drawn and the mode is MODEL_MODE.

Parameters:
width - Width of the canvas.
height - Height of the canvas.
Method Detail

getGL

protected gl4java.GLFunc getGL()

Return a GLFunc object that you can use to draw something on this canvas.

Returns:
GLFunc object of this GLCanvas.

getGLU

protected gl4java.GLUFunc getGLU()

Return the canvas's GLUFunc object.


display

public void display()

Override needed when using GLCanvas: render 1 frame, called by paint.

Overrides:
display in class gl4java.awt.GLAnimCanvas

reshape

public void reshape(int width,
                    int height)

Override needed when using GLCanvas: resize canvas.

Overrides:
reshape in class gl4java.awt.GLCanvas

init

public void init()

Override needed when using GLCanvas: create java-stuff and do GL-inits.

Overrides:
init in class gl4java.awt.GLAnimCanvas

ReInit

public void ReInit()

Override needed when using GLAnimCanvas: re-initialisation after stop for setSuspended(false).

Overrides:
ReInit in class gl4java.awt.GLAnimCanvas

resetManipulations

public void resetManipulations()

Reset all user manipulations (scaling + panning + rotating) of this model canvas.


setModel

public void setModel(MD3Model model)

Set the top level model that is rendered on the canvas. This will reset any manipulation that have been done on the canvas (rotate + pan + scale). The canvas will switch to MODEL_MODE.

Uploading of texture data to OpenGL is the responsability of the client!

Parameters:
model - The MD3Model to render.

getModel

public MD3Model getModel()

Return the top level model rendered on this canvas.

Returns:
The current MD3Model of the canvas.

setTexture

public void setTexture(MD3GLTexture texture)

Set the texture that will be rendered on the canvas. This will reset any manipulations and switch to TEXTURE_MODE.

Uploading of texture data to OpenGL is the responsability of the client!


getTexture

public MD3GLTexture getTexture()

Return the current texture (rendered in TEXTURE_MODE) of this canvas.


setMode

public void setMode(int mode)

Set the operation mode of the canvas. In MODEL_MODE, an MD3Model will be rendered. When in TEXTURE_MODE, a MD3GLTexture object will be shown.


getMode

public int getMode()

Return the current mode of operation of this canvas (TEXTURE_MODE or MODEL_MODE).


setAnimate

public void setAnimate(boolean b)

Start or stop the currently selected animation of the displayed model.

Parameters:
b - true will start the animation, false will stop it.

setAnimation

public void setAnimation(MD3Animation anim)

Set the animation of the model that will be displayed on the canvas.

Parameters:
anim - The animation to play.

getAnimation

public MD3Animation getAnimation()

Return the currently active animation of the canvas.


nextFrame

public void nextFrame()

Switch to the next frame in the current animation of the model.


previousFrame

public void previousFrame()

Switch to the previous frame in the current animation.


rewindAnimation

public void rewindAnimation()

Rewind the animation of the model back to the first frame.


setInterpolate

public void setInterpolate(boolean b)

Enable or disable interpolation between key animation frames.


setRenderMode

public void setRenderMode(int rendermode)

Switch the display to the specified render mode. The supported rendering modes are: WIRE_FRAME, FLAT_SHADED, FLAT_TEXTURED and SHADED_TEXTURED.

Note that the new rendermode will only become active after a call to the activateRenderMode() method.

This method will have no effect when the canvas is in TEXTURE_MODE.

Parameters:
rendermode - The render mode to swith to.

activateRenderMode

public void activateRenderMode()

Activate the current rendering mode.


getRenderMode

public int getRenderMode()

Returns the currently used rendering mode.


dumpCanvasToTGA

public void dumpCanvasToTGA(java.lang.String filename)
                     throws java.io.IOException

Dump the image on the canvas to a Targa file.

Parameters:
filename - Name of the output file.