Hi,
I am new to jirr and was following the tutorials.I have modifed one of the sample like this below.
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import net.sf.jirr.EEVENT_TYPE;
import net.sf.jirr.E_DRIVER_TYPE;
import net.sf.jirr.E_MATERIAL_FLAG;
import net.sf.jirr.E_MATERIAL_TYPE;
import net.sf.jirr.IAnimatedMesh;
import net.sf.jirr.IAnimatedMeshSceneNode;
import net.sf.jirr.ICameraSceneNode;
import net.sf.jirr.IEventReceiver;
import net.sf.jirr.IParticleAffector;
import net.sf.jirr.IParticleEmitter;
import net.sf.jirr.IParticleSystemSceneNode;
import net.sf.jirr.ISceneManager;
import net.sf.jirr.ISceneNode;
import net.sf.jirr.ISceneNodeAnimator;
import net.sf.jirr.IVideoDriver;
import net.sf.jirr.IrrlichtDevice;
import net.sf.jirr.Jirr;
import net.sf.jirr.SColor;
import net.sf.jirr.SColorf;
import net.sf.jirr.SEvent;
import net.sf.jirr.aabbox3df;
import net.sf.jirr.dimension2df;
import net.sf.jirr.dimension2di;
import net.sf.jirr.dimension2du;
import net.sf.jirr.vector3df;
public class TestSpecialFX1
{
static
{
System.loadLibrary("irrlicht_wrap");
}
static IrrlichtDevice device = null;
static protected final int READ_BUFFER_SIZE = 1000;
static ISceneNode node = null;
static IAnimatedMeshSceneNode gunnode = null;
static ISceneManager smgr = null;
static IVideoDriver driver = null;
public static void main(String[] args)
{
// ask if user would like shadows
int i;
boolean shadows = false;
System.out.println("Please press 'y' if you want to use realtime shadows.\n");
try
{
i = System.in.read();
shadows = (i == 'y');
}
catch (IOException e)
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
// ask user for driver
E_DRIVER_TYPE driverType = E_DRIVER_TYPE.EDT_SOFTWARE;
System.out.println("Please select the driver you want for this example:\n"
+ " (a) Direct3D 9.0c\n (b) Direct3D 8.1\n (c) OpenGL 1.2\n"
+ " (d) Software Renderer\n (e) Software Renderer 2\n (f) NullDevice\n (otherKey) exit\n\n");
try
{
i = System.in.read();
// ignore 0A and 0D on Windows (due to 0D 0A <=> line feed)
while (i == 10 || i == 13)
i = System.in.read();
switch (i)
{
case 'a':
driverType = E_DRIVER_TYPE.EDT_DIRECT3D9;
break;
case 'b':
driverType = E_DRIVER_TYPE.EDT_DIRECT3D8;
break;
case 'c':
driverType = E_DRIVER_TYPE.EDT_OPENGL;
break;
case 'd':
driverType = E_DRIVER_TYPE.EDT_SOFTWARE;
break;
case 'e':
driverType = E_DRIVER_TYPE.EDT_BURNINGSVIDEO;
break;
case 'f':
driverType = E_DRIVER_TYPE.EDT_NULL;
break;
default:
System.out.println("i = " + i);
System.exit(0);
}
}
catch (IOException e)
{
e.printStackTrace(); //To change body of catch statement use Options | File Templates.
}
// create device and exit if creation failed
device = Jirr.createDevice(driverType, new dimension2di(640, 480), 32, false, shadows, false, new MyEventReceiver());
if (device == null)
System.exit(1); // could not create selected driver.
driver = device.getVideoDriver();
smgr = device.getSceneManager();
new TestSpecialFX1().loadResources();
IAnimatedMesh mesh = smgr.getMesh("../media/room.3ds");
smgr.getMeshManipulator().makePlanarTextureMapping(mesh.getMesh(0), 0.004f);
//ISceneNode node = smgr.addAnimatedMeshSceneNode(mesh);
node = smgr.addAnimatedMeshSceneNode(mesh);
node.setMaterialTexture(0, driver.getTexture("../media/wall.jpg"));
node.getMaterial(0).setSpecularColor(new SColor(0, 0, 0, 0));
//node.getMaterial(0).setEmissiveColor(new SColor(0, 0, 0, 0));
//node.getMaterial(0).setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ALPHA_CHANNEL_REF);
// add animated water
// mesh = smgr.addHillPlaneMesh("myHill",
// new dimension2df(20, 20),
// new dimension2di(40, 40), null, 0.0f,
// new dimension2df(0, 0),
// new dimension2df(10, 10));
mesh = smgr.addHillPlaneMesh("myHill",
new dimension2df(20, 20),
new dimension2du(40, 40), null, 0.0f,
new dimension2df(0, 0),
new dimension2df(10, 10));
// node = smgr.addWaterSurfaceSceneNode(mesh.getMesh(0), 3.0f, 300.0f, 30.0f);
// node.setPosition(new vector3df(0, 7, 0));
//
// node.setMaterialTexture(0, driver.getTexture("../media/stones.jpg"));
// node.setMaterialTexture(1, driver.getTexture("../media/water.jpg"));
// node.setMaterialType(E_MATERIAL_TYPE.EMT_REFLECTION_2_LAYER);
// adding gun to the node
// loading a gun
mesh = smgr.getMesh("../media/ak47.3ds");
//IAnimatedMeshSceneNode gunnode = smgr.addAnimatedMeshSceneNode(mesh);
gunnode = smgr.addAnimatedMeshSceneNode(mesh);
gunnode.setPosition(new vector3df(-50, 30, -60));
// gunnode.setRotation(new vector3df(-300, 60, -30));
// create light
node = smgr.addLightSceneNode(null, new vector3df(0, 0, 0),
new SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
ISceneNodeAnimator anim = smgr.createFlyCircleAnimator(new vector3df(0, 150, 0), 250.0f);
node.addAnimator(anim);
anim.drop();
// attach billboard to light
node = smgr.addBillboardSceneNode(node, new dimension2df(50, 50));
node.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
node.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
node.setMaterialTexture(0, driver.getTexture("../media/particlewhite.bmp"));
// create a particle system
IParticleSystemSceneNode ps = smgr.addParticleSystemSceneNode(false);
ps.setPosition(new vector3df(-70, 60, 40));
ps.setScale(new vector3df(2, 2, 2));
ps.setParticleSize(new dimension2df(20.0f, 20.0f));
IParticleEmitter em = ps.createBoxEmitter(
new aabbox3df(-7, 0, -7, 7, 1, 7),
new vector3df(0.0f, 0.06f, 0.0f),
80, 100,
new SColor(0, 255, 255, 255), new SColor(0, 255, 255, 255),
800, 2000);
ps.setEmitter(em);
em.drop();
IParticleAffector paf =
ps.createFadeOutParticleAffector();
ps.addAffector(paf);
paf.drop();
ps.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
ps.setMaterialTexture(0, driver.getTexture("../media/fire.bmp"));
ps.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_VERTEX_ALPHA);
// add animated character
// mesh = smgr.getMesh("../media/dwarf.x");
// IAnimatedMeshSceneNode anode = smgr.addAnimatedMeshSceneNode(mesh);
// anode.setPosition(new vector3df(-50, 20, -60));
// anode.setAnimationSpeed(15);
//
// // add shadow
// anode.addShadowVolumeSceneNode();
// smgr.setShadowColor(new SColor(150, 0, 0, 0));
//
// // make the model a little bit bigger and normalize its normals
// // because of this for correct lighting
// anode.setScale(new vector3df(2,2,2));
// anode.setMaterialFlag(E_MATERIAL_FLAG.EMF_NORMALIZE_NORMALS, true);
/*
Finally we simply have to draw everything, that's all.
*/
ICameraSceneNode camera = smgr.addCameraSceneNodeFPS();
camera.setPosition(new vector3df(-50, 50, -150));
// disable mouse cursor
device.getCursorControl().setVisible(false);
int lastFPS = -1;
while (device.run())
{
if (device.isWindowActive())
{
driver.beginScene(true, true, new SColor(0, 0, 0, 0));
smgr.drawAll();
driver.endScene();
int fps = driver.getFPS();
if (lastFPS != fps)
{
String str = "Irrlicht Engine @Java - SpecialFX example [";
str += driver.getName();
str += "] FPS:";
str += fps;
device.setWindowCaption(str);
lastFPS = fps;
}
}
}
device.drop();
System.exit(0);
}
static class MyEventReceiver extends IEventReceiver
{
public boolean OnEvent(SEvent event)
{
/*
If the key 'W' or 'S' was left up, we get the position of the scene node,
and modify the Y coordinate a little bit. So if you press 'W', the node
moves up, and if you press 'S' it moves down.
*/
//X = 20 Y = -182.0 Z 0.0
//X = 20 Y = -32.0 Z 0.0 (GUN POSTION TO BE USED)
if (node != null && event.getEventType() == EEVENT_TYPE.EET_KEY_INPUT_EVENT &&
!event.isKeyInputPressedDown())
{
// 223 <=> ignore upper and lower case
switch (event.getKeyInputChar() & 223)
{
case KeyEvent.VK_A:
{
// rotate on x-axis
System.out.println(" A KEY WAS PRESSED");
vector3df v = gunnode.getRotation();
System.out.println("X "+v.getX());
System.out.println("Y "+v.getY());
System.out.println("Z "+v.getZ());
v.setX(v.getX()+((event.getKeyInputChar() & 223) == KeyEvent.VK_W ? 2.0f : -2.0f));
gunnode.setRotation(v);
break;
}
case KeyEvent.VK_Q:
{
// rotate on Y-axis
System.out.println(" Q KEY WAS PRESSED");
vector3df v = gunnode.getRotation();
System.out.println("X "+v.getX());
System.out.println("Y "+v.getY());
System.out.println("Z "+v.getZ());
v.setY(v.getY()+((event.getKeyInputChar() & 223) == KeyEvent.VK_W ? 2.0f : -2.0f));
gunnode.setRotation(v);
break;
}
case KeyEvent.VK_Z:
{
// rotate on Y-axis
System.out.println(" Z KEY WAS PRESSED");
vector3df v = gunnode.getRotation();
System.out.println("X "+v.getX());
System.out.println("Y "+v.getY());
System.out.println("Z "+v.getZ());
v.setX(v.getX()+((event.getKeyInputChar() & 223) == KeyEvent.VK_W ? 2.0f : +2.0f));
gunnode.setRotation(v);
break;
}
case KeyEvent.VK_X:
{
// rotate on Y-axis
System.out.println(" x KEY WAS PRESSED");
vector3df v = gunnode.getRotation();
System.out.println("X "+v.getX());
System.out.println("Y "+v.getY());
System.out.println("Z "+v.getZ());
v.setZ(v.getZ()-((event.getKeyInputChar() & 223) == KeyEvent.VK_W ? 2.0f : +2.0f));
gunnode.setRotation(v);
break;
}
case KeyEvent.VK_C:
{
// rotate on Y-axis
System.out.println(" C KEY WAS PRESSED");
//node = smgr.addLightSceneNode(null, new vector3df(0, 0, 0),new SColorf(1.0f, 0.6f, 0.7f, 1.0f), 600.0f);
node = smgr.addLightSceneNode();
node = smgr.addBillboardSceneNode(node, new dimension2df(15, 15));
node.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
node.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
node.setMaterialTexture(0, driver.getTexture("../media/fire.bmp"));
// ISceneNode lightnode = smgr.addAnimatedMeshSceneNode(mesh);
// lightnode.setMaterialFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
// lightnode.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
// lightnode.setMaterialTexture(0, driver.getTexture("../media/fire.bmp"));
break;
}
case KeyEvent.VK_W:
break;
case KeyEvent.VK_S:
{
vector3df v = gunnode.getPosition();
System.out.println("" + v.getY());
v.setY(v.getY() + ((event.getKeyInputChar() & 223) == KeyEvent.VK_W ? 2.0f : -2.0f));
node.setPosition(v);
System.out.println("new y " + v.getY());
}
return true;
}
}
return false;
}
}
protected void loadResources()
{
try
{
// The EngineManager assumes that there is a file called media.zip, either in the
// JAR file downloaded via Webstart, or just in the current working directory.
// Webstart doesn't allow you to know the name of the local JAR filename in the cache,
// but we can get access to the media.zip file easily enough with a call to
// getResourceAsStream. Once we get access to that file stream we can copy
// the media.zip file out into a known temporary location and give Irrlicht
// access to it there.
// get the file stream (should be null for a local app, and not null for a webstart app)
InputStream in = this.getClass().getResourceAsStream("media.zip");
if (in != null)
{
// find a unique temporary file name
int i = 0;
String tempDir = System.getProperty("java.io.tmpdir");
File file = null;
do
{
++i;
file = new File(tempDir + "media" + i + ".zip");
} while (file.exists());
// write the output file
String filename = file.getPath();
OutputStream out = new FileOutputStream(filename);
int c;
byte[] buffer = new byte[READ_BUFFER_SIZE];
while ((c = in.read(buffer)) != -1)
{
out.write(buffer, 0, c);
}
in.close();
out.close();
System.out.println("addZipFileArchive: " + file);
device.getFileSystem().addZipFileArchive(file.getPath());
}
else
{
// otherwise assume there is a file called media.zip
System.out.println("addZipFileArchive: media.zip");
device.getFileSystem().addZipFileArchive("media.zip");
}
}
catch (Exception ex)
{
}
}
}
The program work like this.If I press 'C' button in keypad, a fire image should blow in the screen.But the problem is it is not working as expected.I am not able to figure out what is the issue.
Thanks,
problem wih lights
problem wih lights
somehow I was able to correct it.the image loaded.But now the problem is we can see the square box in which the image has included.I have added transparent to it.Still it is coming a square box.I do not know how to remove that.Please shed some light if any knows it.
Thanks in advance
Thanks in advance
-
- Posts: 1186
- Joined: Fri Dec 29, 2006 12:04 am
Re: problem wih lights
Please post a minimal compilable snippet which reproduces the problem.
Thousands of 'System.out.println' really make browsing the code harder.
And using code-tags would help to improve readability too.
Thousands of 'System.out.println' really make browsing the code harder.
And using code-tags would help to improve readability too.
"Whoops..."