import net.sf.jirr.*;
import net.sf.jirrklang.ISoundEngine;
import net.sf.jirrklang.Jirrklang;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Vector;
import java.awt.event.KeyEvent;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
/** using irrklang for mp3 now */
public class TestTechdemoIrrklang
{
static
{
System.loadLibrary("irrklang_wrap");
System.loadLibrary("irrlicht_wrap");
}
boolean music = true;
File ballSound = null;
File impactSound = null;
boolean additive;
long sceneStartTime;
long timeForThisScene;
int currentScene;
IrrlichtDevice device;
IAnimatedMeshSceneNode model1;
IAnimatedMeshSceneNode model2;
IGUIStaticText statusText;
IGUIInOutFader inOutFader;
IParticleSystemSceneNode campFire;
IAnimatedMesh quakeLevelMesh;
ISceneNode quakeLevelNode;
ISceneNode skyboxNode;
IMetaTriangleSelector metaSelector;
ITriangleSelector mapSelector;
SColor backColor;
class SParticleImpact
{
int when;
vector3df pos;
vector3df outVector;
}
Vector<SParticleImpact> Impacts;
public TestTechdemoIrrklang()
{
currentScene = -2;
backColor = new SColor();
Impacts = new Vector<TestTechdemoIrrklang.SParticleImpact>();
}
public static void main(String argv[])
{
final TestTechdemoIrrklang demo = new TestTechdemoIrrklang();
demo.run(argv.length > 0);
}
public void run(boolean isFullscreen)
{
device = Jirr.createDevice(E_DRIVER_TYPE.EDT_OPENGL, new dimension2di(640, 480), 32, isFullscreen, false, false, new TestTechdemoIrrklang.MyEventReciever());
device.getFileSystem().addZipFileArchive("irrlicht.dat", true, true);
device.getFileSystem().addZipFileArchive("../media/irrlicht.dat", true, true);
device.getFileSystem().addZipFileArchive("map-20kdm2.pk3", true, true);
device.getFileSystem().addZipFileArchive("../media/map-20kdm2.pk3", true, true);
IVideoDriver driver = device.getVideoDriver();
ISceneManager smgr = device.getSceneManager();
IGUIEnvironment guienv = device.getGUIEnvironment();
device.setWindowCaption("Irrlicht Engine Techdemo");
// clear backbuffer
if ( driver != null )
{
driver.beginScene(true, true, new SColor(0,0,0,0));
driver.endScene();
}
String tmp;
while (device.run() && driver != null)
{
if (device.isWindowActive())
{
// load next scene if necessary
long now = device.getTimer().getTime();
if (now - sceneStartTime > timeForThisScene && timeForThisScene != -1)
switchToNextScene();
createParticleImpacts();
// draw everything
driver.beginScene(true, true, backColor);
smgr.drawAll();
guienv.drawAll();
driver.endScene();
// write statistics
tmp = "Java@Techdemo - Irrlicht Engine (fps:"
+ driver.getFPS()
+ ") polys:"
+ driver.getPrimitiveCountDrawn();
statusText.setText(tmp);
}
}
device.closeDevice();
device.drop();
}
/**
* EventHandling
*/
public class MyEventReciever extends IEventReceiver
{
public boolean OnEvent(SEvent event)
{
//if (event.getEventType() == EEVENT_TYPE.EET_LOG_TEXT_EVENT);
if (device == null)
{
return false;
}
if (event.getEventType() == EEVENT_TYPE.EET_KEY_INPUT_EVENT &&
event.getKeyInputChar() == KeyEvent.VK_ESCAPE &&
!event.isKeyInputPressedDown())
{
// user wants to quit.
if (currentScene < 3)
{
timeForThisScene = 0;
}
else
{
device.closeDevice();
System.out.println("Esc");
System.exit(0);
}
}
else if ((event.getEventType() == EEVENT_TYPE.EET_KEY_INPUT_EVENT &&
event.getKeyInputChar() == KeyEvent.VK_SPACE &&
!event.isKeyInputPressedDown()) ||
(event.getEventType() == EEVENT_TYPE.EET_MOUSE_INPUT_EVENT &&
event.getMouseInputEvent() == EMOUSE_INPUT_EVENT.EMIE_LMOUSE_LEFT_UP) &&
currentScene == 3)
{
// shoot
shoot();
}
else if (event.getEventType() == EEVENT_TYPE.EET_KEY_INPUT_EVENT)
{
System.out.println("event.getKeyInputKey() = " + event.getKeyInputChar());
System.out.println("event.getKeyInputKey() = " + event.getKeyInputKey());
System.out.println("event.getKeyInputKey()s = " + event.getKeyInputKey().swigValue());
}
else if (device.getSceneManager().getActiveCamera() != null)
{
device.getSceneManager().getActiveCamera().OnEvent(event);
return true;
}
// else if (event.getEventType() == EEVENT_TYPE.EET_MOUSE_INPUT_EVENT)
// {
// return true;
// }
return false;
}
}
void switchToNextScene()
{
currentScene++;
if (currentScene > 3)
currentScene = 1;
ISceneManager sm = device.getSceneManager();
ICameraSceneNode camera = sm.getActiveCamera();
if (camera != null)
{
sm.setActiveCamera(null);
camera.remove();
}
ISceneNodeAnimator sa;
switch (currentScene)
{
case -1: // loading screen
timeForThisScene = 0;
createLoadingScreen();
break;
case 0: // load scene
timeForThisScene = 0;
loadSceneData();
//currentScene += 2;
break;
case 1: // panorama camera
{
/* #if 0
camera = sm.addCameraSceneNodeFPS(null, 100, 500);
timeForThisScene = 14000000;
#else
*/
// timeForThisScene = 39664;
currentScene += 1;
camera = sm.addCameraSceneNode(null,
new vector3df(0, 0, 0),
new vector3df(-586, 708, 52),
-1);
camera.setTarget(new vector3df(0, 400, 0));
vector3dfarray points = new vector3dfarray();
points.push_back(new vector3df(1114.336792f, 242.206009f, -56.976807f));
points.push_back(new vector3df(1116.545166f, 378.685272f, -56.083183f));
points.push_back(new vector3df(1118.940186f, 516.664307f, -56.338856f));
points.push_back(new vector3df(1130.007935f, 662.745605f, -56.157753f));
points.push_back(new vector3df(1154.303345f, 814.303101f, -57.683624f));
points.push_back(new vector3df(1007.227173f, 757.994019f, 226.902283f));
points.push_back(new vector3df(913.370850f, 667.597168f, 469.352020f));
points.push_back(new vector3df(804.647400f, 625.486145f, 637.515320f));
points.push_back(new vector3df(799.796814f, 625.486145f, 971.678223f));
points.push_back(new vector3df(576.089050f, 573.689880f, 1024.815430f));
points.push_back(new vector3df(492.829620f, 545.776917f, 940.990051f));
points.push_back(new vector3df(502.472015f, 563.155029f, 811.918396f));
points.push_back(new vector3df(456.350525f, 545.089233f, 587.798828f));
points.push_back(new vector3df(477.665680f, 545.019470f, 350.156158f));
points.push_back(new vector3df(462.408508f, 534.190247f, 55.671730f));
points.push_back(new vector3df(455.176117f, 548.591370f, -195.685745f));
points.push_back(new vector3df(445.013641f, 561.275391f, -481.564636f));
points.push_back(new vector3df(470.327087f, 554.699463f, -914.740601f));
points.push_back(new vector3df(215.299149f, 478.205139f, -890.992554f));
points.push_back(new vector3df(40.725445f, 406.419464f, -856.153564f));
points.push_back(new vector3df(-139.619537f, 367.475952f, -832.361145f));
points.push_back(new vector3df(-372.134460f, 353.153320f, -718.145630f));
points.push_back(new vector3df(-396.479126f, 399.665192f, -464.819946f));
points.push_back(new vector3df(-401.636963f, 400.320068f, -85.747185f));
points.push_back(new vector3df(-399.067566f, 405.603760f, 78.287315f));
points.push_back(new vector3df(-142.541534f, 390.756897f, 108.415192f));
points.push_back(new vector3df(110.264053f, 388.120453f, 91.955513f));
points.push_back(new vector3df(358.585236f, 392.355316f, 98.712135f));
points.push_back(new vector3df(573.278687f, 396.884125f, 109.258797f));
points.push_back(new vector3df(631.992310f, 419.328979f, 281.179108f));
points.push_back(new vector3df(607.874084f, 413.811523f, 535.857849f));
points.push_back(new vector3df(614.861389f, 400.083984f, 751.252869f));
points.push_back(new vector3df(557.560303f, 341.482758f, 924.299133f));
points.push_back(new vector3df(430.859222f, 331.369476f, 985.138367f));
points.push_back(new vector3df(263.945251f, 215.380280f, 968.150269f));
points.push_back(new vector3df(202.371033f, 213.545090f, 943.107300f));
points.push_back(new vector3df(114.756012f, 199.799759f, 805.014160f));
points.push_back(new vector3df(96.783348f, 181.639481f, 648.188110f));
points.push_back(new vector3df(97.865623f, 138.905975f, 484.812561f));
points.push_back(new vector3df(99.612457f, 102.463669f, 347.603210f));
points.push_back(new vector3df(99.612457f, 102.463669f, 347.603210f));
points.push_back(new vector3df(99.612457f, 102.463669f, 347.603210f));
timeForThisScene = (points.size() - 3) * 1000;
sa = sm.createFollowSplineAnimator((int) device.getTimer().getTime(),
points);/*,
1f,
0.5f);*/
camera.addAnimator(sa);
sa.drop();
// #endif
model1.setVisible(false);
model2.setVisible(false);
campFire.setVisible(false);
inOutFader.fadeIn(7000);
break;
}
case 2: // down fly anim camera
camera = sm.addCameraSceneNode(null,
new vector3df(100, 40, -80),
new vector3df(844, 670, -885),
-1);
sa = sm.createFlyStraightAnimator(new vector3df(94, 1002, 127),
new vector3df(108, 15, -60), 10000, true);
camera.addAnimator(sa);
timeForThisScene = 9900;
model1.setVisible(true);
model2.setVisible(false);
campFire.setVisible(false);
sa.drop();
break;
case 3: // interactive, go around
{
model1.setVisible(true);
model2.setVisible(true);
campFire.setVisible(true);
timeForThisScene = -1;
SKeyMap keyMapArray[] = new SKeyMap[8];
for (int i = 0; i < keyMapArray.length; i++)
{
keyMapArray[i] = new SKeyMap();
}
keyMapArray[0].setAction(EKEY_ACTION.EKA_MOVE_FORWARD);
keyMapArray[0].setKeyCode(EKEY_CODE.KEY_UP);
keyMapArray[1].setAction(EKEY_ACTION.EKA_MOVE_FORWARD);
keyMapArray[1].setKeyCode(EKEY_CODE.KEY_KEY_W);
keyMapArray[2].setAction(EKEY_ACTION.EKA_MOVE_BACKWARD);
keyMapArray[2].setKeyCode(EKEY_CODE.KEY_DOWN);
keyMapArray[3].setAction(EKEY_ACTION.EKA_MOVE_BACKWARD);
keyMapArray[3].setKeyCode(EKEY_CODE.KEY_KEY_S);
keyMapArray[4].setAction(EKEY_ACTION.EKA_STRAFE_LEFT);
keyMapArray[4].setKeyCode(EKEY_CODE.KEY_LEFT);
keyMapArray[5].setAction(EKEY_ACTION.EKA_STRAFE_LEFT);
keyMapArray[5].setKeyCode(EKEY_CODE.KEY_KEY_A);
keyMapArray[6].setAction(EKEY_ACTION.EKA_STRAFE_RIGHT);
keyMapArray[6].setKeyCode(EKEY_CODE.KEY_RIGHT);
keyMapArray[7].setAction(EKEY_ACTION.EKA_STRAFE_RIGHT);
keyMapArray[7].setKeyCode(EKEY_CODE.KEY_KEY_D);
camera = sm.addCameraSceneNodeFPS(null, 100.0f, 300.0f, (-1), keyMapArray, keyMapArray.length);
camera.setPosition(new vector3df(108, 140, -140));
ISceneNodeAnimatorCollisionResponse collider =
sm.createCollisionResponseAnimator(
metaSelector, camera, new vector3df(30, 50, 30),
new vector3df(0, quakeLevelMesh != null ? -100.0f : 0.0f, 0), //100.0f,
new vector3df(0, 40, 0), 0.0005f);
camera.addAnimator(collider);
collider.drop();
}
break;
}
sceneStartTime = device.getTimer().getTime();
}
void loadSceneData()
{
// load quake level
IVideoDriver driver = device.getVideoDriver();
ISceneManager sm = device.getSceneManager();
quakeLevelMesh = sm.getMesh("20kdm2.bsp");
if (quakeLevelMesh != null)
{
quakeLevelNode = sm.addOctTreeSceneNode(quakeLevelMesh.getMesh(0)/*,
null, (-1), (128)*/);
if (quakeLevelNode != null)
{
quakeLevelNode.setPosition(new vector3df(-1300, -70, -1249));
quakeLevelNode.setVisible(true);
// create map triangle selector
mapSelector = sm.createOctTreeTriangleSelector(quakeLevelMesh.getMesh(0),
quakeLevelNode,
128);
// set additive blending if wanted
if (additive)
quakeLevelNode.setMaterialType(E_MATERIAL_TYPE.EMT_LIGHTMAP_ADD);
}
}
// load sydney model and create 2 instances
IAnimatedMesh mesh = sm.getMesh("../media/sydney.md2");
if (mesh != null)
{
model1 = sm.addAnimatedMeshSceneNode(mesh);//, null, -1, new vector3df(0, 0, 0), new vector3df(0, 0, 0), new vector3df(1.0f, 1.0f, 1.0f));
if (model1 != null)
{
model1.setMaterialTexture(0, driver.getTexture("../media/spheremap.jpg"));
model1.setPosition(new vector3df(100, 40, -80));
model1.setScale(new vector3df(2, 2, 2));
model1.setMD2Animation(EMD2_ANIMATION_TYPE.EMAT_SALUTE);
model1.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
model1.setMaterialType(E_MATERIAL_TYPE.EMT_SPHERE_MAP);
model1.addShadowVolumeSceneNode();//-1, true, 10000.0f);
}
model2 = sm.addAnimatedMeshSceneNode(mesh, null, (-1), new vector3df(0, 0, 0), new vector3df(0, 0, 0), new vector3df(1.0f, 1.0f, 1.0f));
if (model2 != null)
{
model2.setPosition(new vector3df(180, 15, -60));
model2.setScale(new vector3df(2, 2, 2));
model2.setMD2Animation(EMD2_ANIMATION_TYPE.EMAT_RUN);
// model2.setAnimationSpeed(20);
model2.setMaterialTexture(0, device.getVideoDriver().getTexture("../media/sydney.BMP"));
model2.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, true);
model2.addShadowVolumeSceneNode();//-1, true, 10000.0f);
}
}
ISceneNodeAnimator anim;
// create sky box
skyboxNode = sm.addSkyBoxSceneNode(
driver.getTexture("../media/irrlicht2_up.jpg"),
driver.getTexture("../media/irrlicht2_dn.jpg"),
driver.getTexture("../media/irrlicht2_lf.jpg"),
driver.getTexture("../media/irrlicht2_rt.jpg"),
driver.getTexture("../media/irrlicht2_ft.jpg"),
driver.getTexture("../media/irrlicht2_bk.jpg"));/*,
null,
(-1));*/
// create walk-between-portals animation
vector3df waypoint[] = new vector3df[2];
waypoint[0] = new vector3df(-150, 40, 100);
waypoint[1] = new vector3df(350, 40, 100);
if (model2 != null)
{
anim = device.getSceneManager().createFlyStraightAnimator(waypoint[0],
waypoint[1], 2000, true);
model2.addAnimator(anim);
anim.drop();
}
// create animation for portals;
ITextureArray textures = new ITextureArray();
for (int g = 1; g < 8; ++g)
{
String tmp = "../media/portal" + g + ".bmp";
ITexture t = driver.getTexture(tmp);
textures.push_back(t);
}
anim = sm.createTextureAnimator(textures, 100);//, true);
// create portals
IBillboardSceneNode bill;
for (int r = 0; r < 2; ++r)
{
bill = sm.addBillboardSceneNode(null,
new dimension2df(100, 100),
add(waypoint[r], new vector3df(0, 20, 0)),
-1);
bill.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
bill.setMaterialTexture((0), driver.getTexture("../media/portal1.bmp"));
bill.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
bill.addAnimator(anim);
}
anim.drop();
// create cirlce flying dynamic light with transparent billboard attached
ILightSceneNode light;
light = device.getSceneManager().addLightSceneNode(null,
new vector3df(0, 0, 0), new SColorf(1.0f, 0.5f, 0.5f, 1.0f), 1500, -1);
anim = device.getSceneManager().createFlyCircleAnimator(
new vector3df(100, 150, 80), 80.0f, 0.0005f);
light.addAnimator(anim);
anim.drop();
bill = device.getSceneManager().addBillboardSceneNode(light,
new dimension2df(40, 40));/*,
new vector3df(0, 0, 0),
-1);*/
bill.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
bill.setMaterialTexture(0, driver.getTexture("../media/particlewhite.bmp"));
bill.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
// create meta triangle selector with all triangles selectors in it.
metaSelector = sm.createMetaTriangleSelector();
metaSelector.addTriangleSelector(mapSelector);
// create camp fire
campFire = sm.addParticleSystemSceneNode(false);
campFire.setPosition(new vector3df(100, 120, 600));
campFire.setScale(new vector3df(2, 2, 2));
campFire.setParticleSize(new dimension2df(20.0f, 10.0f));
IParticleEmitter em = campFire.createBoxEmitter(
new aabbox3df(-7, 0, -7, 7, 1, 7),
new vector3df(0.0f, 0.03f, 0.0f),
80, 100,
new SColor(0, 255, 255, 255), new SColor(0, 255, 255, 255),
800, 2000);//, 0);
campFire.setEmitter(em);
em.drop();
IParticleAffector paf = campFire.createFadeOutParticleAffector();//new SColor(0, 0, 0, 0), 1000);
campFire.addAffector(paf);
paf.drop();
campFire.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
campFire.setMaterialTexture(0, driver.getTexture("../media/fireball.bmp"));
campFire.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_VERTEX_ALPHA);
// load music
if (music)
startSound();
// set background color
backColor.set(0, 0, 0, 0);
}
void createLoadingScreen()
{
dimension2di size = device.getVideoDriver().getScreenSize();
device.getCursorControl().setVisible(false);
// setup loading screen
backColor.set(255, 90, 90, 156);
// create in fader
inOutFader = device.getGUIEnvironment().addInOutFader();//null, null, -1);
inOutFader.setColor(backColor);
// irrlicht logo
device.getGUIEnvironment().addImage(device.getVideoDriver().getTexture("../media/irrlichtlogoalpha2.tga"),
new position2di(5,5));
// loading text
int lwidth = 280;
int lheight = 15;
recti pos = new recti(10, size.getHeight() - lheight - 10, 10 + lwidth, size.getHeight() - 10);
device.getGUIEnvironment().addImage(pos);
statusText = device.getGUIEnvironment().addStaticText("Loading...", pos, true);
statusText.setOverrideColor(new SColor(255, 205, 200, 200));
// load bigger font
device.getGUIEnvironment().getSkin().setFont(
device.getGUIEnvironment().getFont("../media/fonthaettenschweiler.bmp"));
// set new font color
device.getGUIEnvironment().getSkin().setColor(EGUI_DEFAULT_COLOR.EGDC_BUTTON_TEXT,
new SColor(255, 100, 100, 100));
}
void shoot()
{
ISceneManager sm = device.getSceneManager();
ICameraSceneNode camera = sm.getActiveCamera();
if (camera == null || mapSelector == null)
return;
TestTechdemoIrrklang.SParticleImpact imp = new TestTechdemoIrrklang.SParticleImpact();
imp.when = 0;
// get line of camera
vector3df start = camera.getPosition();
vector3df end = sub(camera.getTarget(), start);
end = end.normalize();
end = mult(end, camera.getFarValue());//start + (end * camera.getFarValue());
end = add(end, start);
triangle3df triangle = new triangle3df();
line3df line = new line3df(start, end);
// get intersection point with map
if (sm.getSceneCollisionManager().getCollisionPoint(
line, mapSelector, end, triangle))
{
// collides with wall
vector3df out = triangle.getNormal();
out.setLength(0.03f);
imp.when = 1;
imp.outVector = out;
imp.pos = end;
}
else
{
// doesnt collide with wall
end = sub(camera.getTarget(), start);
end = end.normalize();
end = add(start, mult(end, 1000));
}
// create fire ball
ISceneNode node = sm.addBillboardSceneNode(null,
new dimension2df(25, 25), start, -1);
node.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
node.setMaterialTexture(0, device.getVideoDriver().getTexture("../media/particle.bmp"));
node.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
float length = sub(end, start).getLength();
float speed = 0.3f;
int time = (int) (length / speed);
// set flight line
ISceneNodeAnimator anim = sm.createFlyStraightAnimator(start, end, time, true);
node.addAnimator(anim);
anim.drop();
anim = sm.createDeleteAnimator(time);
node.addAnimator(anim);
anim.drop();
if (imp.when != 0)
{
// create impact note
imp.when = (int) device.getTimer().getTime() + (time - 100);
//Impacts.push_back(imp);
Impacts.add(imp);
}
// play sound
if (ballSound != null)
{
play(ballSound);
}
}
private void play(File aSound)
{
try
{
AudioPlayer p = AudioPlayer.player;
AudioStream as = new AudioStream(new FileInputStream(aSound));
p.start(as);
}
catch (IOException e)
{
e.printStackTrace();
}
}
void createParticleImpacts()
{
long now = device.getTimer().getTime();
ISceneManager sm = device.getSceneManager();
for (int i = 0; i < Impacts.size(); ++i)
//if (now > Impacts[i].when)
if (now > (Impacts.elementAt(i)).when)
{
// create smoke particle system
IParticleSystemSceneNode pas;
pas = sm.addParticleSystemSceneNode(false,
null,
-1,
(Impacts.elementAt(i)).pos,
new vector3df(0, 0, 0),
new vector3df(1, 1, 1));
pas.setParticleSize(new dimension2df(10.0f, 10.0f));
IParticleEmitter em = pas.createBoxEmitter(
new aabbox3df(-5, -5, -5, 5, 5, 5),
(Impacts.elementAt(i)).outVector, 20, 40,
new SColor(0, 255, 255, 255), new SColor(0, 255, 255, 255),
1200, 1600, 20);
pas.setEmitter(em);
em.drop();
IParticleAffector paf = campFire.createFadeOutParticleAffector(new SColor(0, 0, 0, 0), 1000);
pas.addAffector(paf);
paf.drop();
pas.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
pas.setMaterialTexture(0, device.getVideoDriver().getTexture("../media/smoke.bmp"));
pas.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_VERTEX_ALPHA);
ISceneNodeAnimator anim = sm.createDeleteAnimator(2000);
pas.addAnimator(anim);
anim.drop();
// delete entry
Impacts.remove(i);
i--;
// play impact sound
if (impactSound != null)
{
play(impactSound);
}
}
}
public void startSound()
{
try
{
/*
* INITIALIZE
*/
String musicType = ".mp3";
File stream = new File("IrrlichtTheme" + musicType);
if (!stream.exists())
{
stream = new File("../media" + System.getProperty("file.separator") + "IrrlichtTheme" + musicType);
}
//play(stream);
final File finalStream = stream;
basicPlay(finalStream.getCanonicalPath(), true);
File ballFile = new File("ball.wav");
if (!ballFile.exists())
{
ballFile = new File("../media" + System.getProperty("file.separator") + "ball.wav");
}
try
{
ballSound = ballFile;
}
catch (Exception e)
{
e.printStackTrace();
}
File impactFile = new File("ball.wav");
if (!impactFile.exists())
{
impactFile = new File("../media" + System.getProperty("file.separator") + "impact.wav");
}
try
{
impactSound = impactFile;
}
catch (Exception e)
{
e.printStackTrace();
}
}
catch (Exception e)
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
}
// helper methods
private static vector3df add(vector3df a, vector3df b)
{
return new vector3df(a.getX() + b.getX(),
a.getY() + b.getY(),
a.getZ() + b.getZ());
}
private static vector3df sub(vector3df a, vector3df b)
{
return new vector3df(a.getX() - b.getX(),
a.getY() - b.getY(),
a.getZ() - b.getZ());
}
private static vector3df mult(vector3df a, float f)
{
return new vector3df(a.getX() * f,
a.getY() * f,
a.getZ() * f);
}
// mp3 audio using irrklang
private void basicPlay(final String aCanonicalPath, boolean loop)
{
ISoundEngine soundEngine = Jirrklang.createIrrKlangDevice();
soundEngine.play2D(aCanonicalPath, loop);
}
}