World.main.clear();
Light.clear();
//floor = new Entity(box(new Color(0.0f, 0.8f, 0.2f), 20f, 20f, 20f));
Vector3[] fv = new Vector3[8];
fv[0] = new Vector3(-10.0f, 0.0f, -10.0f);
fv[1] = new Vector3(-10.0f, 0.0f, 10.0f);
fv[2] = new Vector3(10.0f, 0.0f, 10.0f);
fv[3] = new Vector3(10.0f, 0.0f, -10.0f);
fv[4] = new Vector3(-5.0f, 5.0f, -5.0f);
fv[5] = new Vector3(-5.0f, 5.0f, 5.0f);
fv[6] = new Vector3(5.0f, 5.0f, 5.0f);
fv[7] = new Vector3(5.0f, 5.0f, -5.0f);
Vector3[] fn = new Vector3[5];
fn[0] = Vector3.yAxis();
fn[1] = new Vector3(1.0f, 1.0f, 0.0f).normalize();
fn[2] = new Vector3(0.0f, 1.0f, 1.0f).normalize();
fn[3] = new Vector3(0.0f, 1.0f, -1.0f).normalize();
fn[4] = new Vector3(-1.0f, 1.0f, 0.0f).normalize();
Vector3[] fe = new Vector3[6];
fe[0] = Vector3.xAxis();
fe[1] = Vector3.zAxis();
fe[2] = new Vector3(1.0f, 1.0f, 1.0f).normalize();
fe[3] = new Vector3(1.0f, 1.0f, -1.0f).normalize();
fe[4] = new Vector3(-1.0f, 1.0f, -1.0f).normalize();
fe[5] = new Vector3(-1.0f, 1.0f, 1.0f).normalize();
ViewModel floorModel = loadObjModel(new File("models/platform.obj"), Vector3.one());
Entity floor = new Entity(floorModel);
floor.transform.position = new Vector3(0, -7, 0);
//floor.transform.set(new Vector3(0, -12, 0), Vector3.yAxis().negate(), Vector3.zAxis(), Vector3.one());
floor.addBehavior(new Collider(fv, fn, fe));
World.main.add(floor);
Light light = new Light(Color.WHITE);
light.transform.position = new Vector3(-5, 5, 2);
light.setAttenuation(1, 0, 0);
//player = new Player(new Vector3(0, 0, 4));
//World.main.add(player);
camera = new Transform(new Vector3(-10, 10, 10), new Vector3(1, -1, -1), Vector3.yAxis(), Vector3.one());
gravity = new UniformGravity();
World.main.addForce(gravity);
counter = new Canvas(128, 32);
updateCounter();
spawner = new Entity();
spawner.transform.position.y = 15.0f;
spawner.addBehavior(new Behavior() {
private float timeUntilSpawn = 2.0f;
@Override
public void update() {
timeUntilSpawn -= Time.deltaTime();
if (timeUntilSpawn <= 0) {
float width = random.nextFloat() * 2.0f + 1.0f;
float height = random.nextFloat() * 2.0f + 1.0f;
float depth = random.nextFloat() * 2.0f + 1.0f;
final Entity entity = RigidBody.box(new Material(Color.random()), width, height, depth, 1.0f);
entity.addBehavior(new Behavior() {
@Override
public void update() {
if (entity.transform.position.y < -20.0f || isKeyDown(KEY_LCONTROL)) {
entity.destroy();
numBlocks--;
updateCounter();
}
}
});
entity.transform.position = spawner.transform.position;
entity.transform.forward = new Vector3(random.nextFloat(), random.nextFloat(), random.nextFloat());
entity.transform.setUp(new Vector3(random.nextFloat(), random.nextFloat(), random.nextFloat()));
//entity.transform.up.x = 0.1f;
World.main.add(entity);
numBlocks++;
updateCounter();
timeUntilSpawn = 2.0f;