📄 collisionbox.java
字号:
/*
* CollisionBox.java
*/
package org.java3dgamesdk.samples.IV;
import javax.media.j3d.*;
import javax.vecmath.*;
import org.java3dgamesdk.core.*;
import org.java3dgamesdk.core.util.*;
import org.java3dgamesdk.graphics.*;
import org.java3dgamesdk.graphics.util.*;
import org.java3dgamesdk.graphics.MS3D.*;
/**
*
* @author Norbert Nopper
*/
public class CollisionBox extends GameFrame {
private MS3DModel jeep;
private DisplayBoundingBox box;
/**
* Variable to remember the last time.
*/
private long lastTime;
/**
* Time delat.
*/
private double rotate;
public static void main(String[] argv) {
// create the object
CollisionBox application = new CollisionBox();
// create the object and pass the game frame to it ...
RenderSelection renderSelection = new RenderSelection(application);
// ... rest is done by the dialog
renderSelection.show();
}
/**
* The game mouse is enabled here and also the cursor is changed as well.
*/
protected void initGame() {
// enable the game mouse
gameMouse = true;
// make an invisible cursor
canvas3d.setCursor(GameMouse.CURSOR_TRANSPARENT);
MS3DLoader loader = new MS3DLoader();
jeep = loader.loadModel("JeepOne", "jeep1.ms3d");
jeep.worldZ = -50.0;
box = new DisplayBoundingBox(loader.getBoundingBox());
box.worldZ = -50.0;
// add light to the scene
gc3D.addLight(new AmbientLight());
}
/**
* For this sample we do not need the method right now.
*
*@param currentTime the current game time in miliseconds, starting with 0
*/
protected void updateGame(long currentTime) {
if(gameKeys[27])
exit();
// calculate the rotation depending on the time
rotate = (double)(currentTime-lastTime)/1000.0;
jeep.rotY += rotate*(double)deltaX;
box.rotY += rotate*(double)deltaX;
// rotate if the mouse was moved vertical
jeep.rotX += rotate*(double)deltaY;
box.rotX += rotate*(double)deltaY;
jeep.update(currentTime);
box.update(currentTime);
// remember the last time
lastTime = currentTime;
}
protected void renderGame() {
gc3D.clear();
jeep.draw(gc3D);
box.draw(gc3D);
}
/**
* Set up the old cursor.
*/
protected void exitGame() {
// go back to the default cursor
canvas3d.setCursor(GameMouse.CURSOR_DEFAULT);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -