package org.ntlab.radishforandroidstudio.cactusClient.views;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import org.ntlab.radishforandroidstudio.R;
import org.ntlab.radishforandroidstudio.cactusClient.models.Player;
import org.ntlab.radishforandroidstudio.framework.RWT.RWTPad;
import org.ntlab.radishforandroidstudio.framework.RWT.RWTUIFragment;
import org.ntlab.radishforandroidstudio.framework.event.PadEvent;
import org.ntlab.radishforandroidstudio.framework.gameMain.RealTime3DFragment;
import org.ntlab.radishforandroidstudio.framework.listener.PadListener;
import org.ntlab.radishforandroidstudio.java3d.AmbientLight;
import org.ntlab.radishforandroidstudio.java3d.Appearance;
import org.ntlab.radishforandroidstudio.java3d.Color3f;
import org.ntlab.radishforandroidstudio.java3d.DirectionalLight;
import org.ntlab.radishforandroidstudio.java3d.Material;
import org.ntlab.radishforandroidstudio.java3d.Vector3f;

public class PlayerFragmentLight extends RealTime3DFragment implements PadListener {
    private boolean isTouched = false;
    private float touchX = 0.0f;
    private float touchY = 0.0f;
    RWTPad pad = null;
    private Player player;

    public PlayerFragmentLight() {
        // Required empty public constructor
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        //環境光
        AmbientLight amblight = new AmbientLight(new Color3f(1.0f, 1.0f, 1.0f));

//		amblight.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0));
        universe.placeLight(amblight);

        //平行光源
        DirectionalLight dirlight = new DirectionalLight(
                new Color3f(1.0f, 1.0f, 1.0f),  //光の色
                new Vector3f(0.0f, -1.0f, -0.5f) //光の方向ベクトル
        );
//		dirlight.setInfluencingBounds(new BoundingSphere(new Point3d(), 10000.0));
        universe.placeLight(dirlight);

        Appearance ap1 = new Appearance();
        Material m = new Material();
        m.setDiffuseColor(0.0f, 0.3f, 1.0f);
        m.setAmbientColor(0.0f, 0.0f, 0.0f);
        m.setEmissiveColor(0.0f, 0.0f, 0.0f);
        m.setSpecularColor(0.0f, 0.0f, 0.0f);
        m.setShininess(5.0f);
        ap1.setMaterial(m);
        camera.setFieldOfView(1.5);
        camera.setBackClipDistance(10000.0);
        start(1000L, 50L, true);
    }


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        super.onCreateView(inflater, container, savedInstanceState);
        initGameWindowView();
        return parentView;
    }

    @Override
    protected void progress(long interval) {
    }


    //sampleUiFragmentからそのまま持ってきた
    public void initGameWindowView() {
    }

    public void onCreateFragmentEvent(RWTUIFragment f) {
        pad = (RWTPad) f.findViewById(R.id.pad);
        pad.addListener((PadListener) this);
    }

    @Override
    public boolean onEvent(PadEvent event) {
        return false;
    }

    public void setPlayer(Player player) {
        this.player = player;
    }
}

