JME배우기 - 5(SimpleGame상속해서 구현해보자)
2008. 5. 28. 11:11ㆍJava
package com.oktab.ncanis;
import com.jme.app.SimpleGame;
import com.jme.bounding.BoundingBox;
import com.jme.image.Texture;
import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.shape.Sphere;
import com.jme.scene.state.TextureState;
import com.jme.util.LoggingSystem;
import com.jme.util.TextureManager;
/**
* TestSphere extends SimpleGame giving us a basic framework.
*/
public class Test extends SimpleGame {
//required values for rotating the sphere
private Quaternion rotQuat = new Quaternion();
private float angle = 0;
private Vector3f axis = new Vector3f(1, 1, 0);
//the Sphere to render
private Sphere s;
/**
* Entry point for the test,
* @param args
*/
public static void main(String[] args) {
LoggingSystem.getLogger().setLevel(java.util.logging.Level.OFF); // 로깅 레벨?
Test app = new Test();
app.setDialogBehaviour(ALWAYS_SHOW_PROPS_DIALOG); //항상 디스플레이 설정 다이얼로그 보여줌
app.start(); // 최종적으로 BaseGame.start()를 호출하겠지
}
/**
* updates an angle and applies it to a quaternion
* to rotate the Sphere.
*/
protected void simpleUpdate() {
if (tpf < 1) { //tpf는 SimpleGame에 선언되어있다. frame 당 time
angle = angle + (tpf * 1); // 즉 프레임이 올라갈수록 각도를 증가시키는데 360프레임 즉 360도 각도를 넘어서면 0으로 초기화한다.
if (angle > 360) {
angle = 0;
}
}
rotQuat.fromAngleAxis(angle, axis); //Quaternion으로부터 angle와 vec axis를 넘겨 인자를 생성
s.setLocalRotation(rotQuat); // 구를 회전시킨다.
}
/**
* builds the Sphere and applies the Monkey texture.
*/
protected void simpleInitGame() {
display.setTitle("jME - Sphere");
s = new Sphere("Sphere", 63, 50, 25);
s.setLocalTranslation(new Vector3f(0,0,-40));
s.setModelBound(new BoundingBox());
s.updateModelBound();
rootNode.attachChild(s); // 노드에 구를 붙인다.
// 텍스쳐 이미지 등록
TextureState ts = display.getRenderer().createTextureState();
ts.setEnabled(true);
ts.setTexture(
TextureManager.loadTexture(
Test.class.getClassLoader().getResource(
"com/oktab/ncanis/gunyoung.jpg"),
Texture.MM_LINEAR_LINEAR,
Texture.FM_LINEAR));
rootNode.setRenderState(ts);
}
}
실행결과는 다음과 같다. 문근영 사진을 돌려봤다.
W Move Forward
A Strafe Left
S Move Backward
D Strafe Right
Up Look Up
Down Look Down
Left Look Left
Right Look Right
T Wireframe Mode on/off
P Pause On/Off
L Lights On/Off
C Print Camera Position
B Bounding Volumes On/Off
N Normals On/Off
F1 Take Screenshot