发现BlogJava没以前人气旺了...首页都没啥人更新了..那我在写一个吧.
一个小程序 ..支持鼠标左键点击 右键按下可旋转 缩略图可以展示被点击的物体.

功能:左边是个缩略图.白框外面是场景...要求点击场景中的任何一个物体并且将物体显示在缩略图中..并且鼠标要求左键无法移动视角只可点击..右键只有在按下时 才可旋转视角.
要实现这个效果..我们一步一步来..
首先是初始化 我们先将 摄象机 灯光 模型 等等都将在这里一次生成.
protected void simpleInitGame() {
display.setTitle("PickBox Demo");
// 安装摄象机
cam.setFrustumPerspective(45.0f, (float) display.getWidth()
/ (float) display.getHeight(), 1, 5000);
cam.setLocation(new Vector3f(200, 150, 200));
cam.lookAt(new Vector3f(0, 0, 0), Vector3f.UNIT_Y);
cam.update();
pr = new BoundingPickResults();
am = new AbsoluteMouse("The Mouse", display.getWidth(), display
.getHeight());
am.registerWithInputHandler(input);
// 安装灯光系统
PointLight light = new PointLight();
light.setDiffuse(new ColorRGBA(1.0f, 1.0f, 1.0f, 1.0f));
light.setAmbient(new ColorRGBA(0.5f, 0.5f, 0.5f, 1.0f));
light.setLocation(new Vector3f(0, 30, 0));
light.setEnabled(true);
lightState.attach(light);
// Objects 所有可选的物体都将加到这个Node里 rootNode.attachChild(createObjects());
// Setup renderpasses
RenderPass rootPass = new RenderPass();
rootPass.add(rootNode);
pManager.add(rootPass);
createDebugQuads();
statNode.attachChild(debugQuadsNode);
//为了让鼠标左键不随鼠标自动旋转视角 我们首先要将鼠标释放出来
MouseInput.get().setCursorVisible(true);
}
//objects 所有可以让鼠标选择的物体都应该加载到这个Node上面
//因为我们会在Update方法中 使用BoundingPickResults 来寻找这个Node
private Node createObjects() {
objects = new Node("objects");
ts = display.getRenderer().createTextureState();
Texture t0 = TextureManager.loadTexture(PickBoxDemo.class.getClassLoader()
.getResource("jmetest/data/texture/wall.jpg"),
Texture.MinificationFilter.Trilinear,
Texture.MagnificationFilter.Bilinear);
t0.setWrap(Texture.WrapMode.Repeat);
ts.setTexture(t0);
textureBox = new Box("box1", new Vector3f(-10, -10, -10), new Vector3f(10,
10, 10));
textureBox.setLocalTranslation(new Vector3f(0, 10, 0));
textureBox.setRenderState(ts);
textureBox.setModelBound(new BoundingBox());
textureBox.updateModelBound();
objects.attachChild(textureBox);
whiteBox = new Box("box2", new Vector3f(-5, -5, -5), new Vector3f(5, 5, 5));
whiteBox.setLocalTranslation(new Vector3f(0, 30, 0));
whiteBox.setModelBound(new BoundingBox());
whiteBox.updateModelBound();
objects.attachChild(whiteBox);
shadowBox = new Box("sn", new Vector3f(-5, -5, -5), 5, 5, 5);
shadowBox.setLocalTranslation(new Vector3f(0, 10, 10));
shadowBox.setModelBound(new BoundingBox());
shadowBox.updateModelBound();
return objects;
}
下面将创建缩略图周围的白色框框
private void createDebugQuads() {
tRenderer = display.createTextureRenderer(256, 256,
TextureRenderer.Target.Texture2D);
tRenderer.getCamera().setAxes(new Vector3f(-1, 0, 0),
new Vector3f(0, 0, 1), new Vector3f(0, 1, 0));
tRenderer.getCamera().setLocation(new Vector3f(0, -100, 20));
monitorNode = new Node("Monitor Node");
monitorNode.setRenderQueueMode(Renderer.QUEUE_ORTHO);
Quad quad = new Quad("Monitor");
quad.updateGeometry(250, 250);
quad.setLocalTranslation(new Vector3f(150, 210, 0));
quad.setZOrder(1);
monitorNode.attachChild(quad);
Quad quad2 = new Quad("Monitor Back");
quad2.updateGeometry(270, 270);
quad2.setLocalTranslation(new Vector3f(150, 210, 0));
quad2.setZOrder(2);
monitorNode.attachChild(quad2);
ZBufferState buf = display.getRenderer().createZBufferState();
buf.setEnabled(fa