/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 *                                                                         *
 *   AndroidWorld Library, Copyright 2011 Bryan Chadwick                   *
 *                                                                         *
 *   FILE: ./android/world/test/ShowDown.java                              *
 *                                                                         *
 *   This file is part of AndroidWorld.                                    *
 *                                                                         *
 *   AndroidWorld is free software: you can redistribute it and/or         *
 *   modify it under the terms of the GNU General Public License           *
 *   as published by the Free Software Foundation, either version          *
 *   3 of the License, or (at your option) any later version.              *
 *                                                                         *
 *   AndroidWorld is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with AndroidWorld.  If not, see <http://www.gnu.org/licenses/>. *
 *                                                                         *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

package android.world.test;

import android.app.Activity;
import android.os.Bundle;
import android.image.*;
import android.util.Log;
import android.view.Display;
import android.world.VoidWorld;

public class ShowDown extends Activity{
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        Display dis = getWindowManager().getDefaultDisplay();
        new Orient(dis.getWidth(), dis.getHeight()-50).bigBang(this);
    }
}
class Orient extends VoidWorld{
    int WIDTH, HEIGHT;
    double ang;
    double mag;
    
    Orient(int w, int h){
        this.WIDTH = w;
        this.HEIGHT = h;
        this.ang = 0;
        this.mag = 1;
    }
    
    public void onOrientation(double x, double y, double z){
        double ang = Math.acos(x/Math.sqrt(x*x + y*y))+Math.PI;
        if(y < 0){
            this.ang = 2*Math.PI-ang;
        }else{
            this.ang = ang;
        }
        this.mag = Math.sqrt(x*x + y*y);
        Log.d("Testing", "("+x+","+y+" ,"+z+")   MAG = "+mag);
    }

    
    public Scene onDraw(){
        double x = WIDTH/2+Math.cos(ang)*mag*WIDTH/20.0,
               y = HEIGHT/2-Math.sin(ang)*mag*WIDTH/20.0;
        return new EmptyScene(WIDTH, HEIGHT)
             .addLine(WIDTH/2, HEIGHT/2, x, y, "black")
             .placeImage(new Circle(10, "solid", "red"), x, y)
             .placeImage(new Text("Ang: "+((int)(180*ang/Math.PI)), 20, "black"), WIDTH/2, 2*HEIGHT/3)
             .placeImage(new Circle(10, "solid", "blue"), WIDTH/2, HEIGHT/2);
    }
}