formatting issues
This commit is contained in:
parent
828f61a3aa
commit
f359b78801
|
@ -9,8 +9,9 @@ import org.lwjgl.opengl.*;
|
||||||
import org.lwjgl.input.*;
|
import org.lwjgl.input.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* $Id$<br>This test
|
* $Id$
|
||||||
* demonstrates OpenAL positioning Based on the example by Chad Armstrong
|
* <br>
|
||||||
|
* This test demonstrates OpenAL positioning Based on the example by Chad Armstrong
|
||||||
* (http://www.edenwaith.com/products/pige/tutorials/openal.php)
|
* (http://www.edenwaith.com/products/pige/tutorials/openal.php)
|
||||||
*
|
*
|
||||||
* @author Brian Matzon <brian@matzon.dk>
|
* @author Brian Matzon <brian@matzon.dk>
|
||||||
|
@ -18,466 +19,463 @@ import org.lwjgl.input.*;
|
||||||
*/
|
*/
|
||||||
public class PositionTest extends BasicTest {
|
public class PositionTest extends BasicTest {
|
||||||
|
|
||||||
/** *Small* glut implementation :) */
|
/** *Small* glut implementation :) */
|
||||||
private GLUT glut;
|
private GLUT glut;
|
||||||
|
|
||||||
/** Width of window */
|
/** Width of window */
|
||||||
public static final int WINDOW_WIDTH = 640;
|
public static final int WINDOW_WIDTH = 640;
|
||||||
|
|
||||||
/** Height of window */
|
/** Height of window */
|
||||||
public static final int WINDOW_HEIGHT = 480;
|
public static final int WINDOW_HEIGHT = 480;
|
||||||
|
|
||||||
/** LEFT enumeration */
|
/** LEFT enumeration */
|
||||||
public static final int LEFT = 0;
|
public static final int LEFT = 0;
|
||||||
|
|
||||||
/** CENTER enumeration */
|
/** CENTER enumeration */
|
||||||
public static final int CENTER = 1;
|
public static final int CENTER = 1;
|
||||||
|
|
||||||
/** RIGHT enumeration */
|
/** RIGHT enumeration */
|
||||||
public static final int RIGHT = 2;
|
public static final int RIGHT = 2;
|
||||||
|
|
||||||
/** Whether the demo is done */
|
/** Whether the demo is done */
|
||||||
private boolean finished = false;
|
private boolean finished = false;
|
||||||
|
|
||||||
// OpenAL stuff
|
// OpenAL stuff
|
||||||
// ===================================================
|
// ===================================================
|
||||||
|
|
||||||
/** OpenAL buffers */
|
/** OpenAL buffers */
|
||||||
private IntBuffer soundBuffers = createIntBuffer(3);
|
private IntBuffer soundBuffers = createIntBuffer(3);
|
||||||
|
|
||||||
/** OpenAL sources */
|
/** OpenAL sources */
|
||||||
private IntBuffer soundSources = createIntBuffer(3);
|
private IntBuffer soundSources = createIntBuffer(3);
|
||||||
|
|
||||||
/** Position of listener */
|
/** Position of listener */
|
||||||
private FloatBuffer listenerPosition = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
private FloatBuffer listenerPosition = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Velocity of listener */
|
/** Velocity of listener */
|
||||||
private FloatBuffer listenerVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
private FloatBuffer listenerVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Orientation of listener */
|
/** Orientation of listener */
|
||||||
private FloatBuffer listenerOrientation =
|
private FloatBuffer listenerOrientation =
|
||||||
createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f });
|
createFloatBuffer(6).put(new float[] { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f });
|
||||||
|
|
||||||
/** Position of left sound */
|
/** Position of left sound */
|
||||||
private FloatBuffer leftPosition = createFloatBuffer(3).put(new float[] { -2.0f, 0.0f, 0.0f });
|
private FloatBuffer leftPosition = createFloatBuffer(3).put(new float[] { -2.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Velocity of left sound */
|
/** Velocity of left sound */
|
||||||
private FloatBuffer leftVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
private FloatBuffer leftVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Position of center sound */
|
/** Position of center sound */
|
||||||
private FloatBuffer centerPosition = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, -4.0f });
|
private FloatBuffer centerPosition = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, -4.0f });
|
||||||
|
|
||||||
/** Velocity of center sound */
|
/** Velocity of center sound */
|
||||||
private FloatBuffer centerVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
private FloatBuffer centerVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Position of right sound */
|
/** Position of right sound */
|
||||||
private FloatBuffer rightPosition = createFloatBuffer(3).put(new float[] { 2.0f, 0.0f, 0.0f });
|
private FloatBuffer rightPosition = createFloatBuffer(3).put(new float[] { 2.0f, 0.0f, 0.0f });
|
||||||
|
|
||||||
/** Velocity of right sound */
|
/** Velocity of right sound */
|
||||||
private FloatBuffer rightVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
private FloatBuffer rightVelocity = createFloatBuffer(3).put(new float[] { 0.0f, 0.0f, 0.0f });
|
||||||
// ---------------------------------------------------
|
// ---------------------------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the actual test, using supplied arguments
|
* Runs the actual test, using supplied arguments
|
||||||
*/
|
*/
|
||||||
protected void execute(String[] args) {
|
protected void execute(String[] args) {
|
||||||
// Setup needed stuff
|
// Setup needed stuff
|
||||||
try {
|
try {
|
||||||
setup();
|
setup();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
System.out.println("Error setting up demonstration: ");
|
System.out.println("Error setting up demonstration: ");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
System.exit(-1);
|
System.exit(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// run the actual demonstration
|
// run the actual demonstration
|
||||||
run();
|
run();
|
||||||
|
|
||||||
// shutdown
|
// shutdown
|
||||||
shutdown();
|
shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs setup of demonstration
|
* Performs setup of demonstration
|
||||||
*/
|
*/
|
||||||
private void setup() throws Exception {
|
private void setup() throws Exception {
|
||||||
|
|
||||||
// Setup Window
|
// Setup Window
|
||||||
// =====================================================
|
// =====================================================
|
||||||
Sys.log("Setting up window");
|
Sys.log("Setting up window");
|
||||||
|
|
||||||
// calc center
|
// calc center
|
||||||
int centerX = (Display.getWidth() - WINDOW_WIDTH) / 2;
|
int centerX = (Display.getWidth() - WINDOW_WIDTH) / 2;
|
||||||
int centerY = (Display.getHeight() - WINDOW_HEIGHT) / 2;
|
int centerY = (Display.getHeight() - WINDOW_HEIGHT) / 2;
|
||||||
|
|
||||||
// setup window
|
// setup window
|
||||||
Window.create("PositionTest", centerX, centerY, WINDOW_WIDTH, WINDOW_HEIGHT, Display.getDepth(), 0, 8, 0);
|
Window.create("PositionTest", centerX, centerY, WINDOW_WIDTH, WINDOW_HEIGHT, Display.getDepth(), 0, 8, 0);
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
// Setup OpenGL
|
// Setup OpenGL
|
||||||
// =====================================================
|
// =====================================================
|
||||||
Sys.log("Setting up OpenGL");
|
Sys.log("Setting up OpenGL");
|
||||||
|
|
||||||
GL.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
GL.glViewport(0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||||
GL.glMatrixMode(GL.GL_PROJECTION);
|
GL.glMatrixMode(GL.GL_PROJECTION);
|
||||||
GL.glLoadIdentity();
|
GL.glLoadIdentity();
|
||||||
GLU.gluPerspective(60.0, WINDOW_WIDTH / WINDOW_HEIGHT, 1.0, 30.0);
|
GLU.gluPerspective(60.0, WINDOW_WIDTH / WINDOW_HEIGHT, 1.0, 30.0);
|
||||||
GL.glMatrixMode(GL.GL_MODELVIEW);
|
GL.glMatrixMode(GL.GL_MODELVIEW);
|
||||||
GL.glLoadIdentity();
|
GL.glLoadIdentity();
|
||||||
GL.glTranslatef(0.0f, 0.0f, -6.6f);
|
GL.glTranslatef(0.0f, 0.0f, -6.6f);
|
||||||
GL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
GL.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
glut = this.new GLUT();
|
glut = this.new GLUT();
|
||||||
|
|
||||||
Window.setVSyncEnabled(true);
|
Window.setVSyncEnabled(true);
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
// Setup OpenAL
|
// Setup OpenAL
|
||||||
// =====================================================
|
// =====================================================
|
||||||
Sys.log("Setting up OpenAL");
|
Sys.log("Setting up OpenAL");
|
||||||
|
|
||||||
AL.create();
|
AL.create();
|
||||||
|
|
||||||
listenerPosition.flip();
|
listenerPosition.flip();
|
||||||
listenerVelocity.flip();
|
listenerVelocity.flip();
|
||||||
listenerOrientation.flip();
|
listenerOrientation.flip();
|
||||||
|
|
||||||
leftPosition.flip();
|
leftPosition.flip();
|
||||||
leftVelocity.flip();
|
leftVelocity.flip();
|
||||||
|
|
||||||
centerPosition.flip();
|
centerPosition.flip();
|
||||||
centerVelocity.flip();
|
centerVelocity.flip();
|
||||||
|
|
||||||
rightPosition.flip();
|
rightPosition.flip();
|
||||||
rightVelocity.flip();
|
rightVelocity.flip();
|
||||||
|
|
||||||
AL.alListener(AL.AL_POSITION, listenerPosition);
|
AL.alListener(AL.AL_POSITION, listenerPosition);
|
||||||
AL.alListener(AL.AL_VELOCITY, listenerVelocity);
|
AL.alListener(AL.AL_VELOCITY, listenerVelocity);
|
||||||
AL.alListener(AL.AL_ORIENTATION, listenerOrientation);
|
AL.alListener(AL.AL_ORIENTATION, listenerOrientation);
|
||||||
|
|
||||||
// creating buffers
|
// creating buffers
|
||||||
Sys.log("Creating buffers");
|
Sys.log("Creating buffers");
|
||||||
AL.alGenBuffers(soundBuffers);
|
AL.alGenBuffers(soundBuffers);
|
||||||
soundBuffers.rewind();
|
soundBuffers.rewind();
|
||||||
|
|
||||||
// creating sources
|
// creating sources
|
||||||
AL.alGenSources(soundSources);
|
AL.alGenSources(soundSources);
|
||||||
soundSources.rewind();
|
soundSources.rewind();
|
||||||
|
|
||||||
// load sound files (left, center, right).wav
|
// load sound files (left, center, right).wav
|
||||||
Sys.log("Loading soundfiles...");
|
Sys.log("Loading soundfiles...");
|
||||||
|
|
||||||
Sys.log("Loading left.wav");
|
Sys.log("Loading left.wav");
|
||||||
WaveData left = WaveData.create("left.wav");
|
WaveData left = WaveData.create("left.wav");
|
||||||
AL.alBufferData(soundBuffers.get(LEFT), left.format, left.data, left.data.capacity(), left.samplerate);
|
AL.alBufferData(soundBuffers.get(LEFT), left.format, left.data, left.data.capacity(), left.samplerate);
|
||||||
AL.alSourcef(soundSources.get(LEFT), AL.AL_PITCH, 1.0f);
|
AL.alSourcef(soundSources.get(LEFT), AL.AL_PITCH, 1.0f);
|
||||||
AL.alSourcef(soundSources.get(LEFT), AL.AL_GAIN, 1.0f);
|
AL.alSourcef(soundSources.get(LEFT), AL.AL_GAIN, 1.0f);
|
||||||
AL.alSource(soundSources.get(LEFT), AL.AL_POSITION, leftPosition);
|
AL.alSource(soundSources.get(LEFT), AL.AL_POSITION, leftPosition);
|
||||||
AL.alSource(soundSources.get(LEFT), AL.AL_VELOCITY, leftVelocity);
|
AL.alSource(soundSources.get(LEFT), AL.AL_VELOCITY, leftVelocity);
|
||||||
AL.alSourcei(soundSources.get(LEFT), AL.AL_BUFFER, soundBuffers.get(LEFT));
|
AL.alSourcei(soundSources.get(LEFT), AL.AL_BUFFER, soundBuffers.get(LEFT));
|
||||||
AL.alSourcei(soundSources.get(LEFT), AL.AL_LOOPING, AL.AL_TRUE);
|
AL.alSourcei(soundSources.get(LEFT), AL.AL_LOOPING, AL.AL_TRUE);
|
||||||
|
|
||||||
Sys.log("Loading center.wav");
|
Sys.log("Loading center.wav");
|
||||||
WaveData center = WaveData.create("center.wav");
|
WaveData center = WaveData.create("center.wav");
|
||||||
AL.alBufferData(soundBuffers.get(CENTER), center.format, center.data, center.data.capacity(), center.samplerate);
|
AL.alBufferData(soundBuffers.get(CENTER), center.format, center.data, center.data.capacity(), center.samplerate);
|
||||||
AL.alSourcef(soundSources.get(CENTER), AL.AL_PITCH, 1.0f);
|
AL.alSourcef(soundSources.get(CENTER), AL.AL_PITCH, 1.0f);
|
||||||
AL.alSourcef(soundSources.get(CENTER), AL.AL_GAIN, 1.0f);
|
AL.alSourcef(soundSources.get(CENTER), AL.AL_GAIN, 1.0f);
|
||||||
AL.alSource(soundSources.get(CENTER), AL.AL_POSITION, centerPosition);
|
AL.alSource(soundSources.get(CENTER), AL.AL_POSITION, centerPosition);
|
||||||
AL.alSource(soundSources.get(CENTER), AL.AL_VELOCITY, centerVelocity);
|
AL.alSource(soundSources.get(CENTER), AL.AL_VELOCITY, centerVelocity);
|
||||||
AL.alSourcei(soundSources.get(CENTER), AL.AL_BUFFER, soundBuffers.get(CENTER));
|
AL.alSourcei(soundSources.get(CENTER), AL.AL_BUFFER, soundBuffers.get(CENTER));
|
||||||
AL.alSourcei(soundSources.get(CENTER), AL.AL_LOOPING, AL.AL_TRUE);
|
AL.alSourcei(soundSources.get(CENTER), AL.AL_LOOPING, AL.AL_TRUE);
|
||||||
|
|
||||||
Sys.log("Loading right.wav");
|
Sys.log("Loading right.wav");
|
||||||
WaveData right = WaveData.create("right.wav");
|
WaveData right = WaveData.create("right.wav");
|
||||||
AL.alBufferData(soundBuffers.get(RIGHT), right.format, right.data, right.data.capacity(), right.samplerate);
|
AL.alBufferData(soundBuffers.get(RIGHT), right.format, right.data, right.data.capacity(), right.samplerate);
|
||||||
AL.alSourcef(soundSources.get(RIGHT), AL.AL_PITCH, 1.0f);
|
AL.alSourcef(soundSources.get(RIGHT), AL.AL_PITCH, 1.0f);
|
||||||
AL.alSourcef(soundSources.get(RIGHT), AL.AL_GAIN, 1.0f);
|
AL.alSourcef(soundSources.get(RIGHT), AL.AL_GAIN, 1.0f);
|
||||||
AL.alSource(soundSources.get(RIGHT), AL.AL_POSITION, rightPosition);
|
AL.alSource(soundSources.get(RIGHT), AL.AL_POSITION, rightPosition);
|
||||||
AL.alSource(soundSources.get(RIGHT), AL.AL_VELOCITY, rightVelocity);
|
AL.alSource(soundSources.get(RIGHT), AL.AL_VELOCITY, rightVelocity);
|
||||||
AL.alSourcei(soundSources.get(RIGHT), AL.AL_BUFFER, soundBuffers.get(RIGHT));
|
AL.alSourcei(soundSources.get(RIGHT), AL.AL_BUFFER, soundBuffers.get(RIGHT));
|
||||||
AL.alSourcei(soundSources.get(RIGHT), AL.AL_LOOPING, AL.AL_TRUE);
|
AL.alSourcei(soundSources.get(RIGHT), AL.AL_LOOPING, AL.AL_TRUE);
|
||||||
|
|
||||||
Sys.log("Soundfiles loaded successfully");
|
Sys.log("Soundfiles loaded successfully");
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
|
|
||||||
// Setup Keyboard
|
// Setup Keyboard
|
||||||
// =====================================================
|
// =====================================================
|
||||||
Sys.log("Setting up Keyboard");
|
Sys.log("Setting up Keyboard");
|
||||||
|
|
||||||
Keyboard.create();
|
Keyboard.create();
|
||||||
// -----------------------------------------------------
|
// -----------------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Runs the actual demonstration
|
* Runs the actual demonstration
|
||||||
*/
|
*/
|
||||||
private void run() {
|
private void run() {
|
||||||
boolean firstRun = true;
|
boolean firstRun = true;
|
||||||
|
|
||||||
System.out.println("Press 1/4 (left), 2/5 (center) or 3/6 (right) to toggle sound");
|
System.out.println("Press 1/4 (left), 2/5 (center) or 3/6 (right) to toggle sound");
|
||||||
System.out.println("Press LEFT/RIGHT to move along x axis");
|
System.out.println("Press LEFT/RIGHT to move along x axis");
|
||||||
System.out.println("Press SHIFT and either UP/DOWN to move along y axis");
|
System.out.println("Press SHIFT and either UP/DOWN to move along y axis");
|
||||||
System.out.println("Press UP/DOWN to move along z axis");
|
System.out.println("Press UP/DOWN to move along z axis");
|
||||||
System.out.println("Press ESC to exit demo");
|
System.out.println("Press ESC to exit demo");
|
||||||
|
|
||||||
Sys.log(
|
|
||||||
"Listener position: "
|
|
||||||
+ listenerPosition.get(0)
|
|
||||||
+ ", "
|
|
||||||
+ listenerPosition.get(1)
|
|
||||||
+ ", "
|
|
||||||
+ listenerPosition.get(2));
|
|
||||||
Sys.log(
|
Sys.log(
|
||||||
"Left position: " + leftPosition.get(0) + ", " + leftPosition.get(1) + ", " + leftPosition.get(2));
|
"Listener position: "
|
||||||
Sys.log(
|
+ listenerPosition.get(0)
|
||||||
"Center position: " + centerPosition.get(0) + ", " + centerPosition.get(1) + ", " + centerPosition.get(2));
|
+ ", "
|
||||||
Sys.log(
|
+ listenerPosition.get(1)
|
||||||
"Right position: " + rightPosition.get(0) + ", " + rightPosition.get(1) + ", " + rightPosition.get(2));
|
+ ", "
|
||||||
|
+ listenerPosition.get(2));
|
||||||
|
Sys.log("Left position: " + leftPosition.get(0) + ", " + leftPosition.get(1) + ", " + leftPosition.get(2));
|
||||||
|
Sys.log("Center position: " + centerPosition.get(0) + ", " + centerPosition.get(1) + ", " + centerPosition.get(2));
|
||||||
|
Sys.log("Right position: " + rightPosition.get(0) + ", " + rightPosition.get(1) + ", " + rightPosition.get(2));
|
||||||
|
|
||||||
while (!finished) {
|
while (!finished) {
|
||||||
// handle any input
|
// handle any input
|
||||||
handleInput();
|
handleInput();
|
||||||
|
|
||||||
// render the scene
|
// render the scene
|
||||||
render();
|
render();
|
||||||
|
|
||||||
// allow window to process internal messages
|
// allow window to process internal messages
|
||||||
Window.update();
|
Window.update();
|
||||||
|
|
||||||
// paint the content and flip buffer
|
// paint the content and flip buffer
|
||||||
Window.paint();
|
Window.paint();
|
||||||
|
|
||||||
// start sound after first paint, since we don't want
|
// start sound after first paint, since we don't want
|
||||||
// the delay before something is painted on the screen
|
// the delay before something is painted on the screen
|
||||||
if (firstRun) {
|
if (firstRun) {
|
||||||
firstRun = false;
|
firstRun = false;
|
||||||
|
|
||||||
// start sounds with delays
|
// start sounds with delays
|
||||||
AL.alSourcePlay(soundSources.get(LEFT));
|
AL.alSourcePlay(soundSources.get(LEFT));
|
||||||
pause(300);
|
pause(300);
|
||||||
AL.alSourcePlay(soundSources.get(CENTER));
|
AL.alSourcePlay(soundSources.get(CENTER));
|
||||||
pause(500);
|
pause(500);
|
||||||
AL.alSourcePlay(soundSources.get(RIGHT));
|
AL.alSourcePlay(soundSources.get(RIGHT));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles any input
|
* Handles any input
|
||||||
*/
|
*/
|
||||||
private void handleInput() {
|
private void handleInput() {
|
||||||
Keyboard.poll();
|
Keyboard.poll();
|
||||||
|
|
||||||
// User wants to exit?
|
// User wants to exit?
|
||||||
finished = Window.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
|
finished = Window.isCloseRequested() || Keyboard.isKeyDown(Keyboard.KEY_ESCAPE);
|
||||||
if (finished) {
|
if (finished) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
boolean shift = Keyboard.isKeyDown(Keyboard.KEY_LSHIFT) || Keyboard.isKeyDown(Keyboard.KEY_RSHIFT);
|
||||||
|
|
||||||
// Test for play
|
// Test for play
|
||||||
// ============================================
|
// ============================================
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_1)) {
|
||||||
AL.alSourcePlay(soundSources.get(LEFT));
|
AL.alSourcePlay(soundSources.get(LEFT));
|
||||||
Sys.log("Playing left.wav");
|
Sys.log("Playing left.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_2)) {
|
||||||
AL.alSourcePlay(soundSources.get(CENTER));
|
AL.alSourcePlay(soundSources.get(CENTER));
|
||||||
Sys.log("Playing center.wav");
|
Sys.log("Playing center.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_3)) {
|
||||||
AL.alSourcePlay(soundSources.get(RIGHT));
|
AL.alSourcePlay(soundSources.get(RIGHT));
|
||||||
Sys.log("Playing right.wav");
|
Sys.log("Playing right.wav");
|
||||||
}
|
}
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
|
||||||
// Test for stop
|
// Test for stop
|
||||||
// ============================================
|
// ============================================
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_4)) {
|
||||||
AL.alSourceStop(soundSources.get(LEFT));
|
AL.alSourceStop(soundSources.get(LEFT));
|
||||||
Sys.log("Stopped left.wav");
|
Sys.log("Stopped left.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_5)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_5)) {
|
||||||
AL.alSourceStop(soundSources.get(CENTER));
|
AL.alSourceStop(soundSources.get(CENTER));
|
||||||
Sys.log("Stopped center.wav");
|
Sys.log("Stopped center.wav");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_6)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_6)) {
|
||||||
AL.alSourceStop(soundSources.get(RIGHT));
|
AL.alSourceStop(soundSources.get(RIGHT));
|
||||||
Sys.log("Stopped right.wav");
|
Sys.log("Stopped right.wav");
|
||||||
}
|
}
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
|
|
||||||
// Test for movement
|
// Test for movement
|
||||||
// ============================================
|
// ============================================
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) {
|
||||||
listenerPosition.put(0, listenerPosition.get(0) - 0.1f);
|
listenerPosition.put(0, listenerPosition.get(0) - 0.1f);
|
||||||
AL.alListener(AL.AL_POSITION, listenerPosition);
|
AL.alListener(AL.AL_POSITION, listenerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) {
|
||||||
listenerPosition.put(0, listenerPosition.get(0) + 0.1f);
|
listenerPosition.put(0, listenerPosition.get(0) + 0.1f);
|
||||||
AL.alListener(AL.AL_POSITION, listenerPosition);
|
AL.alListener(AL.AL_POSITION, listenerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_UP)) {
|
||||||
if (shift) {
|
if (shift) {
|
||||||
listenerPosition.put(1, listenerPosition.get(1) + 0.1f);
|
listenerPosition.put(1, listenerPosition.get(1) + 0.1f);
|
||||||
} else {
|
} else {
|
||||||
listenerPosition.put(2, listenerPosition.get(2) - 0.1f);
|
listenerPosition.put(2, listenerPosition.get(2) - 0.1f);
|
||||||
}
|
}
|
||||||
AL.alListener(AL.AL_POSITION, listenerPosition);
|
AL.alListener(AL.AL_POSITION, listenerPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
|
if (Keyboard.isKeyDown(Keyboard.KEY_DOWN)) {
|
||||||
if (shift) {
|
if (shift) {
|
||||||
listenerPosition.put(1, listenerPosition.get(1) - 0.1f);
|
listenerPosition.put(1, listenerPosition.get(1) - 0.1f);
|
||||||
} else {
|
} else {
|
||||||
listenerPosition.put(2, listenerPosition.get(2) + 0.1f);
|
listenerPosition.put(2, listenerPosition.get(2) + 0.1f);
|
||||||
}
|
}
|
||||||
AL.alListener(AL.AL_POSITION, listenerPosition);
|
AL.alListener(AL.AL_POSITION, listenerPosition);
|
||||||
}
|
}
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render the scene
|
* Render the scene
|
||||||
*/
|
*/
|
||||||
private void render() {
|
private void render() {
|
||||||
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
|
GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT);
|
||||||
GL.glPushMatrix();
|
GL.glPushMatrix();
|
||||||
{
|
{
|
||||||
GL.glRotatef(20.0f, 1.0f, 1.0f, 0.0f);
|
GL.glRotatef(20.0f, 1.0f, 1.0f, 0.0f);
|
||||||
|
|
||||||
GL.glPushMatrix();
|
GL.glPushMatrix();
|
||||||
{
|
{
|
||||||
GL.glTranslatef(leftPosition.get(0), leftPosition.get(1), leftPosition.get(2));
|
GL.glTranslatef(leftPosition.get(0), leftPosition.get(1), leftPosition.get(2));
|
||||||
GL.glColor3f(1.0f, 0.0f, 0.0f);
|
GL.glColor3f(1.0f, 0.0f, 0.0f);
|
||||||
glut.glutWireCube(0.5f);
|
glut.glutWireCube(0.5f);
|
||||||
}
|
}
|
||||||
GL.glPopMatrix();
|
GL.glPopMatrix();
|
||||||
|
|
||||||
GL.glPushMatrix();
|
GL.glPushMatrix();
|
||||||
{
|
{
|
||||||
GL.glTranslatef(centerPosition.get(0), centerPosition.get(1), centerPosition.get(2));
|
GL.glTranslatef(centerPosition.get(0), centerPosition.get(1), centerPosition.get(2));
|
||||||
GL.glColor3f(0.0f, 0.0f, 1.0f);
|
GL.glColor3f(0.0f, 0.0f, 1.0f);
|
||||||
glut.glutWireCube(0.5f);
|
glut.glutWireCube(0.5f);
|
||||||
}
|
}
|
||||||
GL.glPopMatrix();
|
GL.glPopMatrix();
|
||||||
|
|
||||||
GL.glPushMatrix();
|
GL.glPushMatrix();
|
||||||
{
|
{
|
||||||
GL.glTranslatef(rightPosition.get(0), rightPosition.get(1), rightPosition.get(2));
|
GL.glTranslatef(rightPosition.get(0), rightPosition.get(1), rightPosition.get(2));
|
||||||
GL.glColor3f(0.0f, 1.0f, 0.0f);
|
GL.glColor3f(0.0f, 1.0f, 0.0f);
|
||||||
glut.glutWireCube(0.5f);
|
glut.glutWireCube(0.5f);
|
||||||
}
|
}
|
||||||
GL.glPopMatrix();
|
GL.glPopMatrix();
|
||||||
|
|
||||||
//the listener
|
//the listener
|
||||||
GL.glPushMatrix();
|
GL.glPushMatrix();
|
||||||
{
|
{
|
||||||
GL.glTranslatef(listenerPosition.get(0), listenerPosition.get(1), listenerPosition.get(2));
|
GL.glTranslatef(listenerPosition.get(0), listenerPosition.get(1), listenerPosition.get(2));
|
||||||
GL.glColor3f(1.0f, 1.0f, 1.0f);
|
GL.glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
glut.glutSolidCube(0.5f);
|
glut.glutSolidCube(0.5f);
|
||||||
}
|
}
|
||||||
GL.glPopMatrix();
|
GL.glPopMatrix();
|
||||||
}
|
}
|
||||||
GL.glPopMatrix();
|
GL.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shutdown of demonstration
|
* Shutdown of demonstration
|
||||||
*/
|
*/
|
||||||
private void shutdown() {
|
private void shutdown() {
|
||||||
Sys.log("Shutting down Keyboard");
|
Sys.log("Shutting down Keyboard");
|
||||||
Keyboard.destroy();
|
Keyboard.destroy();
|
||||||
|
|
||||||
Sys.log("Shutting down OpenAL");
|
Sys.log("Shutting down OpenAL");
|
||||||
AL.alSourceStop(soundSources);
|
AL.alSourceStop(soundSources);
|
||||||
AL.alDeleteSources(soundSources);
|
AL.alDeleteSources(soundSources);
|
||||||
AL.alDeleteBuffers(soundBuffers);
|
AL.alDeleteBuffers(soundBuffers);
|
||||||
AL.destroy();
|
AL.destroy();
|
||||||
|
|
||||||
Sys.log("Shutting down Window");
|
Sys.log("Shutting down Window");
|
||||||
Window.destroy();
|
Window.destroy();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* main entry point
|
* main entry point
|
||||||
*
|
*
|
||||||
* @param args
|
* @param args
|
||||||
* String array containing arguments
|
* String array containing arguments
|
||||||
*/
|
*/
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
PositionTest positionTest = new PositionTest();
|
PositionTest positionTest = new PositionTest();
|
||||||
positionTest.execute(args);
|
positionTest.execute(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Minute implementation of GLUT: <br>COPYRIGHT:
|
* Minute implementation of GLUT: <br>COPYRIGHT:
|
||||||
*
|
*
|
||||||
* The OpenGL Utility Toolkit distribution for Win32 (Windows NT & Windows
|
* The OpenGL Utility Toolkit distribution for Win32 (Windows NT & Windows
|
||||||
* 95) contains source code modified from the original source code for GLUT
|
* 95) contains source code modified from the original source code for GLUT
|
||||||
* version 3.3 which was developed by Mark J. Kilgard. The original source
|
* version 3.3 which was developed by Mark J. Kilgard. The original source
|
||||||
* code for GLUT is Copyright 1997 by Mark J. Kilgard. GLUT for Win32 is
|
* code for GLUT is Copyright 1997 by Mark J. Kilgard. GLUT for Win32 is
|
||||||
* Copyright 1997 by Nate Robins and is not in the public domain, but it is
|
* Copyright 1997 by Nate Robins and is not in the public domain, but it is
|
||||||
* freely distributable without licensing fees. It is provided without
|
* freely distributable without licensing fees. It is provided without
|
||||||
* guarantee or warrantee expressed or implied. It was ported with the
|
* guarantee or warrantee expressed or implied. It was ported with the
|
||||||
* permission of Mark J. Kilgard by Nate Robins.
|
* permission of Mark J. Kilgard by Nate Robins.
|
||||||
*
|
*
|
||||||
* THIS SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
* THIS SOURCE CODE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER
|
||||||
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
* EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||||
* OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
* OR MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
|
||||||
*/
|
*/
|
||||||
class GLUT {
|
class GLUT {
|
||||||
|
|
||||||
float n[][] = new float[][] { { -1.0f, 0.0f, 0.0f }, {
|
float n[][] = new float[][] { { -1.0f, 0.0f, 0.0f }, {
|
||||||
0.0f, 1.0f, 0.0f }, {
|
0.0f, 1.0f, 0.0f }, {
|
||||||
1.0f, 0.0f, 0.0f }, {
|
1.0f, 0.0f, 0.0f }, {
|
||||||
0.0f, -1.0f, 0.0f }, {
|
0.0f, -1.0f, 0.0f }, {
|
||||||
0.0f, 0.0f, 1.0f }, {
|
0.0f, 0.0f, 1.0f }, {
|
||||||
0.0f, 0.0f, -1.0f }
|
0.0f, 0.0f, -1.0f }
|
||||||
};
|
};
|
||||||
|
|
||||||
int faces[][] = new int[][] { { 0, 1, 2, 3 }, {
|
int faces[][] = new int[][] { { 0, 1, 2, 3 }, {
|
||||||
3, 2, 6, 7 }, {
|
3, 2, 6, 7 }, {
|
||||||
7, 6, 5, 4 }, {
|
7, 6, 5, 4 }, {
|
||||||
4, 5, 1, 0 }, {
|
4, 5, 1, 0 }, {
|
||||||
5, 6, 2, 1 }, {
|
5, 6, 2, 1 }, {
|
||||||
7, 4, 0, 3 }
|
7, 4, 0, 3 }
|
||||||
};
|
};
|
||||||
float v[][] = new float[8][3];
|
float v[][] = new float[8][3];
|
||||||
|
|
||||||
public void glutWireCube(float size) {
|
public void glutWireCube(float size) {
|
||||||
drawBox(size, GL.GL_LINE_LOOP);
|
drawBox(size, GL.GL_LINE_LOOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void glutSolidCube(float size) {
|
public void glutSolidCube(float size) {
|
||||||
drawBox(size, GL.GL_QUADS);
|
drawBox(size, GL.GL_QUADS);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawBox(float size, int type) {
|
private void drawBox(float size, int type) {
|
||||||
|
|
||||||
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
|
v[0][0] = v[1][0] = v[2][0] = v[3][0] = -size / 2;
|
||||||
v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
|
v[4][0] = v[5][0] = v[6][0] = v[7][0] = size / 2;
|
||||||
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
|
v[0][1] = v[1][1] = v[4][1] = v[5][1] = -size / 2;
|
||||||
v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
|
v[2][1] = v[3][1] = v[6][1] = v[7][1] = size / 2;
|
||||||
v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
|
v[0][2] = v[3][2] = v[4][2] = v[7][2] = -size / 2;
|
||||||
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
|
v[1][2] = v[2][2] = v[5][2] = v[6][2] = size / 2;
|
||||||
|
|
||||||
for (int i = 5; i >= 0; i--) {
|
for (int i = 5; i >= 0; i--) {
|
||||||
GL.glBegin(type);
|
GL.glBegin(type);
|
||||||
GL.glNormal3f(n[i][0], n[i][1], n[i][2]);
|
GL.glNormal3f(n[i][0], n[i][1], n[i][2]);
|
||||||
GL.glVertex3f(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
|
GL.glVertex3f(v[faces[i][0]][0], v[faces[i][0]][1], v[faces[i][0]][2]);
|
||||||
GL.glVertex3f(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
|
GL.glVertex3f(v[faces[i][1]][0], v[faces[i][1]][1], v[faces[i][1]][2]);
|
||||||
GL.glVertex3f(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
|
GL.glVertex3f(v[faces[i][2]][0], v[faces[i][2]][1], v[faces[i][2]][2]);
|
||||||
GL.glVertex3f(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
|
GL.glVertex3f(v[faces[i][3]][0], v[faces[i][3]][1], v[faces[i][3]][2]);
|
||||||
GL.glEnd();
|
GL.glEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue