public class Rotation3DExample extends BaseExample {
// ===========================================================
// Constants
// ===========================================================
private static final int CAMERA_WIDTH = 720;
private static final int CAMERA_HEIGHT = 480;
// ===========================================================
// Fields
// ===========================================================
private Camera mCamera;
private Texture mTexture;
private TextureRegion mFaceTextureRegion;
// ===========================================================
// Constructors
// ===========================================================
// ===========================================================
// Getter & Setter
// ===========================================================
// ===========================================================
// Methods for/from SuperClass/Interfaces
// ===========================================================
@Override
public Engine onLoadEngine() {
this.mCamera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
this.mCamera.setZClippingPlanes(-100, 100);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), this.mCamera));
}
@Override
public void onLoadResources() {
this.mTexture = new Texture(32, 32, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.mFaceTextureRegion = TextureRegionFactory.createFromAsset(this.mTexture, this, "gfx/face_box.png", 0, 0);
this.mEngine.getTextureManager().loadTexture(this.mTexture);
}
@Override
public Scene onLoadScene() {
this.mEngine.registerUpdateHandler(new FPSLogger());
final Scene scene = new Scene(1);
scene.setBackground(new ColorBackground(0.09804f, 0.6274f, 0.8784f));
/* Calculate the coordinates for the face, so its centered on the camera. */
final int centerX = (CAMERA_WIDTH - this.mFaceTextureRegion.getWidth()) / 2;
final int centerY = (CAMERA_HEIGHT - this.mFaceTextureRegion.getHeight()) / 2;
/* Create the face and add it to the scene. */
final Sprite face = new Sprite(centerX, centerY, this.mFaceTextureRegion) {
@Override
protected void applyRotation(final GL10 pGL) {
/* Disable culling so we can see the backside of this sprite. */
GLHelper.disableCulling(pGL);//背面检测
final float rotation = this.mRotation;
if(rotation != 0) {
final float rotationCenterX = this.mRotationCenterX;
final float rotationCenterY = this.mRotationCenterY;
//pGL.glTranslatef(rotationCenterX, rotationCenterY, 0)跟pGL.glTranslatef(rotationCenterX, rotationCenterY, 0);绕过中心点的竖直方向翻转
pGL.glTranslatef(rotationCenterX, rotationCenterY, 0);
/* Note we are applying rotation around the y-axis and not the z-axis anymore! */
pGL.glRotatef(rotation, 0, 1, 0);//延Y轴转
pGL.glTranslatef(rotationCenterX, rotationCenterY, 0);
}
}
@Override
protected void drawVertices(final GL10 pGL, final Camera pCamera) {
super.drawVertices(pGL, pCamera);
/* Enable culling as 'normal' entities profit from culling. */
GLHelper.enableCulling(pGL);
}
};
face.addShapeModifier(new LoopShapeModifier(new RotationModifier(6, 0, 360)));//duration 是设置的动画执行时间
scene.getTopLayer().addEntity(face);
return scene;
}
@Override
public void onLoadComplete() {
}
// ===========================================================
// Methods
// ===========================================================
// ===========================================================
// Inner and Anonymous Classes
// ===========================================================
}