Home | History | Annotate | Download | only in ndk_helper
      1 /*
      2  * Copyright 2013 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 #pragma once
     18 #include <vector>
     19 #include <string>
     20 #include <GLES2/gl2.h>
     21 
     22 #include "JNIHelper.h"
     23 #include "vecmath.h"
     24 #include "interpolator.h"
     25 
     26 namespace ndk_helper
     27 {
     28 
     29 /******************************************************************
     30  * Camera control helper class with a tap gesture
     31  * This class is mainly used for 3D space camera control in samples.
     32  *
     33  */
     34 class TapCamera
     35 {
     36 private:
     37     //Trackball
     38     Vec2 vec_ball_center_;
     39     float ball_radius_;
     40     Quaternion quat_ball_now_;
     41     Quaternion quat_ball_down_;
     42     Vec2 vec_ball_now_;
     43     Vec2 vec_ball_down_;
     44     Quaternion quat_ball_rot_;
     45 
     46     bool dragging_;
     47     bool pinching_;
     48 
     49     //Pinch related info
     50     Vec2 vec_pinch_start_;
     51     Vec2 vec_pinch_start_center_;
     52     float pinch_start_distance_SQ_;
     53 
     54     //Camera shift
     55     Vec3 vec_offset_;
     56     Vec3 vec_offset_now_;
     57 
     58     //Camera Rotation
     59     float camera_rotation_;
     60     float camera_rotation_start_;
     61     float camera_rotation_now_;
     62 
     63     //Momentum support
     64     bool momentum_;
     65     Vec2 vec_drag_delta_;
     66     Vec2 vec_last_input_;
     67     Vec3 vec_offset_last_;
     68     Vec3 vec_offset_delta_;
     69     float momemtum_steps_;
     70 
     71     Vec2 vec_flip_;
     72     float flip_z_;
     73 
     74     Mat4 mat_rotation_;
     75     Mat4 mat_transform_;
     76 
     77     Vec3 vec_pinch_transform_factor_;
     78 
     79     Vec3 PointOnSphere( Vec2& point );
     80     void BallUpdate();
     81     void InitParameters();
     82 public:
     83     TapCamera();
     84     virtual ~TapCamera();
     85     void BeginDrag( const Vec2& vec );
     86     void EndDrag();
     87     void Drag( const Vec2& vec );
     88     void Update();
     89 
     90     Mat4& GetRotationMatrix();
     91     Mat4& GetTransformMatrix();
     92 
     93     void BeginPinch( const Vec2& v1, const Vec2& v2 );
     94     void EndPinch();
     95     void Pinch( const Vec2& v1, const Vec2& v2 );
     96 
     97     void SetFlip( const float x, const float y, const float z )
     98     {
     99         vec_flip_ = Vec2( x, y );
    100         flip_z_ = z;
    101     }
    102 
    103     void SetPinchTransformFactor( const float x, const float y, const float z )
    104     {
    105         vec_pinch_transform_factor_ = Vec3( x, y, z );
    106     }
    107 
    108     void Reset( const bool bAnimate );
    109 
    110 };
    111 
    112 } //namespace ndkHelper
    113