mirror of
https://github.com/leozide/leocad
synced 2025-01-17 18:11:42 +01:00
Merged projection and view classes.
This commit is contained in:
parent
e0d4f03cbc
commit
df90611f77
8 changed files with 64 additions and 248 deletions
|
@ -598,21 +598,6 @@ void lcCamera::BoxTest(lcObjectBoxTest& ObjectBoxTest) const
|
|||
}
|
||||
}
|
||||
|
||||
void lcCamera::LoadProjection(const lcProjection& projection)
|
||||
{
|
||||
if (m_pTR != NULL)
|
||||
m_pTR->BeginTile();
|
||||
else
|
||||
{
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
mProjection = projection;
|
||||
glLoadMatrixf((lcMatrix44&)mProjection);
|
||||
}
|
||||
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadMatrixf(mWorldView);
|
||||
}
|
||||
|
||||
void lcCamera::ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, unsigned short nTime, bool bAddKey)
|
||||
{
|
||||
int Viewport[4] = { 0, 0, view->mWidth, view->mHeight };
|
||||
|
@ -823,12 +808,22 @@ void lcCamera::SetViewpoint(LC_VIEWPOINT Viewpoint, unsigned short nTime, bool b
|
|||
UpdatePosition(nTime);
|
||||
}
|
||||
|
||||
void lcCamera::StartTiledRendering(int tw, int th, int iw, int ih, float fAspect)
|
||||
void lcCamera::StartTiledRendering(int tw, int th, int iw, int ih, float AspectRatio)
|
||||
{
|
||||
m_pTR = new TiledRender();
|
||||
m_pTR->TileSize(tw, th, 0);
|
||||
m_pTR->ImageSize(iw, ih);
|
||||
m_pTR->Perspective(m_fovy, fAspect, m_zNear, m_zFar);
|
||||
if (IsOrtho())
|
||||
{
|
||||
float f = (mPosition - mOrthoTarget).Length();
|
||||
float d = (m_fovy * f) * (LC_PI / 180.0f);
|
||||
float r = d / 2;
|
||||
|
||||
float right = r * AspectRatio;
|
||||
m_pTR->Ortho(-right, right, -r, r, m_zNear, m_zFar * 4);
|
||||
}
|
||||
else
|
||||
m_pTR->Perspective(m_fovy, AspectRatio, m_zNear, m_zFar);
|
||||
}
|
||||
|
||||
void lcCamera::GetTileInfo(int* row, int* col, int* width, int* height)
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include "object.h"
|
||||
#include "lc_math.h"
|
||||
#include "lc_array.h"
|
||||
#include "lc_projection.h"
|
||||
|
||||
class TiledRender;
|
||||
class View;
|
||||
|
@ -256,7 +255,6 @@ public:
|
|||
void UpdatePosition(unsigned short nTime);
|
||||
void CopyPosition(const Camera* camera);
|
||||
void Render(View* View);
|
||||
void LoadProjection(const lcProjection& projection);
|
||||
|
||||
void ZoomExtents(View* view, const lcVector3& Center, const lcVector3* Points, int NumPoints, unsigned short nTime, bool bAddKey);
|
||||
void ZoomRegion(View* view, float Left, float Right, float Bottom, float Top, unsigned short nTime, bool bAddKey);
|
||||
|
@ -284,15 +282,13 @@ public:
|
|||
lcVector3 mTargetPosition;
|
||||
lcVector3 mUpVector;
|
||||
lcVector3 mOrthoTarget;
|
||||
lcProjection mProjection;
|
||||
TiledRender* m_pTR;
|
||||
|
||||
protected:
|
||||
void Initialize();
|
||||
|
||||
lcuint32 mState;
|
||||
unsigned char m_nType;
|
||||
|
||||
TiledRender* m_pTR;
|
||||
};
|
||||
|
||||
#endif // _CAMERA_H_
|
||||
|
|
|
@ -1,50 +0,0 @@
|
|||
#include "lc_global.h"
|
||||
#include "lc_math.h"
|
||||
#include "lc_projection.h"
|
||||
#include "camera.h"
|
||||
|
||||
const char* lcProjection::GetName() const
|
||||
{
|
||||
if (!mCamera)
|
||||
return "";
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
return "Ortho";
|
||||
else
|
||||
return "Projection";
|
||||
}
|
||||
|
||||
void lcProjection::setTransformInput(const Camera* pCamera, int width, int height)
|
||||
{
|
||||
mViewPixelWidth = width;
|
||||
mViewPixelHeight = height;
|
||||
mCamera = pCamera;
|
||||
|
||||
calculateTransform();
|
||||
}
|
||||
|
||||
void lcProjection::calculateTransform()
|
||||
{
|
||||
if (NULL == mCamera)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
float fAspect = (float)mViewPixelWidth/(float)mViewPixelHeight;
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
{
|
||||
// Compute the FOV/plane intersection radius.
|
||||
// d d
|
||||
// a = 2 atan(------) => ~ a = --- => d = af
|
||||
// 2f f
|
||||
float f = (mCamera->mPosition - mCamera->mOrthoTarget).Length();
|
||||
float d = ( mCamera->m_fovy * f) * (LC_PI / 180.0f);
|
||||
float r = d/2;
|
||||
|
||||
float right = r * fAspect;
|
||||
mTransform = lcMatrix44Ortho(-right, right, -r, r, mCamera->m_zNear, mCamera->m_zFar * 4);
|
||||
}
|
||||
else
|
||||
mTransform = lcMatrix44Perspective(mCamera->m_fovy, fAspect, mCamera->m_zNear, mCamera->m_zFar);
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
#ifndef _LC_PROJECTION_H_
|
||||
#define _LC_PROJECTION_H_
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "opengl.h"
|
||||
#include "lc_math.h"
|
||||
|
||||
class lcProjection
|
||||
{
|
||||
public:
|
||||
|
||||
enum Type
|
||||
{
|
||||
Ortho = 0,
|
||||
Projection,
|
||||
OUT_OF_RANGE,
|
||||
Cycle
|
||||
};
|
||||
|
||||
lcProjection()
|
||||
{
|
||||
mTransform = lcMatrix44Identity();
|
||||
mCamera = NULL;
|
||||
}
|
||||
|
||||
inline void SetView(const Camera* pCamera, int width, int height)
|
||||
{
|
||||
setTransformInput(pCamera, width, height);
|
||||
}
|
||||
|
||||
inline lcVector3 ProjectPoint(const lcMatrix44& WorldView, const lcVector3& Point) const
|
||||
{
|
||||
int viewport[4] = { 0, 0, mViewPixelWidth, mViewPixelHeight };
|
||||
return lcProjectPoint(Point, WorldView, mTransform, viewport);
|
||||
}
|
||||
|
||||
inline lcVector3 UnprojectPoint(const lcMatrix44& WorldView, const lcVector3& Point) const
|
||||
{
|
||||
int viewport[4] = { 0, 0, mViewPixelWidth, mViewPixelHeight };
|
||||
return lcUnprojectPoint(Point, WorldView, mTransform, viewport);
|
||||
}
|
||||
|
||||
inline void UnprojectPoints(const lcMatrix44& WorldView, lcVector3* Points, int NumPoints) const
|
||||
{
|
||||
if (NumPoints > 0)
|
||||
{
|
||||
int viewport[4] = { 0, 0, mViewPixelWidth, mViewPixelHeight };
|
||||
lcUnprojectPoints(Points, NumPoints, WorldView, mTransform, viewport);
|
||||
}
|
||||
}
|
||||
|
||||
inline int ConstrainX(int x) const
|
||||
{
|
||||
if (x >= mViewPixelWidth)
|
||||
return mViewPixelWidth - 1;
|
||||
else
|
||||
if (x <= 0)
|
||||
return 1;
|
||||
return x;
|
||||
}
|
||||
|
||||
inline int ConstrainY(int y) const
|
||||
{
|
||||
if (y >= mViewPixelHeight)
|
||||
return mViewPixelHeight - 1;
|
||||
else
|
||||
if (y <= 0)
|
||||
return 1;
|
||||
return y;
|
||||
}
|
||||
|
||||
operator lcMatrix44& ()
|
||||
{
|
||||
return mTransform;
|
||||
}
|
||||
|
||||
const char* GetName() const;
|
||||
void calculateTransform();
|
||||
|
||||
private:
|
||||
void setTransformInput(const Camera* pCamera, int width, int height);
|
||||
|
||||
lcMatrix44 mTransform;
|
||||
const Camera* mCamera;
|
||||
int mViewPixelWidth;
|
||||
int mViewPixelHeight;
|
||||
};
|
||||
|
||||
#endif // _LC_PROJECTION_H_
|
|
@ -5292,7 +5292,6 @@ void Project::HandleCommand(LC_COMMANDS id)
|
|||
m_ActiveView->mCamera->SetOrtho(false);
|
||||
if (m_ActiveView->mCamera->IsFocused())
|
||||
gMainWindow->UpdateFocusObject(m_ActiveView->mCamera);
|
||||
m_ActiveView->SetProjectionType(lcProjection::Projection);
|
||||
m_ActiveView->Redraw();
|
||||
gMainWindow->UpdatePerspective(m_ActiveView);
|
||||
break;
|
||||
|
@ -5301,13 +5300,12 @@ void Project::HandleCommand(LC_COMMANDS id)
|
|||
m_ActiveView->mCamera->SetOrtho(true);
|
||||
if (m_ActiveView->mCamera->IsFocused())
|
||||
gMainWindow->UpdateFocusObject(m_ActiveView->mCamera);
|
||||
m_ActiveView->SetProjectionType(lcProjection::Ortho);
|
||||
m_ActiveView->Redraw();
|
||||
gMainWindow->UpdatePerspective(m_ActiveView);
|
||||
break;
|
||||
|
||||
case LC_VIEW_PROJECTION_CYCLE:
|
||||
m_ActiveView->SetProjectionType(lcProjection::Cycle);
|
||||
m_ActiveView->mCamera->SetOrtho(!m_ActiveView->mCamera->IsOrtho());
|
||||
m_ActiveView->Redraw();
|
||||
gMainWindow->UpdatePerspective(m_ActiveView);
|
||||
break;
|
||||
|
@ -5432,9 +5430,8 @@ void Project::HandleCommand(LC_COMMANDS id)
|
|||
{
|
||||
// TODO: rewrite this
|
||||
|
||||
const lcProjection& projection = m_ActiveView->UpdateProjection();
|
||||
lcVector3 Pts[3] = { lcVector3(5.0f, 5.0f, 0.1f), lcVector3(10.0f, 5.0f, 0.1f), lcVector3(5.0f, 10.0f, 0.1f) };
|
||||
projection.UnprojectPoints(m_ActiveView->mCamera->mWorldView, Pts, 3);
|
||||
m_ActiveView->UnprojectPoints(Pts, 3);
|
||||
|
||||
float ax, ay;
|
||||
lcVector3 vx((Pts[1][0] - Pts[0][0]), (Pts[1][1] - Pts[0][1]), 0);//Pts[1][2] - Pts[0][2] };
|
||||
|
@ -6146,49 +6143,42 @@ void Project::HandleCommand(LC_COMMANDS id)
|
|||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_FRONT, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_BACK:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_BACK, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_TOP:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_TOP, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_BOTTOM:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_BOTTOM, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_LEFT:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_LEFT, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_RIGHT:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_RIGHT, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_VIEWPOINT_HOME:
|
||||
{
|
||||
m_ActiveView->mCamera->SetViewpoint(LC_VIEWPOINT_HOME, m_nCurStep, m_bAddKeys);
|
||||
HandleCommand(LC_VIEW_ZOOM_EXTENTS);
|
||||
m_ActiveView->UpdateProjection();
|
||||
} break;
|
||||
|
||||
case LC_VIEW_CAMERA_NONE:
|
||||
|
@ -6917,10 +6907,8 @@ void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, lcVecto
|
|||
}
|
||||
|
||||
// Try to hit the base grid.
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
|
||||
lcVector3 ClickPoints[2] = { lcVector3((float)m_nDownX, (float)m_nDownY, 0.0f), lcVector3((float)m_nDownX, (float)m_nDownY, 1.0f) };
|
||||
projection.UnprojectPoints(view->mCamera->mWorldView, ClickPoints, 2);
|
||||
view->UnprojectPoints(ClickPoints, 2);
|
||||
|
||||
lcVector3 Intersection;
|
||||
if (lcLinePlaneIntersection(&Intersection, ClickPoints[0], ClickPoints[1], lcVector4(0, 0, 1, m_pCurPiece->m_fDimensions[5])))
|
||||
|
@ -6932,21 +6920,19 @@ void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, lcVecto
|
|||
}
|
||||
|
||||
// Couldn't find a good position, so just place the piece somewhere near the camera.
|
||||
Position = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)m_nDownX, (float)m_nDownY, 0.9f));
|
||||
Position = view->UnprojectPoint(lcVector3((float)m_nDownX, (float)m_nDownY, 0.9f));
|
||||
Rotation = lcVector4(0, 0, 1, 0);
|
||||
}
|
||||
|
||||
lcObjectSection Project::FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly)
|
||||
{
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
|
||||
lcVector3 Start = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.0f));
|
||||
lcVector3 End = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 1.0f));
|
||||
lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) };
|
||||
view->UnprojectPoints(StartEnd, 2);
|
||||
|
||||
lcObjectRayTest ObjectRayTest;
|
||||
|
||||
ObjectRayTest.Start = Start;
|
||||
ObjectRayTest.End = End;
|
||||
ObjectRayTest.Start = StartEnd[0];
|
||||
ObjectRayTest.End = StartEnd[1];
|
||||
ObjectRayTest.Distance = FLT_MAX;
|
||||
ObjectRayTest.ObjectSection.Object = NULL;
|
||||
ObjectRayTest.ObjectSection.Section = 0;;
|
||||
|
@ -6979,8 +6965,6 @@ lcObjectSection Project::FindObjectFromPoint(View* view, int x, int y, bool Piec
|
|||
|
||||
lcArray<lcObjectSection> Project::FindObjectsInBox(View* View, float x1, float y1, float x2, float y2)
|
||||
{
|
||||
const lcProjection& projection = m_ActiveView->UpdateProjection();
|
||||
|
||||
// Find out the top-left and bottom-right corners in screen coordinates.
|
||||
float Left, Top, Bottom, Right;
|
||||
|
||||
|
@ -7013,7 +6997,7 @@ lcArray<lcObjectSection> Project::FindObjectsInBox(View* View, float x1, float y
|
|||
lcVector3(Right, Top, 0), lcVector3(Left, Top, 1), lcVector3(Right, Bottom, 1)
|
||||
};
|
||||
|
||||
projection.UnprojectPoints(m_ActiveView->mCamera->mWorldView, Corners, 6);
|
||||
m_ActiveView->UnprojectPoints(Corners, 6);
|
||||
|
||||
// Build the box planes.
|
||||
lcVector3 PlaneNormals[6];
|
||||
|
@ -8106,8 +8090,7 @@ void Project::OnLeftButtonDown(View* view)
|
|||
m_MouseTotalDelta = lcVector3(0, 0, 0);
|
||||
m_MouseSnapLeftover = lcVector3(0, 0, 0);
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
lcVector3 point = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.9f));
|
||||
lcVector3 point = view->UnprojectPoint(lcVector3((float)x, (float)y, 0.9f));
|
||||
|
||||
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
|
||||
|
||||
|
@ -8259,7 +8242,7 @@ void Project::OnLeftButtonDown(View* view)
|
|||
if (count == max)
|
||||
break;
|
||||
|
||||
lcVector3 tmp = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3(x+1.0f, y-1.0f, 0.9f));
|
||||
lcVector3 tmp = view->UnprojectPoint(lcVector3(x+1.0f, y-1.0f, 0.9f));
|
||||
StartTracking(LC_TRACK_START_LEFT);
|
||||
Light* NewLight = new Light(m_fTrack[0], m_fTrack[1], m_fTrack[2], tmp[0], tmp[1], tmp[2]);
|
||||
mLights.Add(NewLight);
|
||||
|
@ -8269,7 +8252,7 @@ void Project::OnLeftButtonDown(View* view)
|
|||
|
||||
case LC_TOOL_CAMERA:
|
||||
{
|
||||
lcVector3 tmp = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3(x+1.0f, y-1.0f, 0.9f));
|
||||
lcVector3 tmp = view->UnprojectPoint(lcVector3(x + 1.0f, y - 1.0f, 0.9f));
|
||||
StartTracking(LC_TRACK_START_LEFT);
|
||||
|
||||
Camera* NewCamera = new Camera(m_fTrack[0], m_fTrack[1], m_fTrack[2], tmp[0], tmp[1], tmp[2]);
|
||||
|
@ -8381,8 +8364,7 @@ void Project::OnMiddleButtonDown(View* view)
|
|||
m_nDownY = y;
|
||||
m_bTrackCancel = false;
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
lcVector3 point = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.9f));
|
||||
lcVector3 point = view->UnprojectPoint(lcVector3((float)x, (float)y, 0.9f));
|
||||
|
||||
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
|
||||
|
||||
|
@ -8392,16 +8374,8 @@ void Project::OnMiddleButtonDown(View* view)
|
|||
switch (GetAction())
|
||||
{
|
||||
case LC_TOOL_PAN:
|
||||
{
|
||||
StartTracking(LC_TRACK_START_RIGHT);
|
||||
} break;
|
||||
|
||||
default:
|
||||
{
|
||||
view->SetProjectionType(lcProjection::Cycle);
|
||||
gMainWindow->UpdatePerspective(view);
|
||||
UpdateAllViews();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -8426,8 +8400,7 @@ void Project::OnRightButtonDown(View* view)
|
|||
m_nDownY = y;
|
||||
m_bTrackCancel = false;
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
lcVector3 point = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.9f));
|
||||
lcVector3 point = view->UnprojectPoint(lcVector3((float)x, (float)y, 0.9f));
|
||||
|
||||
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
|
||||
|
||||
|
@ -8515,8 +8488,7 @@ void Project::OnMouseMove(View* view)
|
|||
|
||||
float ptx, pty, ptz;
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
lcVector3 tmp = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.9f));
|
||||
lcVector3 tmp = view->UnprojectPoint(lcVector3((float)x, (float)y, 0.9f));
|
||||
|
||||
ptx = tmp[0]; pty = tmp[1]; ptz = tmp[2];
|
||||
|
||||
|
@ -8524,8 +8496,8 @@ void Project::OnMouseMove(View* view)
|
|||
{
|
||||
case LC_TOOL_SELECT:
|
||||
{
|
||||
m_fTrack[0] = (float)projection.ConstrainX(x);
|
||||
m_fTrack[1] = (float)projection.ConstrainY(y);
|
||||
m_fTrack[0] = lcClamp((float)x, 1.0f, view->mWidth - 1.0f);
|
||||
m_fTrack[1] = lcClamp((float)y, 1.0f, view->mHeight - 1.0f);
|
||||
|
||||
if (m_nTracking != LC_TRACK_NONE)
|
||||
{
|
||||
|
@ -9036,8 +9008,6 @@ void Project::MouseUpdateOverlays(View* view, int x, int y)
|
|||
const float OverlayRotateArrowStart = 1.0f * OverlayScale;
|
||||
const float OverlayRotateArrowEnd = 1.5f * OverlayScale;
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
|
||||
// Intersect the mouse with the 3 planes.
|
||||
lcVector3 PlaneNormals[3] =
|
||||
{
|
||||
|
@ -9061,8 +9031,10 @@ void Project::MouseUpdateOverlays(View* view, int x, int y)
|
|||
}
|
||||
|
||||
int Mode = (m_nCurAction == LC_TOOL_MOVE) ? LC_OVERLAY_MOVE_XYZ : LC_OVERLAY_NONE;
|
||||
lcVector3 Start = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.0f));
|
||||
lcVector3 End = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 1.0f));
|
||||
lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) };
|
||||
view->UnprojectPoints(StartEnd, 2);
|
||||
const lcVector3& Start = StartEnd[0];
|
||||
const lcVector3& End = StartEnd[1];
|
||||
float ClosestIntersectionDistance = FLT_MAX;
|
||||
|
||||
for (int AxisIndex = 0; AxisIndex < 3; AxisIndex++)
|
||||
|
@ -9131,11 +9103,11 @@ void Project::MouseUpdateOverlays(View* view, int x, int y)
|
|||
const float OverlayRotateRadius = 2.0f;
|
||||
Camera* Cam = m_ActiveView->mCamera;
|
||||
|
||||
const lcProjection& projection = view->UpdateProjection();
|
||||
|
||||
// Unproject the mouse point against both the front and the back clipping planes.
|
||||
lcVector3 SegStart = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 0.0f));
|
||||
lcVector3 SegEnd = projection.UnprojectPoint(view->mCamera->mWorldView, lcVector3((float)x, (float)y, 1.0f));
|
||||
lcVector3 StartEnd[2] = { lcVector3((float)x, (float)y, 0.0f), lcVector3((float)x, (float)y, 1.0f) };
|
||||
view->UnprojectPoints(StartEnd, 2);
|
||||
const lcVector3& SegStart = StartEnd[0];
|
||||
const lcVector3& SegEnd = StartEnd[1];
|
||||
|
||||
lcVector3 Center(m_OverlayCenter);
|
||||
|
||||
|
@ -9355,10 +9327,9 @@ void Project::UpdateOverlayScale()
|
|||
{
|
||||
// Calculate the scaling factor by projecting the center to the front plane then
|
||||
// projecting a point close to it back.
|
||||
const lcProjection& projection = m_ActiveView->UpdateProjection();
|
||||
lcVector3 Screen = projection.ProjectPoint(m_ActiveView->mCamera->mWorldView, m_OverlayCenter);
|
||||
lcVector3 Screen = m_ActiveView->ProjectPoint(m_OverlayCenter);
|
||||
Screen[0] += 10.0f;
|
||||
lcVector3 Point = projection.UnprojectPoint(m_ActiveView->mCamera->mWorldView, Screen);
|
||||
lcVector3 Point = m_ActiveView->UnprojectPoint(Screen);
|
||||
|
||||
lcVector3 Dist(Point - m_OverlayCenter);
|
||||
m_ActiveView->m_OverlayScale = Dist.Length() * 5.0f;
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
#include "camera.h"
|
||||
#include "view.h"
|
||||
#include "system.h"
|
||||
#include "tr.h"
|
||||
|
||||
View::View(Project *project)
|
||||
{
|
||||
|
@ -56,6 +57,9 @@ lcMatrix44 View::GetProjectionMatrix() const
|
|||
{
|
||||
float AspectRatio = (float)mWidth / (float)mHeight;
|
||||
|
||||
if (mCamera->m_pTR)
|
||||
mCamera->m_pTR->BeginTile();
|
||||
|
||||
if (mCamera->IsOrtho())
|
||||
{
|
||||
// Compute the FOV/plane intersection radius.
|
||||
|
@ -141,27 +145,6 @@ LC_CURSOR_TYPE View::GetCursor() const
|
|||
}
|
||||
}
|
||||
|
||||
// Call this once before using a view during a callback in order
|
||||
// to pick up any changes to the view or its camera.
|
||||
const lcProjection& View::UpdateProjection()
|
||||
{
|
||||
mProjection.SetView(mCamera, mWidth, mHeight);
|
||||
mCamera->LoadProjection(mProjection);
|
||||
return mProjection;
|
||||
}
|
||||
|
||||
void View::SetProjectionType(lcProjection::Type type)
|
||||
{
|
||||
if (type == lcProjection::Ortho)
|
||||
mCamera->SetOrtho(true);
|
||||
else if (type == lcProjection::Projection)
|
||||
mCamera->SetOrtho(false);
|
||||
else if (type == lcProjection::Cycle)
|
||||
mCamera->SetOrtho(!mCamera->IsOrtho());
|
||||
|
||||
mProjection.calculateTransform();
|
||||
}
|
||||
|
||||
void View::OnDraw()
|
||||
{
|
||||
m_Project->Render(this, false);
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
#define _VIEW_H_
|
||||
|
||||
#include "lc_glwidget.h"
|
||||
#include "lc_projection.h"
|
||||
|
||||
class Project;
|
||||
|
||||
|
@ -28,8 +27,6 @@ public:
|
|||
void SetCamera(Camera* camera, bool ForceCopy);
|
||||
void SetDefaultCamera();
|
||||
lcMatrix44 GetProjectionMatrix() const;
|
||||
const lcProjection& UpdateProjection();
|
||||
void SetProjectionType(lcProjection::Type type);
|
||||
|
||||
LC_CURSOR_TYPE GetCursor() const;
|
||||
|
||||
|
@ -37,8 +34,23 @@ public:
|
|||
Camera* mCamera;
|
||||
float m_OverlayScale;
|
||||
|
||||
private:
|
||||
lcProjection mProjection;
|
||||
lcVector3 ProjectPoint(const lcVector3& Point) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
return lcProjectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
lcVector3 UnprojectPoint(const lcVector3& Point) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
return lcUnprojectPoint(Point, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
|
||||
void UnprojectPoints(lcVector3* Points, int NumPoints) const
|
||||
{
|
||||
int Viewport[4] = { 0, 0, mWidth, mHeight };
|
||||
lcUnprojectPoints(Points, NumPoints, mCamera->mWorldView, GetProjectionMatrix(), Viewport);
|
||||
}
|
||||
};
|
||||
|
||||
#endif // _VIEW_H_
|
||||
|
|
|
@ -103,7 +103,6 @@ SOURCES += common/view.cpp \
|
|||
common/lc_mainwindow.cpp \
|
||||
common/lc_mesh.cpp \
|
||||
common/lc_profile.cpp \
|
||||
common/lc_projection.cpp \
|
||||
common/lc_shortcuts.cpp \
|
||||
common/lc_texture.cpp \
|
||||
common/lc_zipfile.cpp \
|
||||
|
@ -167,7 +166,6 @@ HEADERS += \
|
|||
common/lc_math.h \
|
||||
common/lc_mesh.h \
|
||||
common/lc_profile.h \
|
||||
common/lc_projection.h \
|
||||
common/lc_shortcuts.h \
|
||||
common/lc_texture.h \
|
||||
common/lc_zipfile.h \
|
||||
|
|
Loading…
Reference in a new issue