Jirr and Irrlicht custom scene nodes

Discussion about Irrlicht's Java wrapper
Post Reply
de3000
Posts: 20
Joined: Tue Sep 19, 2006 4:57 pm
Location: South Africa

Jirr and Irrlicht custom scene nodes

Post by de3000 »

With the latest release of Jirr i have decided to try and convert Irrlicht custom scene nodes to Jirr.

If any of the creators do not wish me to do so then pm me or just post it here.

So far all i have done is a cube custom node which im still working on for my tactics game called MightBlade (Name might change).

Although it seems as if nobody is intrested here is the custom cube code

Code: Select all

public class CCubeTile extends ISceneNode
{
    public enum E_CUBE_EDGE
    {
	ECE_TOP_NW, ECE_TOP_NE, ECE_TOP_SW, ECE_TOP_SE, ECE_BOTTOM_NW, ECE_BOTTOM_NE, ECE_BOTTOM_SW, ECE_BOTTOM_SE
    }
    
    public static final SColor S_COLOR = GameColour.WHITE;
    private aabbox3df Box = new aabbox3df(0, 0, 0, 0, 0, 0);
    private S3DVertex Vertices[] = new S3DVertex[12];
    private SMaterial Material = new SMaterial();
    private ISceneManager SceneManager;
    private int cubeSize;
    
    public CCubeTile(ISceneNode parent, ISceneManager mgr, IVideoDriver driver, int id, int size, GameTile tile)
    {
	super(parent, mgr, id);
	SceneManager = mgr;
	cubeSize = size;
	Material.setFlag(E_MATERIAL_FLAG.EMF_WIREFRAME, false);
	Material.setFlag(E_MATERIAL_FLAG.EMF_LIGHTING, false);
	if (tile != null)
	{
	    ITexture tex = driver.getTexture(tile.getTexture());
	    Material.setTexture(0, tex);
	    matrix4 rotate = new matrix4();
	    rotate.makeIdentity();
	    rotate.setTextureRotationCenter((tile.getTexRot()) / 360);//tRotationDegrees(new vector3df(tile.getTexRot(), tile.getTexRot(),tile.getTexRot()));
	    Material.setTextureMatrix(0, rotate);
	}
	//getMaterial(0).setTexture(0, SceneManager.getVideoDriver().getTexture("./media/unused/wall.jpg"));
	Vertices[0] = new S3DVertex(0, 0, 0, -1, -1, -1, S_COLOR, 0, 1);
	Vertices[1] = new S3DVertex(1, 0, 0, 1, -1, -1, S_COLOR, 1, 1);
	Vertices[2] = new S3DVertex(1, 1, 0, 1, 1, -1, S_COLOR, 1, 0);
	Vertices[3] = new S3DVertex(0, 1, 0, -1, 1, -1, S_COLOR, 0, 0);
	Vertices[4] = new S3DVertex(1, 0, 1, 1, -1, 1, S_COLOR, 0, 1);
	Vertices[5] = new S3DVertex(1, 1, 1, 1, 1, 1, S_COLOR, 0, 0);
	Vertices[6] = new S3DVertex(0, 1, 1, -1, 1, 1, S_COLOR, 1, 0);
	Vertices[7] = new S3DVertex(0, 0, 1, -1, -1, 1, S_COLOR, 1, 1);
	Vertices[8] = new S3DVertex(0, 1, 1, -1, 1, 1, S_COLOR, 0, 1);
	Vertices[9] = new S3DVertex(0, 1, 0, -1, 1, -1, S_COLOR, 1, 1);
	Vertices[10] = new S3DVertex(1, 0, 1, 1, -1, 1, S_COLOR, 1, 0);
	Vertices[11] = new S3DVertex(1, 0, 0, 1, -1, -1, S_COLOR, 0, 0);
	Box.reset(Vertices[0].getPos());
	for (int i = 0; i < Vertices.length; ++i)
	{
	    Vertices[i].setPos(Vertices[i].getPos().subtractOperator(new vector3df(0.5f, 0.5f, 0.5f)));
	    Vertices[i].setPos(Vertices[i].getPos().timesOperator(cubeSize * 2));
	    if (i != 0) Box.addInternalPoint(Vertices[i].getPos());
	}
    }
    
    public void OnRegisterSceneNode()
    {
	if (isVisible())
	{
	    SceneManager.registerNodeForRendering(this, E_SCENE_NODE_RENDER_PASS.ESNRP_TRANSPARENT);
	}
	OnRegisterSceneNodeJava();
    }
    
    public void render()
    {
	int indices[] = { 0, 2, 1,/**/0, 3, 2,/**/1, 5, 4,/**/1, 2, 5,/**/4, 6, 7,/**/4, 5, 6,
	/**/7, 3, 0,/**/7, 6, 3,/**/9, 5, 2,/**/9, 8, 5,/**/0, 11, 10,/**/0, 10, 7 };
	IVideoDriver driver = SceneManager.getVideoDriver();
	driver.setMaterial(Material);
	driver.setTransform(E_TRANSFORMATION_STATE.ETS_WORLD, getAbsoluteTransformation());
	driver.drawIndexedTriangleList(Vertices, Vertices.length, indices, indices.length / 3);
    }
    
    /*
     0		011         111
     1	  	  /6--------/5        y
     2	 	 /  |      / |        ^  z
     3		/   |     /  |        | /
     4      010 3---------2  |        |/
     5		|   7- - -| -4 101    *---->x
     6		|  /      |  /
     7		|/        | /
     8		0---------1/
     9	       000       100       
     */
    public void morph(E_CUBE_EDGE edge, vector3df newpos)
    {
	switch (edge)
	{
	    case ECE_TOP_NW:
		morph(6, newpos);
		morph(8, newpos);
		break;
	    case ECE_TOP_NE:
		morph(5, newpos);
		break;
	    case ECE_TOP_SW:
		morph(3, newpos);
		morph(9, newpos);
		break;
	    case ECE_TOP_SE:
		morph(2, newpos);
		break;
	    case ECE_BOTTOM_NW:
		morph(7, newpos);
		break;
	    case ECE_BOTTOM_NE:
		morph(4, newpos);
		morph(10, newpos);
		break;
	    case ECE_BOTTOM_SW:
		morph(0, newpos);
		break;
	    case ECE_BOTTOM_SE:
		morph(1, newpos);
		morph(11, newpos);
		break;
	    default:
		return;
	}
    }
    
    public void setDebugColour(SColor col)
    {
	for (int i = 0; i < Vertices.length; ++i)
	{
	    Vertices[i].setColor(col);
	}
    }
    
    public void morph(E_CUBE_EDGE edge, int height)
    {
	morph(edge, new vector3df(0, height, 0));
    }
    
    private void morph(int side, vector3df newpos)
    {
	S3DVertex old = Vertices[side];
	old.setPos(old.getPos().addOperator(newpos));
	Vertices[side] = old;
    }
    
    public aabbox3df getBoundingBoxConst()
    {
	return Box;
    }
    
    public long getMaterialCount()
    {
	return 1;
    }
    
    public SMaterial getMaterial(long i)
    {
	return Material;
    }
}
de3000
Posts: 20
Joined: Tue Sep 19, 2006 4:57 pm
Location: South Africa

Post by de3000 »

Here is a little motion trail thingy that I found in the beginners forums which I ported to jirr and made it work. Well sort of work because there is no way yet of geting a texture from a material without getting a SWIG_array of textures. Maybe in the next version of jirr we will have that.

Code: Select all

for (int b = 1; b < 3; b++)//5 is the number of trailers created 
		    {
			IAnimatedMeshSceneNode node = sceneManager.addAnimatedMeshSceneNode(getMeshNode().getMesh(),null,-1,getMeshNode().getPosition(),getMeshNode().getRotation());
			SMaterial mat=node.getMaterial(0);
			mat.setMaterialType(E_MATERIAL_TYPE.EMT_TRANSPARENT_ADD_COLOR);
			mat.setShininess(1.0f);
			mat.setSpecularColor(new SColor(100,255,0,0));
			mat.setZWriteEnable(false);
			node.setMaterial(0, mat);
			node.setFrameLoop(getMeshNode().getFrameNr(), getMeshNode().getEndFrame());
			node.setAnimationSpeed(0);			
			if (node != null)
			{
			    node.addAnimator(sceneManager.createDeleteAnimator(200));
			    sceneManager.getMeshManipulator().setVertexColors(node.getMesh().getMesh(getMeshNode().getFrameNr()),new SColor(100/(b*5),255,100,255));
			    node.render();
			}
			System.out.println("Motion Trail:" + b+" "+node);
			sceneManager.getMeshManipulator().setVertexColors(getMeshNode().getMesh().getMesh(getMeshNode().getFrameNr()),new SColor(255,255,255,255));
		    }
jirr
Posts: 36
Joined: Sat Feb 19, 2005 8:05 am

Post by jirr »

Ok, I will add a proper method for getting the Texture(s) ;)

In the meantime let me explain why I did not see a special need for a java compatible texture getter: though it requires you to keep track of nodes and their textures by yourself it is possible to do so using a Hashtable etc. because you as the programmer are deciding which node will get which texture(s).
Post Reply