diff --git a/bazaar/SurfaceCtrl/Camera.cpp b/bazaar/SurfaceCtrl/Camera.cpp index 5e70b708d..28a3a9189 100644 --- a/bazaar/SurfaceCtrl/Camera.cpp +++ b/bazaar/SurfaceCtrl/Camera.cpp @@ -1,4 +1,4 @@ -#include "Camera.h" +/*#include "Camera.h" //Camera CLASS namespace Upp{ @@ -490,5 +490,5 @@ CameraEuler& CameraEuler::ProcessMouveMouvement(float xoffset, float yoffset){ */ /* return *this; -}*/ -} \ No newline at end of file +} +}*/ \ No newline at end of file diff --git a/bazaar/SurfaceCtrl/Camera.h b/bazaar/SurfaceCtrl/Camera.h index 12773d0c4..e191fa4b5 100644 --- a/bazaar/SurfaceCtrl/Camera.h +++ b/bazaar/SurfaceCtrl/Camera.h @@ -28,157 +28,128 @@ class UOGL_Camera{ Upp::Sizef ScreenSize; public: - UOGL_Camera(){} - UOGL_Camera(UOGL_Camera& camera); - UOGL_Camera& operator=(UOGL_Camera& camera); - virtual UOGL_Camera* Clone()=0; - virtual ~UOGL_Camera(){} - - UOGL_Camera& SetTransform(Transform& value); - Transform& GetTransform(); - UOGL_Camera& SetCameraType(CameraType value); - CameraType GetCameraType()const; - - UOGL_Camera& SetFOV(float value); - float GetFOV()const; - UOGL_Camera& SetMaxFOV(float value); - float GetMaxFOV()const; - UOGL_Camera& SetMinFOV(float value); - float GetMinFOV()const; - - UOGL_Camera& EnableLimiteFOV(); - UOGL_Camera& DisableLimiteFOV(); - bool IsFOVLimited()const; - - UOGL_Camera& SetDrawDisanceMax(float value); - float GetDrawDisanceMax()const; - UOGL_Camera& SetDrawDistanceMin(float value); - float GetDrawDistanceMin()const; - - virtual glm::mat4 GetProjectionMatrix(Upp::Sizef ScreenSize); - virtual glm::mat4 GetViewMatrix() =0; - - virtual UOGL_Camera& SetPosition(glm::vec3 const& position); - virtual UOGL_Camera& LookAt(glm::vec3 const& lookTo); - - virtual UOGL_Camera& ProcessKeyboardMouvement(Camera_Movement direction)=0; - virtual bool ProcessKeyBoard(unsigned long Key,int count); //To process key - virtual UOGL_Camera& ProcessMouveMouvement(float xoffset, float yoffset)=0; - virtual UOGL_Camera& ProcessMouseScroll(float yoffset); - - UOGL_Camera& SetMouvementSpeed(float value = 15.0f); - float GetMouvementSpeed(); - UOGL_Camera& SetMouseSensitivity(float value = 0.01f); - float GetMouseSensitivity(); - UOGL_Camera& SetZoomSpeed(float value = 10.0f){ZoomSpeed = value; return *this;} - float GetZoomSpeed(){return ZoomSpeed;} - - Point StartPress; + Point lastPress; bool MouseLeftPressed = false; bool MouseMiddlePressed = false; bool ShiftPressed = false; -}; -/* -class CameraQuaterion : public UOGL_Camera{ - protected: - float GetRealMouseSensitivity(); - public: - CameraQuaterion(); //be carefull of setting scene correctly - CameraQuaterion(CameraQuaterion& cameraQuaterion); - CameraQuaterion& operator=(CameraQuaterion& cameraQuaterion); - virtual ~CameraQuaterion(){} - virtual CameraQuaterion* Clone(); - - //virtual glm::mat4 GetProjectionMatrix(Upp::Sizef ScreenSize)const; - virtual glm::mat4 GetViewMatrix(); - - virtual CameraQuaterion& ProcessKeyboardMouvement(Camera_Movement direction); - virtual CameraQuaterion& ProcessMouveMouvement(float xoffset, float yoffset); -}; + UOGL_Camera(){} + UOGL_Camera(UOGL_Camera& camera){*this = camera;} + UOGL_Camera& operator=(UOGL_Camera& camera){ + ScreenSize = camera.ScreenSize; + ZoomSpeed = camera.ZoomSpeed; + MouseSensitivity = camera.MouseSensitivity; + MouvementSpeed = camera.MouvementSpeed; + transform = camera.transform; + type = camera.type; + MaxFOV = camera.MaxFOV; + MinFOV = camera.MinFOV; + LimiteFOV = camera.LimiteFOV; + FOV = camera.FOV; + DrawDisanceMax = camera.DrawDisanceMax; + DrawDistanceMin = camera.DrawDistanceMin; + return *this; + } + virtual ~UOGL_Camera(){} -class CameraEuler : public UOGL_Camera{ - protected: - float Yaw = 0.0f; - float Pitch = 0.0f; - float Roll = 0.0f; - - float MinPitch = -89.9f; - float MaxPitch = 89.9f; - bool ActivatePitch = true; //Activate rotation on pitch - bool ConstraintPitchEnable = true; - - float MinYaw = -179.9f; - float MaxYaw = 179.9f; - bool ActivateYaw = true; //Activate rotation on Yaw - bool ConstraintYawEnable = false; - - float MinRoll = -179.9f; - float MaxRoll = 179.9f; - bool ActivateRoll = false; //Activate rotation on Roll - bool ConstraintRollEnable = false; - public: - CameraEuler(); - CameraEuler(CameraEuler& cameraEuler); - CameraEuler& operator=(CameraEuler& cameraEuler); - virtual ~CameraEuler(){} - virtual CameraEuler* Clone(); + UOGL_Camera& SetTransform(Transform& value)noexcept{transform = value;return *this;} + Transform& GetTransform()noexcept{return transform;} - CameraEuler& SetYaw(float value); - CameraEuler& SetPitch(float value); - CameraEuler& SetRoll(float value); + UOGL_Camera& SetCameraType(CameraType value)noexcept{type = value; return *this;} + CameraType GetCameraType()const noexcept{return type;} - float GetYaw()const; - float GetPitch()const; - float GetRoll()const; + UOGL_Camera& SetFOV(float value)noexcept{if(LimiteFOV){if(value < MinFOV) FOV = MinFOV;else if(value > MaxFOV)FOV = MaxFOV;else FOV = value;}else{FOV = value;} return *this;} + float GetFOV()const noexcept{return FOV;} + float GetMaxFOV()const noexcept{return MaxFOV;} + float GetMinFOV()const noexcept{return MinFOV;} - CameraEuler& SetMinPitch(float value); - CameraEuler& SetMaxPitch(float value); - CameraEuler& SetMinYaw(float value); - CameraEuler& SetMaxYaw(float value); - CameraEuler& SetMinRoll(float value); - CameraEuler& SetMaxRoll(float value); + UOGL_Camera& SetMaxFOV(float value)noexcept{ + if(MaxFOV <= MinFOV){ + LOG("ERROR camera in Camera::SetMaxFOV(float) the float passed is equal or lower to MinFOV(" + Upp::AsString(MinFOV) +"), IT CANT BE Possible. MaxFOV Have been set to MinFOV + 10.0f"); + MaxFOV = MinFOV + 10.0f; + }else{ + MaxFOV = value; + } + return *this; + } + UOGL_Camera& SetMinFOV(float value)noexcept{ + //You can set a negativ number here, I dont see the point but you can + //However, it cant be superior as MaxFOV + if(MinFOV >= MaxFOV){ + LOG("ERROR camera in Camera::SetMinFOV(float) the float passed is equal or Higher to MaxFOV(" + Upp::AsString(MaxFOV) +"), IT CANT BE Possible. MinFOV Have been set to MaxFOV - 10.0f"); + MinFOV = MaxFOV -10.0f; + }else{ + MinFOV = value; + } + return *this; + } + UOGL_Camera& EnableLimiteFOV()noexcept{LimiteFOV = true; return *this;} + UOGL_Camera& DisableLimiteFOV()noexcept{LimiteFOV = false; return *this;} + bool IsFOVLimited()const noexcept{return LimiteFOV;} - float GetMinPitch()const; - float GetMaxPitch()const; - float GetMinYaw()const; - float GetMaxYaw()const; - float GetMinRoll()const; - float GetMaxRoll()const; - - CameraEuler& EnablePitch(); - CameraEuler& EnableYaw(); - CameraEuler& EnableRoll(); - - CameraEuler& DisablePitch(); - CameraEuler& DisableYaw(); - CameraEuler& DisableRoll(); - - bool IsPitchEnable()const; - bool IsYawEnable()const; - bool IsRollchEnable()const; - - CameraEuler& EnableConstraintPitch(); - CameraEuler& EnableConstraintYaw(); - CameraEuler& EnableConstraintRoll(); - - CameraEuler& DisableConstraintPitch(); - CameraEuler& DisableConstraintYaw(); - CameraEuler& DisableConstraintRoll(); - - bool IsConstraintPitchEnable()const; - bool IsConstraintYawEnable()const; - bool IsConstraintRollchEnable()const; + UOGL_Camera& SetDrawDisanceMax(float value)noexcept{ + if(value <= DrawDistanceMin){ + LOG("ERROR camera in Camera::SetDrawDisanceMax(float) the float passed is equal or lower to DrawDistanceMin(" + Upp::AsString(DrawDistanceMin) +"), IT CANT BE Possible. DrawDistanceMax Have been set to DrawDistanceMin + 100.0f"); + DrawDisanceMax = DrawDistanceMin + 100.0f; + }else if(value <= DrawDistanceMin){ + LOG("ERROR camera in Camera::SetDrawDisanceMax(float) the float passed is equal or lower to DrawDistanceMin(" + Upp::AsString(DrawDistanceMin) +"), IT CANT BE Possible. DrawDisanceMax Have been set to DrawDistanceMin + 100.0f"); + DrawDisanceMax = DrawDistanceMin + 100.0f; + }else{ + DrawDisanceMax = value; + }return *this; + } - virtual glm::mat4 GetViewMatrix(); + float GetDrawDisanceMax()const noexcept{return DrawDisanceMax;} + UOGL_Camera& SetDrawDistanceMin(float value)noexcept{ + if(value <= 0){ + LOG("ERROR in UOGL_Camera::SetDrawDistanceMin(float) the float passed is equal or lower to 0, IT CANT BE Possible. DrawDistanceMin Have been set to 0.001f"); + DrawDistanceMin = 0.001f; + }else if(value >= DrawDisanceMax){ + LOG("ERROR in UOGL_Camera::SetDrawDistanceMin(float) the float passed is equal or Higher to DrawDisanceMax(" + Upp::AsString(DrawDisanceMax) +"), IT CANT BE Possible. DrawDistanceMin Have been set to 0.001f"); + DrawDistanceMin = 0.001f; + }else{ + DrawDistanceMin = value; + } + return *this; + } + float GetDrawDistanceMin()const noexcept{return DrawDistanceMin;} - virtual CameraEuler& LookAt(glm::vec3 const& lookTo); - CameraEuler& LookAt(glm::vec3 const& lookTo,bool UseYaw, bool UsePitch,bool UseRoll); + glm::mat4 GetProjectionMatrix()const noexcept{ + if(type == CT_PERSPECTIVE){ + return glm::perspective(glm::radians(GetFOV()),(float)(ScreenSize.cx / ScreenSize.cy),GetDrawDistanceMin(),GetDrawDisanceMax());//We calculate Projection here since multiple camera can have different FOV + }else if(type == CT_ORTHOGRAPHIC){ + float distance = glm::distance(glm::vec3(0,0,0),transform.GetPosition())* (ScreenSize.cx/ScreenSize.cy); + float distanceY = glm::distance(glm::vec3(0,0,0),transform.GetPosition()); + return glm::ortho(-distance ,distance ,-distanceY ,distanceY, 0.00001f, 10000.0f); + }else{ + LOG("Swaping to Camera Perspective (cause of unknow type)"); + return glm::perspective(glm::radians(GetFOV()),(float)( ScreenSize.cx / ScreenSize.cy),GetDrawDistanceMin(),GetDrawDisanceMax());//We calculate Projection here since multiple camera can have different FOV + } + } + UOGL_Camera& LookAt(glm::vec3 const& lookAt)noexcept{transform.LookAt(lookAt);return *this;} + virtual UOGL_Camera& ProcessMouseScroll(float yoffset)noexcept{ + if(LimiteFOV && FOV >= MinFOV && FOV <= MaxFOV){ + FOV -=yoffset; + if(FOV <= MinFOV) FOV = MinFOV; + if(FOV >= MaxFOV) FOV = MaxFOV; + }else if(!LimiteFOV){ + FOV -= yoffset; + } + return *this; + } + virtual bool ProcessKeyBoard(unsigned long Key,int count)noexcept{return false;} - virtual CameraEuler& ProcessKeyboardMouvement(Camera_Movement direction); - virtual CameraEuler& ProcessMouveMouvement(float xoffset, float yoffset); + UOGL_Camera& SetMouvementSpeed(float value)noexcept{MouvementSpeed = value;return *this;} + UOGL_Camera& SetMouseSensitivity(float value)noexcept{MouseSensitivity = value;return *this;} + UOGL_Camera& SetZoomSpeed(float value = 10.0f)noexcept{ZoomSpeed = value; return *this;} + float GetMouvementSpeed()const noexcept{return MouvementSpeed;} + float GetMouseSensitivity()const noexcept{return MouseSensitivity;} + float GetZoomSpeed()const noexcept{return ZoomSpeed;} + + Upp::Sizef GetScreenSize()const noexcept{return ScreenSize;} + UOGL_Camera& SetScreenSize(float width, float height)noexcept{ScreenSize = Sizef(width,height);return *this;} + }; -*/ } #endif diff --git a/bazaar/SurfaceCtrl/MagicCamera.h b/bazaar/SurfaceCtrl/MagicCamera.h new file mode 100644 index 000000000..8ecb348e8 --- /dev/null +++ b/bazaar/SurfaceCtrl/MagicCamera.h @@ -0,0 +1,180 @@ +#ifndef _SurfaceCtrl_MagicCamera_h_ +#define _SurfaceCtrl_MagicCamera_h_ + +#include "Camera.h" +namespace Upp{ + class MagicCamera : public UOGL_Camera{ + private: + Vector* allObjects = nullptr; + + glm::vec3 focus(0.0f,0.0f,0.0f); + + glm::vec3 UnProject2(float winX, float winY,float winZ){ + glm::mat4 View = GetViewMatrix() * glm::mat4(1.0f); + glm::mat4 projection = GetProjectionMatrix(ScreenSize); + glm::mat4 viewProjInv = glm::inverse(projection * View); + winY = ScreenSize.cy - winY; + glm::vec4 clickedPointOnSreen; + clickedPointOnSreen.x = ((winX - 0.0f) / (ScreenSize.cx)) *2.0f -1.0f; + clickedPointOnSreen.y = ((winY - 0.0f) / (ScreenSize.cy)) * 2.0f -1.0f; + clickedPointOnSreen.z = 2.0f*winZ-1.0f; + clickedPointOnSreen.w = 1.0f; + glm::vec4 clickedPointOrigin = viewProjInv * clickedPointOnSreen; + return glm::vec3(clickedPointOrigin.x / clickedPointOrigin.w,clickedPointOrigin.y / clickedPointOrigin.w,clickedPointOrigin.z / clickedPointOrigin.w); + } + + Vector Pick(float x, float y){ + Vector intersect; + if(allObjects){ + glm::vec3 start = UnProject2(x,y,0.0f); + glm::vec3 end = UnProject2(x,y,1.0f); + for (Object3D& obj : *(allObjects)){ + if (obj.TestLineIntersection(start,end)){ + intersect.Add(&obj); + } + } + } + return intersect; + } + + public: + MagicCamera(){} + MagicCamera& Init(){transform.SetPosition(0, 10, 20);return *this;} + + MagicCamera& SetAllObjects(Vector& all){allObjects = &all;return *this;} + + glm::mat4 GetProjectionMatrix(){ + if(type == CT_PERSPECTIVE){ + return glm::perspective(glm::radians(GetFOV()),(float)( ScreenSize.cx / ScreenSize.cy),GetDrawDistanceMin(),GetDrawDisanceMax());//We calculate Projection here since multiple camera can have different FOV + }else if(type == CT_ORTHOGRAPHIC){ + float distance = glm::distance(glm::vec3(0,0,0),transform.GetPosition())* (ScreenSize.cx/ScreenSize.cy); + float distanceY = glm::distance(glm::vec3(0,0,0),transform.GetPosition()); + return glm::ortho(-distance ,distance ,-distanceY ,distanceY, 0.00001f, 10000.0f); + // return glm::ortho(-glm::distance(focus,transform.GetPosition()) ,glm::distance(focus,transform.GetPosition()) ,-glm::distance(focus,transform.GetPosition()) ,glm::distance(focus,transform.GetPosition()), 0.00001f, 10000.0f); + }else{ + LOG("Swaping to Camera Perspective (cause of unknow type)"); + return glm::perspective(glm::radians(GetFOV()),(float)( ScreenSize.cx / ScreenSize.cy),GetDrawDistanceMin(),GetDrawDisanceMax());//We calculate Projection here since multiple camera can have different FOV + } + } + + virtual glm::mat4 GetViewMatrix(){ + return glm::lookAt( transform.GetPosition() , transform.GetPosition() + transform.GetFront() , transform.GetUp()); + } + + virtual SketchupCamera2& ProcessKeyboardMouvement(Camera_Movement direction){ + return *this; + } + + glm::vec3 GetVirtualAxis(){ + glm::vec3 v = transform.GetPosition(); + glm::vec3 virtualAxis = v + ((transform.GetFront()) * (DezoomFactor * 2.0f)); + glm::vec3 test = v - virtualAxis; + //Cout() <<"Distance between camera and virtual :" << test.x <<"," << test.y << "," << test.z << EOL; + return virtualAxis; + } + float GetDezoomFactor(){return DezoomFactor;} + + + virtual SketchupCamera2& ProcessMouseWheelTranslation(float xoffset,float yoffset){ + yoffset *= 0.05f * -1.0f; + xoffset *= 0.05f; + float Absx = sqrt(pow(xoffset,2)); + float Absy = sqrt(pow(yoffset,2)); + if(Absx > Absy){ + transform.Move(transform.GetRight() * xoffset); + }else{ + transform.Move(transform.GetUp() * yoffset); + } + return *this; + } + + virtual SketchupCamera2& ProcessMouseWheelMouvement(float xoffset,float yoffset){ + xoffset *= MouseSensitivity; + yoffset *= MouseSensitivity; + float a1 = xoffset * -1.0f; + // float AbsA1 = sqrt(pow(a1,2)); + float a2 = yoffset * -1.0f; + // float AbsA2 = sqrt(pow(a2,2)); + // if(AbsA1 > AbsA2) a2 = 0.0f; else a1 = 0.0f; + + glm::vec3 v = transform.GetPosition(); + //glm::vec3 axis = v + ((transform.GetFront() * 10.0f) * (DezoomFactor * 2.0f)); + glm::vec3 axis = GetVirtualAxis(); + glm::vec3 between = v - axis; + + glm::quat upRotation = Transform::GetQuaterion(a1,transform.GetWorldUp()); + glm::quat rightRotation = Transform::GetQuaterion(a2,glm::normalize(glm::cross(transform.GetUp(),between))); + between = glm::rotate(upRotation, between); + between = glm::rotate(rightRotation, between); + + transform.SetPosition(axis + between); + transform.Rotate(glm::inverse(upRotation * rightRotation)); + + return *this; + } + virtual SketchupCamera2& ProcessMouseLeftClick(float xoffset, float yoffset){ + Vector obj = Pick(xoffset ,yoffset); + Array centers; + for(Object3D* o : obj){ + if(o){ + o->ShowBoundingBox(true); + centers.Add(o->GetBoundingBoxTransformed().GetCenter()); + } + } + AdapteZoomFactor(centers); + return *this; + } + + virtual SketchupCamera2& ProcessMouveMouvement(float xoffset, float yoffset){ + if(MouseMiddlePressed && !ShiftPressed ) return ProcessMouseWheelMouvement(xoffset,yoffset); + if(MouseMiddlePressed && ShiftPressed ) return ProcessMouseWheelTranslation(xoffset,yoffset); + return *this; + } + + virtual bool ProcessKeyBoard(unsigned long Key,int count){ + return true; + } + + virtual SketchupCamera2& ProcessMouseScroll(float zdelta){ + float xoffset = (StartPress.x - (ScreenSize.cx/2)) * 0.005f; + float yoffset = (StartPress.y) * 0.005f * -1.0; + float Upoffset = (StartPress.y - (ScreenSize.cy/2)) * 0.005f; + bool doX = false, doY = false; + if(!forceZoom && ! (type == CT_ORTHOGRAPHIC)){ + /*if(sqrt(pow( StartPress.x - (ScreenSize.cx/2),2)) > (ScreenSize.cx/20)) doX = true; + if(sqrt(pow( StartPress.y - (ScreenSize.cy/2),2)) > (ScreenSize.cy/20)) doY = true;*/ + doX = true; + doY = true; + } + //glm::vec3 scaling = (0.1f * (transform.GetPosition())); + glm::vec3 scaling = - transform.GetFront()* 2.0f; + if(zdelta == - 120){ + if(doX)transform.SetPosition(transform.GetPosition() - (transform.GetRight() * xoffset)); + if(doY){ + transform.SetPosition(transform.GetPosition() +(transform.GetFront() * yoffset)); + transform.SetPosition(transform.GetPosition() + (transform.GetUp() * Upoffset)); + } + if(!doY && !doX){ + transform.SetPosition(transform.GetPosition() + scaling); + DezoomFactor +=1.0f; + } + }else{ + if(doX)transform.SetPosition(transform.GetPosition() + (transform.GetRight() * xoffset)); + if(doY){ + transform.SetPosition(transform.GetPosition() - (transform.GetFront() * yoffset)); + transform.SetPosition(transform.GetPosition() - (transform.GetUp() * Upoffset)); + } + if(!doY && !doX){ + if(DezoomFactor > 2.0f){ + transform.SetPosition(transform.GetPosition() - scaling); + DezoomFactor -=1.0f; + } + } + } + return *this; + } + + }; +} + +#endif diff --git a/bazaar/SurfaceCtrl/SketchupCamera.h b/bazaar/SurfaceCtrl/SketchupCamera.h index 36863dd0f..ba3ca01dd 100644 --- a/bazaar/SurfaceCtrl/SketchupCamera.h +++ b/bazaar/SurfaceCtrl/SketchupCamera.h @@ -81,18 +81,16 @@ class SketchupCamera : public UOGL_Camera { return *this; } - virtual bool ProcessKeyBoard(unsigned long Key,int count){ + virtual bool ProcessKeyBoard(unsigned long Key,int count)noexcept{ return true; } - virtual SketchupCamera& ProcessMouseScroll(float zdelta){ - float xoffset = (StartPress.x - (ScreenSize.cx/2)) * 0.005f; - float yoffset = (StartPress.y) * 0.005f * -1.0; - float Upoffset = (StartPress.y - (ScreenSize.cy/2)) * 0.005f; + virtual SketchupCamera& ProcessMouseScroll(float zdelta)noexcept{ + float xoffset = (lastPress.x - (ScreenSize.cx/2)) * 0.005f; + float yoffset = (lastPress.y) * 0.005f * -1.0; + float Upoffset = (lastPress.y - (ScreenSize.cy/2)) * 0.005f; bool doX = false, doY = false; if(!forceZoom && ! (type == CT_ORTHOGRAPHIC)){ - /*if(sqrt(pow( StartPress.x - (ScreenSize.cx/2),2)) > (ScreenSize.cx/20)) doX = true; - if(sqrt(pow( StartPress.y - (ScreenSize.cy/2),2)) > (ScreenSize.cy/20)) doY = true;*/ doX = true; doY = true; } diff --git a/bazaar/SurfaceCtrl/SketchupCamera2.h b/bazaar/SurfaceCtrl/SketchupCamera2.h index 9c40f718c..a2e0d76d7 100644 --- a/bazaar/SurfaceCtrl/SketchupCamera2.h +++ b/bazaar/SurfaceCtrl/SketchupCamera2.h @@ -161,14 +161,14 @@ class SketchupCamera2 : public UOGL_Camera{ return *this; } - virtual bool ProcessKeyBoard(unsigned long Key,int count){ + virtual bool ProcessKeyBoard(unsigned long Key,int count)noexcept{ return true; } - virtual SketchupCamera2& ProcessMouseScroll(float zdelta){ - float xoffset = (StartPress.x - (ScreenSize.cx/2)) * 0.005f; - float yoffset = (StartPress.y) * 0.005f * -1.0; - float Upoffset = (StartPress.y - (ScreenSize.cy/2)) * 0.005f; + virtual SketchupCamera2& ProcessMouseScroll(float zdelta)noexcept{ + float xoffset = (lastPress.x - (ScreenSize.cx/2)) * 0.005f; + float yoffset = (lastPress.y) * 0.005f * -1.0; + float Upoffset = (lastPress.y - (ScreenSize.cy/2)) * 0.005f; bool doX = false, doY = false; if(!forceZoom && ! (type == CT_ORTHOGRAPHIC)){ /*if(sqrt(pow( StartPress.x - (ScreenSize.cx/2),2)) > (ScreenSize.cx/20)) doX = true; diff --git a/bazaar/SurfaceCtrl/SurfaceCtrl.cpp b/bazaar/SurfaceCtrl/SurfaceCtrl.cpp index c47697709..fb4280e0a 100644 --- a/bazaar/SurfaceCtrl/SurfaceCtrl.cpp +++ b/bazaar/SurfaceCtrl/SurfaceCtrl.cpp @@ -108,6 +108,7 @@ void SurfaceCtrl::GLResize(int w, int h){ sizeW = w; sizeH = h; glViewport(0, 0, (GLsizei)w, (GLsizei)h); + camera.SetScreenSize(w,h); Refresh(); } bool SurfaceCtrl::Key(dword key,int count){ @@ -239,11 +240,11 @@ bool SurfaceCtrl::Key(dword key,int count){ } void SurfaceCtrl::MouseMove(Point p, dword keyflags){ if(camera.MouseMiddlePressed || camera.MouseLeftPressed){ - camera.ProcessMouveMouvement(p.x - camera.StartPress.x,p.y - camera.StartPress.y); + camera.ProcessMouveMouvement(p.x - camera.lastPress.x,p.y - camera.lastPress.y); Refresh(); } - camera.StartPress = p; + camera.lastPress = p; } void SurfaceCtrl::MouseWheel(Point p,int zdelta,dword keyflags){ camera.forceZoom = keyflags & K_CTRL; @@ -251,7 +252,7 @@ void SurfaceCtrl::MouseWheel(Point p,int zdelta,dword keyflags){ Refresh(); } void SurfaceCtrl::LeftDown(Point p, dword){ - camera.StartPress = p; + camera.lastPress = p; camera.MouseLeftPressed = true; camera.ProcessMouseLeftClick(p.x,p.y); Refresh(); @@ -262,7 +263,7 @@ void SurfaceCtrl::LeftUp(Point p, dword){ void SurfaceCtrl::MiddleDown(Point p, dword keyflags){ camera.MouseMiddlePressed = true; camera.ShiftPressed = keyflags & K_SHIFT; - camera.StartPress = p; + camera.lastPress = p; } void SurfaceCtrl::MiddleUp(Point p, dword keyflags){ camera.MouseMiddlePressed = false; diff --git a/bazaar/SurfaceCtrl/SurfaceCtrl.upp b/bazaar/SurfaceCtrl/SurfaceCtrl.upp index cfc48e4c2..c94cf588a 100644 --- a/bazaar/SurfaceCtrl/SurfaceCtrl.upp +++ b/bazaar/SurfaceCtrl/SurfaceCtrl.upp @@ -17,6 +17,7 @@ file Transform.cpp, Camera.h, Camera.cpp, + MagicCamera.h, TrackBallCamera.h, SketchupCamera.h, SketchupCamera2.h, diff --git a/bazaar/SurfaceCtrl/TrackBallCamera.h b/bazaar/SurfaceCtrl/TrackBallCamera.h index db7e29eb9..957f08c06 100644 --- a/bazaar/SurfaceCtrl/TrackBallCamera.h +++ b/bazaar/SurfaceCtrl/TrackBallCamera.h @@ -22,7 +22,7 @@ class TrackBallCamera : public UOGL_Camera { TrackBallCamera& Init(){ - SetPosition(glm::vec3(0.0f,0.0f,5.0f)); + transform.SetPosition(glm::vec3(0.0f,0.0f,5.0f)); LookAt(focus); return *this; } @@ -145,7 +145,7 @@ class TrackBallCamera : public UOGL_Camera { } - virtual bool ProcessKeyBoard(unsigned long Key,int count){ + virtual bool ProcessKeyBoard(unsigned long Key,int count)noexcept{ /* if( Key == Upp::K_Z){ objectToFocus->GetTransform().Move(glm::vec3(0,1 * 0.3f,0)); @@ -164,7 +164,7 @@ class TrackBallCamera : public UOGL_Camera { return true; } - virtual TrackBallCamera& ProcessMouseScroll(float zdelta){ + virtual TrackBallCamera& ProcessMouseScroll(float zdelta)noexcept{ glm::vec3 camPos = transform.GetPosition(); float result = glm::dot(transform.GetPosition(), glm::vec3(0.1f,0.1f,0.1f)); diff --git a/bazaar/SurfaceCtrl/Transform.cpp b/bazaar/SurfaceCtrl/Transform.cpp index cb06024d6..481c768b0 100644 --- a/bazaar/SurfaceCtrl/Transform.cpp +++ b/bazaar/SurfaceCtrl/Transform.cpp @@ -1,4 +1,4 @@ -#include "Transform.h" +//#include "Transform.h" /* Transform object from UltimateOpenGL */ diff --git a/bazaar/SurfaceCtrl/Transform.h b/bazaar/SurfaceCtrl/Transform.h index 3d0d4a84e..921b31d4f 100644 --- a/bazaar/SurfaceCtrl/Transform.h +++ b/bazaar/SurfaceCtrl/Transform.h @@ -36,7 +36,7 @@ class Transform{ public: Transform(){} Transform(const Transform& _transform){*this = _transform;} - Transform& operator=(const Transform& _transform){Front = _transform.Front; Up = _transform.Up; Right = _transform.Right; WorldUp = _transform.WorldUp; Position = _transform.Position; Rotation = _transform.Rotation; Scale = _transform.Scale; return *this;} + Transform& operator=(const Transform& _transform){Front = _transform.Front; Up = _transform.Up; Right = _transform.Right; WorldUp = _transform.WorldUp; WorldFront = _transform.WorldFront; WorldRight = _transform.WorldRight; Position = _transform.Position; Rotation = _transform.Rotation; Scale = _transform.Scale; return *this;} virtual ~Transform(){} Transform& SetFront(const glm::vec3& vec3)noexcept{Front = vec3; return *this;}