Diligent Engine API Reference
tapCamera.h
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  * Camera control helper class with a tap gesture
30  * This class is mainly used for 3D space camera control in samples.
31  *
32  */
33 class TapCamera {
34  private:
35  // Trackball
36  Vec2 vec_ball_center_;
37  float ball_radius_;
38  Quaternion quat_ball_now_;
39  Quaternion quat_ball_down_;
40  Vec2 vec_ball_now_;
41  Vec2 vec_ball_down_;
42  Quaternion quat_ball_rot_;
43 
44  bool dragging_;
45  bool pinching_;
46 
47  // Pinch related info
48  Vec2 vec_pinch_start_;
49  Vec2 vec_pinch_start_center_;
50  float pinch_start_distance_SQ_;
51 
52  // Camera shift
53  Vec3 vec_offset_;
54  Vec3 vec_offset_now_;
55 
56  // Camera Rotation
57  float camera_rotation_;
58  float camera_rotation_start_;
59  float camera_rotation_now_;
60 
61  // Momentum support
62  bool momentum_;
63  double time_stamp_;
64  Vec2 vec_drag_delta_;
65  Vec2 vec_last_input_;
66  Vec3 vec_offset_last_;
67  Vec3 vec_offset_delta_;
68  float momemtum_steps_;
69 
70  Vec2 vec_flip_;
71  float flip_z_;
72 
73  Mat4 mat_rotation_;
74  Mat4 mat_transform_;
75 
76  Vec3 vec_pinch_transform_factor_;
77 
78  Vec3 PointOnSphere(Vec2& point);
79  void BallUpdate();
80  void InitParameters();
81 
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  void Update(const double time);
90 
91  Mat4& GetRotationMatrix();
92  Mat4& GetTransformMatrix();
93 
94  void BeginPinch(const Vec2& v1, const Vec2& v2);
95  void EndPinch();
96  void Pinch(const Vec2& v1, const Vec2& v2);
97 
98  void SetFlip(const float x, const float y, const float z) {
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  vec_pinch_transform_factor_ = Vec3(x, y, z);
105  }
106 
107  void Reset(const bool bAnimate);
108 };
109 
110 } // namespace ndkHelper
Definition: gestureDetector.h:32