package com.eje_c.meganekko.sample;

import android.view.View;

import com.eje_c.meganekko.Frame;
import com.eje_c.meganekko.MeganekkoApp;
import com.eje_c.meganekko.ObjectLookingStateDetector;
import com.eje_c.meganekko.Scene;
import com.eje_c.meganekko.SceneObject;

import ovr.JoyButton;

public class FirstScene extends Scene {
    private SceneObject button, videocam;
    private ObjectLookingStateDetector detector;

    @Override
    protected void initialize(MeganekkoApp app) {
        super.initialize(app);
        button = findObjectById(R.id.button);
        videocam = findObjectById(R.id.ic_videocam);

        View buttonView = button.view();

        detector = new ObjectLookingStateDetector(app, button, new ObjectLookingStateDetector.ObjectLookingStateListener() {
            @Override
            public void onLookStart(SceneObject targetObject, Frame vrFrame) {
                getApp().runOnUiThread(() -> buttonView.setPressed(true));
            }

            @Override
            public void onLooking(SceneObject targetObject, Frame vrFrame) {
            }

            @Override
            public void onLookEnd(SceneObject targetObject, Frame vrFrame) {
                getApp().runOnUiThread(() -> buttonView.setPressed(false));
            }
        });
    }

    @Override
    public void update(Frame frame) {
        detector.update(frame);

        final boolean singleTouchDetected = JoyButton.contains(frame.getButtonPressed(), JoyButton.BUTTON_TOUCH_SINGLE);
        if (singleTouchDetected) {
            if (isLookingAt(button)) {
                MyApp app = (MyApp) getApp();
                app.onTapButton();
            } else if (isLookingAt(videocam)) {
                MyApp app = (MyApp) getApp();
                app.onTapVideocam();
            }
        }

        super.update(frame);
    }
}

@@ -262,16 +262,43 @@
 bject;%0A%0A
+import org.joml.Vector3f;%0A%0A
 import o
@@ -433,17 +433,65 @@
 etector 
-d
+buttonLookingStateDetector, videocamLookingStateD
 etector;
@@ -733,25 +733,43 @@
 );%0A%0A        
-d
+buttonLookingStateD
 etector = ne
@@ -1382,76 +1382,1004 @@
 %7D);%0A
-    %7D%0A%0A    @Override%0A    public void update(Frame frame) %7B%0A        d
+%0A        videocamLookingStateDetector = new ObjectLookingStateDetector(app, videocam, new ObjectLookingStateDetector.ObjectLookingStateListener() %7B%0A            Vector3f focusSize = new Vector3f(1.5f, 1.5f, 1.5f);%0A            Vector3f originalSize = videocam.scale();%0A%0A            @Override%0A            public void onLookStart(SceneObject targetObject, Frame vrFrame) %7B%0A                videocam.animate()%0A                        .scaleTo(focusSize)%0A                        .start(app);%0A            %7D%0A%0A            @Override%0A            public void onLooking(SceneObject targetObject, Frame vrFrame) %7B%0A            %7D%0A%0A            @Override%0A            public void onLookEnd(SceneObject targetObject, Frame vrFrame) %7B%0A                videocam.animate()%0A                        .scaleTo(originalSize)%0A                        .start(app);%0A            %7D%0A        %7D);%0A    %7D%0A%0A    @Override%0A    public void update(Frame frame) %7B%0A        buttonLookingStateDetector.update(frame);%0A        videocamLookingStateD
 etec

Update sample