If you think the Android project Schooner-3D listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2012 Dan Mercer//www.java2s.com
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/package com.supermercerbros.gameengine;
import java.util.Random;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import com.supermercerbros.gameengine.engine.Camera;
import com.supermercerbros.gameengine.engine.Engine;
import com.supermercerbros.gameengine.material.TexturedMaterial;
import com.supermercerbros.gameengine.objects.GameObject;
import com.supermercerbros.gameengine.texture.BitmapTexture;
import com.supermercerbros.gameengine.texture.Texture;
publicclass TestActivity extends GameActivity {
privatestatic String TAG = GameActivity.class.getSimpleName();
privatestaticfinalfloat NEAR_CLIP_DISTANCE = 0.1f;
privatestaticfinalfloat FAR_CLIP_DISTANCE = 20.0f;
privatestaticfinalint CAMERA_MOVE_DURATION = 1500;
private Engine engine;
private Camera cam;
privateboolean iso = true;
privateint bg;
private GameObject object;
/**
* This provides an example of a subclass of GameActivity
*/
@Override
publicvoid onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
bg = 0x00000000;
setBackgroundColor(bg);
engine = getEngine();
cam = getCamera();
cam.set(10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f );
object = getObject();
engine.setLight(0.0f, 0.0f, 1.0f, ((float) Color.red(bg) / 256 + 1.0f) / 2.0f, ((float) Color.green(bg) / 256 + 1.0f) / 2.0f, ((float) Color.blue(bg) / 256 + 1.0f) / 2.0f);
engine.addObject(object);
setClipDistances(NEAR_CLIP_DISTANCE, FAR_CLIP_DISTANCE);
start();
}
protected GameObject getObject() {
final Texture testTexture2 = new BitmapTexture(getResources(), R.drawable.test_texture2);
return TestObjects.cube(new TexturedMaterial(testTexture2));
}
// @Override
publicboolean onTouch(View v, MotionEvent event) {
if (event.getAction() != MotionEvent.ACTION_DOWN) return false;
switchCamPosition();
Random rand = new Random();
setBG(event.getX() / getWidth(), event.getY(0) / getHeight(), rand.nextFloat());
Log.d("onTouch", "x: " + event.getX() + " y: " + event.getY());
return true;
}
privatevoid switchCamPosition(){
if (iso) {
cam.moveTo(2.0f, -10.0f, 2.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, CAMERA_MOVE_DURATION);
iso = false;
} else {
cam.moveTo(10.0f, 10.0f, 10.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, CAMERA_MOVE_DURATION);
iso = true;
}
}
privatevoid setBG(float r, float g, float b){
bg = Color.argb(255, (int) (255 * r), (int) (255 * g), (int) (255 * b));
engine.setLight(0.0f, 0.0f, 1.0f, 1 - r/2, 1 - g/2, 1 - b/2);
setBackgroundColor(bg);
}
@Override
publicboolean onPrepareOptionsMenu(Menu menu) {
onMenuButtonClick();
Log.d(TAG, "onMenuButtonClick");
return super.onPrepareOptionsMenu(menu);
}
protectedvoid onMenuButtonClick() {
}
@Override
publicvoid onResume() {
super.onResume();
resumeGame();
}
}