Kaydet (Commit) b53e1acd authored tarafından Markus Mohrhard's avatar Markus Mohrhard

keep camera calculations out of the rendering code

Change-Id: I7a26ce1881958a7465692174dd8ea793b593efad
üst 28e7d538
...@@ -113,14 +113,12 @@ struct Extrude3DInfo ...@@ -113,14 +113,12 @@ struct Extrude3DInfo
struct CameraInfo struct CameraInfo
{ {
bool useDefault;
glm::vec3 cameraPos; glm::vec3 cameraPos;
glm::vec3 cameraOrg; glm::vec3 cameraOrg;
glm::vec3 cameraUp; glm::vec3 cameraUp;
CameraInfo(): CameraInfo():
useDefault(true), cameraUp(glm::vec3(0, 0, 1)) {}
cameraUp(glm::vec3(0, 1, 0)) {}
}; };
struct CoordinateAxisInfo struct CoordinateAxisInfo
...@@ -203,7 +201,7 @@ public: ...@@ -203,7 +201,7 @@ public:
void SetClickPos(Point aMPos); void SetClickPos(Point aMPos);
void RenderClickPos(Point aMPos); void RenderClickPos(Point aMPos);
void SetSize(const Size& rSize); void SetSize(const Size& rSize);
void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut); void SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up);
void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft); void CreateTextTexture(const BitmapEx& rBitmapEx, glm::vec3 vTopLeft,glm::vec3 vTopRight, glm::vec3 vBottomRight, glm::vec3 vBottomLeft);
void ProcessUnrenderedShape(); void ProcessUnrenderedShape();
private: private:
......
...@@ -184,7 +184,7 @@ Camera::Camera(OpenGL3DRenderer* pRenderer): ...@@ -184,7 +184,7 @@ Camera::Camera(OpenGL3DRenderer* pRenderer):
void Camera::render() void Camera::render()
{ {
mpRenderer->SetCameraInfo(maPos, maDirection, maUp, false); mpRenderer->SetCameraInfo(maPos, maDirection, maUp);
} }
void Camera::zoom(sal_uInt32 /*nId*/) void Camera::zoom(sal_uInt32 /*nId*/)
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include <StaticGeometry.h> #include <StaticGeometry.h>
#include "glm/gtc/matrix_inverse.hpp" #include "glm/gtc/matrix_inverse.hpp"
#define GL_PI 3.14159f
#define RGB_WHITE (0xFF | (0xFF << 8) | (0xFF << 16)) #define RGB_WHITE (0xFF | (0xFF << 8) | (0xFF << 16))
#define DEBUG_FBO 0 #define DEBUG_FBO 0
...@@ -141,13 +140,8 @@ void OpenGL3DRenderer::LoadShaders() ...@@ -141,13 +140,8 @@ void OpenGL3DRenderer::LoadShaders()
CHECK_GL_ERROR(); CHECK_GL_ERROR();
} }
void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up, bool useDefalut) void OpenGL3DRenderer::SetCameraInfo(glm::vec3 pos, glm::vec3 direction, glm::vec3 up)
{ {
m_CameraInfo.useDefault = useDefalut;
if (m_CameraInfo.useDefault)
{
return;
}
m_CameraInfo.cameraPos = pos; m_CameraInfo.cameraPos = pos;
m_CameraInfo.cameraOrg = pos + direction; m_CameraInfo.cameraOrg = pos + direction;
m_CameraInfo.cameraUp = up; m_CameraInfo.cameraUp = up;
...@@ -1458,26 +1452,6 @@ void OpenGL3DRenderer::RenderClickPos(Point aMPos) ...@@ -1458,26 +1452,6 @@ void OpenGL3DRenderer::RenderClickPos(Point aMPos)
void OpenGL3DRenderer::CreateSceneBoxView() void OpenGL3DRenderer::CreateSceneBoxView()
{ {
if (m_CameraInfo.useDefault)
{
float senceBoxWidth = m_SenceBox.maxXCoord - m_SenceBox.minXCoord;
float senceBoxHeight = m_SenceBox.maxYCoord - m_SenceBox.minYCoord;
float senceBoxDepth = m_SenceBox.maxZCoord - m_SenceBox.minZCoord;
float distanceZ = m_SenceBox.maxZCoord + senceBoxWidth / 2 / tan(m_fViewAngle / 2 * GL_PI / 180.0f);
float veriticalAngle = atan((float)m_iHeight / (float)m_iWidth);
float distance = distanceZ / cos(veriticalAngle);
float horizontalAngle = 0;
m_fHeightWeight = senceBoxWidth * (float)m_iHeight / (float)m_iWidth / senceBoxHeight;
m_SenceBox.maxYCoord *= m_fHeightWeight;
m_SenceBox.minYCoord *= m_fHeightWeight;
m_CameraInfo.cameraOrg = glm::vec3(m_SenceBox.minXCoord + senceBoxWidth / 2,
m_SenceBox.minYCoord + senceBoxHeight * m_fHeightWeight/ 2,
m_SenceBox.minZCoord + senceBoxDepth * 2);
//update the camera position and org
m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x + distance * cos(veriticalAngle) * sin(horizontalAngle);
m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle);
m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y + distance * sin(veriticalAngle);
}
m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space
m_CameraInfo.cameraOrg, // and looks at the origin m_CameraInfo.cameraOrg, // and looks at the origin
m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down) m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down)
...@@ -1601,25 +1575,11 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox() ...@@ -1601,25 +1575,11 @@ int OpenGL3DRenderer::ProcessExtrude3DPickingBox()
} }
return 0; return 0;
} }
//reset the camera by index
//update the camera position and org
float distance = 500;
float veriticalAngle = GL_PI / 3.25f;
float horizontalAngle = GL_PI / 6.0f;
extrude3DInfo = m_Extrude3DList[selectID]; extrude3DInfo = m_Extrude3DList[selectID];
extrude3DInfo.yTransform *= m_fHeightWeight; extrude3DInfo.yTransform *= m_fHeightWeight;
extrude3DInfo.yScale *= m_fHeightWeight; extrude3DInfo.yScale *= m_fHeightWeight;
int reverse = 1; int reverse = 1;
if (m_CameraInfo.useDefault)
{
m_CameraInfo.cameraOrg = glm::vec3(extrude3DInfo.xTransform + extrude3DInfo.xScale / 2,
-extrude3DInfo.yTransform + extrude3DInfo.yScale *reverse,
extrude3DInfo.zTransform + extrude3DInfo.xScale / 2);
m_CameraInfo.cameraPos.x = m_CameraInfo.cameraOrg.x - distance * cos(veriticalAngle) * sin(horizontalAngle);
m_CameraInfo.cameraPos.z = m_CameraInfo.cameraOrg.z + distance * cos(veriticalAngle) * cos(horizontalAngle);
m_CameraInfo.cameraPos.y = m_CameraInfo.cameraOrg.y + distance * sin(horizontalAngle) * reverse;
}
m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space m_3DView = glm::lookAt(m_CameraInfo.cameraPos, // Camera is at (0,0,3), in World Space
m_CameraInfo.cameraOrg, // and looks at the origin m_CameraInfo.cameraOrg, // and looks at the origin
m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down) m_CameraInfo.cameraUp // Head is up (set to 0,-1,0 to look upside-down)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment