I have written a class that draws a triangle with TriMesh and is then supposed to put red in 1 corner and green in the other two corners. I then added key bindings so that when you press the G key it is supposed to move the red color to a different corner and then the greens to the other two corners. Here is my code:
/**
*
* @author Josh Branchaud
* @version 12/3/2008
*/
// imported classes
import com.jme.app.SimpleGame;
import com.jme.scene.TriMesh;
import com.jme.math.Vector3f;
import com.jme.math.Vector2f;
import com.jme.renderer.ColorRGBA;
import com.jme.bounding.BoundingBox;
import com.jme.util.geom.BufferUtils;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
public class rotateColor1 extends SimpleGame
{
KeyBindingManager KBM = KeyBindingManager.getKeyBindingManager();
TriMesh triMesh1;
// create the colors here
ColorRGBA[] colors =
{
new ColorRGBA(1,0,0,1),
new ColorRGBA(1,0,0,1),
new ColorRGBA(0,1,0,1)
};
protected void simpleInitGame()
{
// create an instance of the TriMesh
triMesh1 = new TriMesh("TriMesh1");
// create vectors for the TriMesh
Vector3f[] vectorArray =
{
new Vector3f(0,0,0),
new Vector3f(2,2,0),
new Vector3f(0,4,0)
};
// create texture Coordinates for the bufferUtil
Vector2f[] texCoords =
{
new Vector2f(0,0),
new Vector2f(2,2),
new Vector2f(0,4)
};
int[] indexes =
{
1,2,3
};
triMesh1.reconstruct
(BufferUtils.createFloatBuffer(vectorArray),
null,
BufferUtils.createFloatBuffer(colors),
BufferUtils.createFloatBuffer(texCoords),
BufferUtils.createIntBuffer(indexes));
// create and update model bound for triMesh1
triMesh1.setModelBound(new BoundingBox());
triMesh1.updateModelBound();
// add triMesh1 to the rootNode
rootNode.attachChild(triMesh1);
// get rid of default lighting
lightState.setEnabled(false);
// set an action to KEY_G
KBM.set("rotate", KeyInput.KEY_G);
}
protected void simpleUpdate()
{
if(KBM.isValidCommand("rotate", false))
{
ColorRGBA color1, color2, color3;
color1 = colors[0];
color2 = colors[1];
color3 = colors[2];
colors[0] = color3;
colors[1] = color1;
colors[2] = color2;
}
}
public static void main(String[] args)
{
rotateColor1 thisWorld = new rotateColor1();
thisWorld.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG);
thisWorld.start();
}
}
Any ideas of what I am doing wrong?