📄 obstacle.java
字号:
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.io.*;
import java.lang.*;
import com.mascotcapsule.micro3d.v3.*;
/*
* Obstacle class - a root of all object placed in our world.
* It contains object's layout, current position, angles and rotation
*/
public class Obstacle
{
protected AffineTrans move = new AffineTrans();
protected AffineTrans rotX = new AffineTrans();
protected AffineTrans rotY = new AffineTrans();
protected AffineTrans rotZ = new AffineTrans();
private AffineTrans trans = new AffineTrans();
protected FigureLayout layout = new FigureLayout();
protected int mSpinAngleX = 0;
protected int mSpinAngleY = 0;
protected int mSpinAngleZ = 0;
// returns this object layout
public FigureLayout getLayout() { return layout; }
// constructor
public Obstacle(int aPosX, int aPosY, int aPosZ,
int aRX, int aRY, int aRZ,
int aWidth, int aHeight,
AffineTrans aCamTrans, AffineTrans aTmpAT)
{
move.setIdentity();
move(aPosX, aPosY, aPosZ);
rotate(aRX, aRY, aRZ);
aTmpAT.setIdentity();
aTmpAT.mul(move, rotX);
trans.setIdentity();
trans.mul(aCamTrans, aTmpAT);
layout.setAffineTrans( trans );
layout.setPerspective(1, 14096, 512);
layout.setCenter(aWidth/2, aHeight/2);
}
// update objects position according to camera
public void updateCamPosition(AffineTrans aCamTrans, AffineTrans aTmpAT)
{
aTmpAT.setIdentity();
aTmpAT.mul(move, rotX);
trans.setIdentity();
trans.mul(aCamTrans, aTmpAT);
}
// move object
public void move(int aPosX, int aPosY, int aPosZ)
{
move.m03 += aPosX;
move.m13 += aPosY;
move.m23 += aPosZ;
}
// rotate object
public void rotate(int aRX, int aRY, int aRZ)
{
mSpinAngleX += aRX;
mSpinAngleY += aRY;
mSpinAngleZ += aRZ;
if(mSpinAngleX >= 2048)
mSpinAngleX = mSpinAngleX - 4096;
else if( mSpinAngleX <= -2048 )
mSpinAngleX = mSpinAngleX + 4096;
if(mSpinAngleY >= 4096)
mSpinAngleY = mSpinAngleY - 4096;
else if( mSpinAngleY <= 0 )
mSpinAngleY = mSpinAngleY + 4096;
if(mSpinAngleZ >= 4096)
mSpinAngleZ = mSpinAngleZ - 4096;
else if( mSpinAngleZ <= 0 )
mSpinAngleZ = mSpinAngleZ + 4096;
rotX.setIdentity();
rotX.rotationX(mSpinAngleX); // rotate X
rotY.setIdentity();
rotY.rotationY(mSpinAngleY); // rotate Y
rotZ.setIdentity();
rotZ.rotationZ(mSpinAngleZ); // rotate Y
rotX.mul(rotY);
rotX.mul(rotZ);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -