void clViewport::UpdateTrackball( clVirtualTrackball* Trackball, float Speed, bool Keypressed ) const { if ( Keypressed ) { Trackball->DragTo( LVector2( FMouseCursorInfo.FMouseX, FMouseCursorInfo.FMouseY ), Speed ); } else { Trackball->StartDragging( LVector2( FMouseCursorInfo.FMouseX, FMouseCursorInfo.FMouseY ) ); } }
LVector2 clViewport::TransformPointerPosition( int X, int Y ) { float fX = Math::Clamp( X * FScaleFactorX, 0.0f, 1.0f ); float fY = Math::Clamp( Y * FScaleFactorY, 0.0f, 1.0f ); return LVector2( fX, fY ); }
JNIEXPORT void JNICALL Java_com_packtpub_ndkcookbook_game1_Game1Activity_SendMotion( JNIEnv* env, jobject obj, int PointerID, int x, int y, bool Pressed, int Flag ) { sSendMotionData M; M.ContactID = PointerID; M.Flag = ( eMotionFlag )Flag; M.Pos = LVector2( ( float )x / ( float )g_Width, ( float )y / ( float )g_Height ); M.Pressed = Pressed; LMutex Lock( &g_MotionEventsQueueMutex ); g_MotionEventsQueue.push_back( M ); }
LRESULT CALLBACK MyFunc( HWND h, UINT msg, WPARAM w, LPARAM p ) { int x = ( ( int )( short )LOWORD( p ) ), y = ( ( int )( short )HIWORD( p ) ); float Xf = ( float )x / ( float )WindowW; float Yf = ( float )y / ( float )WindowH; switch ( msg ) { case WM_KEYUP: OnKey( w, false ); if ( w == 27 ) { SendMessage( h, WM_DESTROY, 0, 0 ); } break; case WM_KEYDOWN: OnKey( w, true ); break; case WM_LBUTTONDOWN: SetCapture( h ); OnMouseDown( 0, LVector2( Xf, Yf ) ); break; case WM_MOUSEMOVE: OnMouseMove( LVector2( Xf, Yf ) ); break; case WM_LBUTTONUP: OnMouseUp( 0, LVector2( Xf, Yf ) ); ReleaseCapture(); break; case WM_DESTROY: PostQuitMessage( 0 ); break; } return DefWindowProc( h, msg, w, p ); }
void clCanvas::Rect3D( const LMatrix4& Proj, const LMatrix4& MV, const LVector3& V1, const LVector3& V2, const LVector3& V3, const LVector3& V4, const clPtr<clGLTexture>& Texture, const clPtr<clGLSLShaderProgram>& SP ) { LGL3->glDisable( GL_DEPTH_TEST ); Texture->Bind( 0 ); clPtr<clGLSLShaderProgram> S = SP ? SP : FRect3DSP; S->Bind(); S->SetUniformNameMat4Array( "u_MVP", 1, MV * Proj ); FRect3D->Restart( 6 ); FRect3D->SetTexCoordV( LVector2( 0, 0 ) ); FRect3D->EmitVertexV( V1 ); FRect3D->SetTexCoordV( LVector2( 1, 0 ) ); FRect3D->EmitVertexV( V2 ); FRect3D->SetTexCoordV( LVector2( 0, 1 ) ); FRect3D->EmitVertexV( V4 ); FRect3D->SetTexCoordV( LVector2( 1, 0 ) ); FRect3D->EmitVertexV( V2 ); FRect3D->SetTexCoordV( LVector2( 1, 1 ) ); FRect3D->EmitVertexV( V3 ); FRect3D->SetTexCoordV( LVector2( 0, 1 ) ); FRect3D->EmitVertexV( V4 ); FRect3DVA->SetVertexAttribs( FRect3D ); FRect3DVA->Draw( false ); }
void clGUIColorDial::SetAlpha( const LVector2& Pnt ) { LVector2 dP = Screen2Local( Pnt ); dP = LVector2( dP.X / GetWidth(), dP.Y / GetHeight() ); float nx = ( dP.X - 0.5f ) * 2.0f; float ny = ( dP.Y - 0.5f ) * 2.0f; float r = sqrt( nx * nx + ny * ny ); float r_min = FRMin; LVector2 p_color = -Math::ToPolar( r_min, FAlpha ); LVector2 p_white = -Math::ToPolar( r_min, FAlpha + 120.0f ); LVector2 p_black = -Math::ToPolar( r_min, FAlpha + 240.0f ); LVector3 Mark = LVector3( FMousePoint.X * p_black + FMousePoint.Y * p_white + FMousePoint.Z * p_color, 1.0f ); DialSP->BindUniforms(); DialSP->SetUniformVec3Array( FMousePtUniform, 1, Mark ); if ( r < FRMax && r > FRMin ) { FAlpha = 180.0f + Linderdaum::Math::RadToDeg( atan2( ny, nx ) ); DialSP->SetUniformFloat( FAlphaUniform, FAlpha ); } else { LVector3 NewB = Math::Barycentric2D( nx, ny, p_black.X, p_black.Y, p_white.X, p_white.Y, p_color.X, p_color.Y ); if ( NewB.X >= 0 && NewB.X <= 1 && NewB.Y >= 0 && NewB.Y <= 1 && NewB.Z >= 0 && NewB.Z <= 1 ) { FMousePoint = NewB; } } LVector3 CC = FMousePoint.X * LC_Black.ToVector3() + FMousePoint.Y * LC_White.ToVector3() + FMousePoint.Z * Math::ColorFromAngle( FAlpha ); Env->Console->GetVar( FOutVarName )->SetVector4( LVector4( CC, 1.0f ) ); }
JNIEXPORT void JNICALL Java_com_packtpub_ndkcookbook_app13_App13Activity_SendMotion( JNIEnv* env, jobject obj, int PointerID, int x, int y, bool Pressed, int Flag ) { LVector2 Pos = LVector2( ( float )x / ( float )g_Width, ( float )y / ( float )g_Height ); GestureHandler_SendMotion( PointerID, ( eMotionFlag )Flag, Pos, Pressed ); }
LVector2 clViewport::GetMousePosition() const { return LVector2( FMouseCursorInfo.FMouseX, FMouseCursorInfo.FMouseY ); }
LVector2 clViewport::MousePositionIntToFloat( int X, int Y ) const { return LVector2( X * FScaleFactorX, Y * FScaleFactorY ); }
#if defined( ANDROID ) # include "Wrapper_Android.h" #else # include "Wrapper_Windows.h" #endif iGestureResponder* g_Responder; void UpdateGesture(); sMotionData FMotionData; RingBuffer<sMotionData> FPrevMotionData( 5 ); bool FMotionDataValid = false; bool FMoving = false; sTouchPoint FInitialPoint( 0, LVector2(), L_MOTION_MOVE, 0.0 ); /// get the position of the current touch point in the current gesture, that means the current position of the last point touched sTouchPoint FCurrentPoint( 0, LVector2(), L_MOTION_MOVE, 0.0 ); #pragma region Fling /// pointer movements below this value are ignored float FlingThresholdSensitivity = 0.1f; /// pointer movements below this value will not generate a fling float FlingStartSensitivity = 0.2f; bool FFlingWasValid = false; #pragma endregion #pragma region Pinch-zoom bool FPinchZoomValid = false; bool FPinchZoomWasValid = false;