Fixed inconsistencies between default viewpoints and the view cube.

This commit is contained in:
Leonardo Zide
2018-09-19 13:19:01 -07:00
parent f507e08cde
commit 8b0bfc801e
3 changed files with 45 additions and 40 deletions
+2 -2
View File
@@ -1003,8 +1003,8 @@ void lcCamera::SetViewpoint(const lcVector3& Position)
lcVector3 UpVector(0, 0, 1), FrontVector(Position), SideVector;
FrontVector.Normalize();
if (FrontVector == UpVector)
SideVector = lcVector3(1, 0, 0);
if (fabsf(lcDot(UpVector, FrontVector)) > 0.99f)
SideVector = lcVector3(-1, 0, 0);
else
SideVector = lcCross(FrontVector, UpVector);
UpVector = lcCross(SideVector, FrontVector);
+42 -38
View File
@@ -248,6 +248,8 @@ bool lcViewCube::OnLeftButtonDown()
if (Preferences.mViewCubeLocation == lcViewCubeLocation::DISABLED)
return false;
mIntersectionFlags = GetIntersectionFlags(mIntersection);
if (!mIntersectionFlags.any())
return false;
@@ -277,9 +279,9 @@ bool lcViewCube::OnLeftButtonUp()
for (int AxisIdx = 0; AxisIdx < 3; AxisIdx++)
{
if (mIntersectionFlags.test(AxisIdx * 2))
Position[AxisIdx] = 250.0f;
Position[AxisIdx] = 1250.0f;
else if (mIntersectionFlags.test(AxisIdx * 2 + 1))
Position[AxisIdx] = -250.0f;
Position[AxisIdx] = -1250.0f;
}
mView->SetViewpoint(Position);
@@ -305,42 +307,7 @@ bool lcViewCube::OnMouseMove()
if (mView->IsTracking())
return false;
int Width = mView->mWidth;
int Height = mView->mHeight;
int ViewportSize = Preferences.mViewCubeSize;
int Left = (Location == lcViewCubeLocation::BOTTOM_LEFT || Location == lcViewCubeLocation::TOP_LEFT) ? 0 : Width - ViewportSize;
int Bottom = (Location == lcViewCubeLocation::BOTTOM_LEFT || Location == lcViewCubeLocation::BOTTOM_RIGHT) ? 0 : Height - ViewportSize;
int x = mView->mInputState.x - Left;
int y = mView->mInputState.y - Bottom;
if (x < 0 || x > Width || y < 0 || y > Height)
{
if (mIntersectionFlags.any())
{
mIntersectionFlags.reset();
mView->Redraw();
}
return false;
}
lcVector3 StartEnd[2] = { lcVector3(x, y, 0), lcVector3(x, y, 1) };
const int Viewport[4] = { 0, 0, ViewportSize, ViewportSize };
lcUnprojectPoints(StartEnd, 2, GetViewMatrix(), GetProjectionMatrix(), Viewport);
std::bitset<6> IntersectionFlags;
float Distance;
if (lcBoundingBoxRayIntersectDistance(lcVector3(-BoxSize, -BoxSize, -BoxSize), lcVector3(BoxSize, BoxSize, BoxSize), StartEnd[0], StartEnd[1], &Distance, &mIntersection))
{
for (int AxisIdx = 0; AxisIdx < 3; AxisIdx++)
{
if (mIntersection[AxisIdx] > BoxSize * 2 / 3)
IntersectionFlags.set(2 * AxisIdx);
else if (mIntersection[AxisIdx] < -BoxSize * 2 / 3)
IntersectionFlags.set(2 * AxisIdx + 1);
}
}
std::bitset<6> IntersectionFlags = GetIntersectionFlags(mIntersection);
if (IntersectionFlags != mIntersectionFlags)
{
@@ -355,3 +322,40 @@ bool lcViewCube::IsDragging() const
{
return mMouseDown && (qAbs(mMouseDownX - mView->mInputState.x) > 3 || qAbs(mMouseDownY - mView->mInputState.y) > 3);
}
std::bitset<6> lcViewCube::GetIntersectionFlags(lcVector3& Intersection) const
{
const lcPreferences& Preferences = lcGetPreferences();
lcViewCubeLocation Location = Preferences.mViewCubeLocation;
int Width = mView->mWidth;
int Height = mView->mHeight;
int ViewportSize = Preferences.mViewCubeSize;
int Left = (Location == lcViewCubeLocation::BOTTOM_LEFT || Location == lcViewCubeLocation::TOP_LEFT) ? 0 : Width - ViewportSize;
int Bottom = (Location == lcViewCubeLocation::BOTTOM_LEFT || Location == lcViewCubeLocation::BOTTOM_RIGHT) ? 0 : Height - ViewportSize;
int x = mView->mInputState.x - Left;
int y = mView->mInputState.y - Bottom;
std::bitset<6> IntersectionFlags;
if (x < 0 || x > Width || y < 0 || y > Height)
return IntersectionFlags;
lcVector3 StartEnd[2] = { lcVector3(x, y, 0), lcVector3(x, y, 1) };
const int Viewport[4] = { 0, 0, ViewportSize, ViewportSize };
lcUnprojectPoints(StartEnd, 2, GetViewMatrix(), GetProjectionMatrix(), Viewport);
float Distance;
if (lcBoundingBoxRayIntersectDistance(lcVector3(-BoxSize, -BoxSize, -BoxSize), lcVector3(BoxSize, BoxSize, BoxSize), StartEnd[0], StartEnd[1], &Distance, &Intersection))
{
for (int AxisIdx = 0; AxisIdx < 3; AxisIdx++)
{
if (mIntersection[AxisIdx] > BoxSize * 2 / 3)
IntersectionFlags.set(2 * AxisIdx);
else if (mIntersection[AxisIdx] < -BoxSize * 2 / 3)
IntersectionFlags.set(2 * AxisIdx + 1);
}
}
return IntersectionFlags;
}
+1
View File
@@ -19,6 +19,7 @@ public:
protected:
lcMatrix44 GetViewMatrix() const;
lcMatrix44 GetProjectionMatrix() const;
std::bitset<6> GetIntersectionFlags(lcVector3& Intersection) const;
View* mView;
lcVector3 mIntersection;