I'm new to JME 2.01.
I just run HelloKeyInput.java,and find something wrong.
import java.net.URL;
import java.nio.FloatBuffer;
import com.jme.app.SimpleGame;
import com.jme.image.Texture;
import com.jme.input.KeyBindingManager;
import com.jme.input.KeyInput;
import com.jme.math.Vector2f;
import com.jme.math.Vector3f;
import com.jme.scene.TexCoords;
import com.jme.scene.TriMesh;
import com.jme.scene.state.TextureState;
import com.jme.util.TextureManager;
import com.jme.util.geom.BufferUtils;
/**
- Started Date: Jul 21, 2004<br>
- <br>
*
- This program demonstrates using key inputs to change things.
*
-
@author Jack Lindamood
*/
public class NewClass extends SimpleGame {
// The TriMesh that I will change
TriMesh square;
// A scale of my current texture values
float coordDelta;
public static void main(String[] args) {
NewClass app = new NewClass();
app.setConfigShowMode(ConfigShowMode.AlwaysShow);
app.start();
}
protected void simpleInitGame() {
// Vertex positions for the mesh
Vector3f[] vertexes = {
new Vector3f(0, 0, 0),
new Vector3f(1, 0, 0),
new Vector3f(0, 1, 0),
new Vector3f(1, 1, 0)
};
// Texture Coordinates for each position
coordDelta = 1;
Vector2f[] texCoords = {
new Vector2f(0,0),
new Vector2f(1,0),
new Vector2f(0,1),
new Vector2f(1,1)
};
// The indexes of Vertex/Normal/Color/TexCoord sets. Every 3 makes a
// triangle.
int[] indexes = { 0, 1, 2, 1, 2, 3 };
// Create the square
square = new TriMesh(“My Mesh”,
BufferUtils.createFloatBuffer(vertexes),
null,
null,
TexCoords.makeNew(texCoords),
BufferUtils.createIntBuffer(indexes));
// Point to the monkey image
URL monkeyLoc = HelloKeyInput.class.getClassLoader().getResource(
“jmetest/data/images/Monkey.jpg”);
// Get my TextureState
TextureState ts = display.getRenderer().createTextureState();
// Get my Texture
Texture t = TextureManager.loadTexture(monkeyLoc,
Texture.MinificationFilter.BilinearNearestMipMap,
Texture.MagnificationFilter.Bilinear);
// Set a wrap for my texture so it repeats
t.setWrap(Texture.WrapMode.Repeat);
// Set the texture to the TextureState
ts.setTexture(t);
// Assign the TextureState to the square
square.setRenderState(ts);
// Scale my square 10x larger
square.setLocalScale(10);
// Attach my square to my rootNode
rootNode.attachChild(square);
// Assign the “+” key on the keypad to the command “coordsUp”
KeyBindingManager.getKeyBindingManager().set(“coordsUp”,
KeyInput.KEY_ADD);
// Adds the “u” key to the command “coordsUp”
KeyBindingManager.getKeyBindingManager().add(“coordsUp”,
KeyInput.KEY_U);
// Assign the “-” key on the keypad to the command “coordsDown”
KeyBindingManager.getKeyBindingManager().set(“coordsDown”,
KeyInput.KEY_SUBTRACT);
}
// Called every frame update
protected void simpleUpdate() {
boolean updateTex = false;
// If the coordsDown command was activated
if (KeyBindingManager.getKeyBindingManager().isValidCommand(
“coordsDown”, true)) {
// Scale my texture down
coordDelta -= .01f;
updateTex = true;
}
// if the coordsUp command was activated
if (KeyBindingManager.getKeyBindingManager().isValidCommand(“coordsUp”,
true)) {
// Scale my texture up
coordDelta += .01f;
updateTex = true;
}
if (updateTex) {
// Get my square’s texture array
FloatBuffer texBuf = square.getTextureCoords((int)0.5).coords;
texBuf.rewind().position(2); // start after the 1st texcoord (2
// floats wide)
// Change the values of the texture coords in the buffer
texBuf.put(coordDelta).put(0);
texBuf.put(0).put(coordDelta);
texBuf.put(coordDelta).put(coordDelta);
}
}
}
This is the code.
Instead of a complete square,I got a square half of which is brighter.
Another is when i changed the value in “square.getTextureCoords((int)0.5).coords;” from 0.5 to 0,nothing happened.
If I change “int[] indexes = { 0, 1, 2, 1, 2, 3 };” into “int[] indexes = { 0, 1, 2, 2, 1, 3 };” ,
I’ll get a whole bright square.
Anyone could explain this?