📄 defaultbehaviour.java
字号:
/* Ogre4J
Copyright (C) 2002 macross
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package org.ogre4j.demo;
import org.ogre4j.Camera;
import org.ogre4j.InputState;
import org.ogre4j.Root;
import org.ogre4j.event.FrameEvent;
import org.ogre4j.event.IFrameListener;
import org.ogre4j.event.IKeyListener;
import org.ogre4j.event.KeyEvent;
import org.ogre4j.math.Vector3;
/**
* DefaultBehaviour
*
* @author Ivica Aracic <ivica.aracic@bytelords.de>
*/
public class DefaultBehaviour
implements IKeyListener,
IFrameListener {
private Camera camera;
private Root root;
private Vector3 moveVec = new Vector3();
public DefaultBehaviour(Camera camera) {
this.root = Root.instance();
this.camera = camera;
}
public void keyClicked(KeyEvent e) {
if(e.getKey() == KeyEvent.KC_ESCAPE)
root.exit();
}
public void keyPressed(KeyEvent e) {
}
public void keyReleased(KeyEvent e) {
}
public void frameStarted(FrameEvent e) {
float dTime = e.getTimeSinceLastFrame();
InputState inputState = root.getInputState();
moveVec.set(Vector3.ZERO);
if(inputState.isKeyDown(KeyEvent.KC_UP)) {
moveVec.z = -1;
}
else if(inputState.isKeyDown(KeyEvent.KC_DOWN)) {
moveVec.z = +1;
}
if(inputState.isKeyDown(KeyEvent.KC_LEFT)) {
moveVec.x = -1;
}
else if(inputState.isKeyDown(KeyEvent.KC_RIGHT)) {
moveVec.x = +1;
}
else if(inputState.isKeyDown(KeyEvent.KC_PGDOWN)) {
moveVec.y = -1;
}
else if(inputState.isKeyDown(KeyEvent.KC_PGUP)) {
moveVec.y = +1;
}
moveVec.multThis(180*dTime);
camera.yaw(-inputState.getRelX()*100.0f);
camera.pitch(-inputState.getRelY()*100.0f);
camera.moveRelative(moveVec);
}
public void frameEnded(FrameEvent e) {
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -