//#####################################################################
// Copyright 2020, Craig Schroeder.
// This file is part of PhysBAM whose distribution is governed by the license contained in the accompanying file PHYSBAM_COPYRIGHT.txt.
//#####################################################################
#ifndef __QT_CAMERA__
#define __QT_CAMERA__

#include <Core/Matrices/MATRIX.h>
#include <Core/Vectors/VECTOR.h>
#include "QT_ARCBALL.h"

namespace PhysBAM{

class QT_CAMERA
{
    friend class QT_WORLD;
    typedef VECTOR<float,2> TV2;
    typedef VECTOR<float,3> TV;
    typedef VECTOR<float,4> TV4;
    typedef MATRIX<float,3> TM;
    typedef MATRIX<float,4> TM4;
    int width=640, height=480;

    bool do_rotation=false;
    bool do_zoom=false;
    bool do_translation=false;

    int mouse_last_x=0, mouse_last_y=0;

    QT_ARCBALL arcball;
    TV target_position;
    TV target_dx,target_dy;
    TM rotation_matrix;
    float scale=1;
    float nearclip_factor=.0625;
    float farclip_factor=4;
    float fovy=50;
public:
    bool mode_2d=false;

    QT_CAMERA();
    ~QT_CAMERA();

    void Set_Size(int w, int h);
    void Begin_Rotation(int x, int y);
    void Apply_Rotation(int x, int y);
    void End_Rotation(int x, int y);
    void Begin_Zoom(int x, int y);
    void Apply_Zoom(int x, int y);
    void End_Zoom(int x, int y);
    void Begin_Translation(int x, int y);
    void Apply_Translation(int x, int y);
    void End_Translation(int x, int y);
    TM4 Transform() const;
    TV Camera_Frame_To_World(const TV& u) const;
    void Look_At(const TV& X);
    void Look_At(const RANGE<TV>& box);
    TM4 Perspective() const;
};
}
#endif
