Allow different cameras for each submodel.

This commit is contained in:
leo 2015-03-01 23:17:50 +00:00
parent 635d408101
commit 7440111b64
3 changed files with 38 additions and 5 deletions

View file

@ -66,7 +66,11 @@ void lcApplication::SetProject(Project* Project)
const lcArray<View*>& Views = gMainWindow->GetViews(); const lcArray<View*>& Views = gMainWindow->GetViews();
for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++) for (int ViewIdx = 0; ViewIdx < Views.GetSize(); ViewIdx++)
Views[ViewIdx]->SetModel(lcGetActiveModel()); {
View* View = Views[ViewIdx];
View->ClearCameras();
View->SetModel(lcGetActiveModel());
}
lcGetPiecesLibrary()->RemoveTemporaryPieces(); lcGetPiecesLibrary()->RemoveTemporaryPieces();
lcGetActiveModel()->UpdateInterface(); lcGetActiveModel()->UpdateInterface();

View file

@ -33,8 +33,9 @@ View::~View()
if (gMainWindow) if (gMainWindow)
gMainWindow->RemoveView(this); gMainWindow->RemoveView(this);
if (mCamera && mCamera->IsSimple()) foreach (lcCamera* Camera, mCameras)
delete mCamera; if (Camera && Camera->IsSimple())
delete Camera;
} }
void View::SetModel(lcModel* Model) void View::SetModel(lcModel* Model)
@ -44,14 +45,28 @@ void View::SetModel(lcModel* Model)
mModel = Model; mModel = Model;
if (mCamera && !mCamera->IsSimple()) lcCamera* Camera = mCameras.value(mModel);
if (Camera)
mCamera = Camera;
else
{ {
lcCamera* Camera = mCamera; Camera = mCamera;
mCamera = new lcCamera(true); mCamera = new lcCamera(true);
if (Camera) if (Camera)
mCamera->CopyPosition(Camera); mCamera->CopyPosition(Camera);
else
mCamera->SetViewpoint(LC_VIEWPOINT_HOME);
} }
mCameras[mModel] = mCamera;
}
void View::ClearCameras()
{
mCamera = NULL;
mCameras.clear();
} }
void View::RemoveCamera() void View::RemoveCamera()
@ -64,6 +79,10 @@ void View::RemoveCamera()
if (Camera) if (Camera)
mCamera->CopyPosition(Camera); mCamera->CopyPosition(Camera);
else
mCamera->SetViewpoint(LC_VIEWPOINT_HOME);
mCameras[mModel] = mCamera;
gMainWindow->UpdateCurrentCamera(-1); gMainWindow->UpdateCurrentCamera(-1);
Redraw(); Redraw();
@ -85,6 +104,8 @@ void View::SetCamera(lcCamera* Camera, bool ForceCopy)
mCamera = Camera; mCamera = Camera;
} }
mCameras[mModel] = mCamera;
} }
void View::SetCameraIndex(int Index) void View::SetCameraIndex(int Index)
@ -104,7 +125,10 @@ void View::SetCameraIndex(int Index)
void View::SetViewpoint(lcViewpoint Viewpoint) void View::SetViewpoint(lcViewpoint Viewpoint)
{ {
if (!mCamera || !mCamera->IsSimple()) if (!mCamera || !mCamera->IsSimple())
{
mCamera = new lcCamera(true); mCamera = new lcCamera(true);
mCameras[mModel] = mCamera;
}
mCamera->SetViewpoint(Viewpoint); mCamera->SetViewpoint(Viewpoint);
ZoomExtents(); ZoomExtents();
@ -114,7 +138,10 @@ void View::SetViewpoint(lcViewpoint Viewpoint)
void View::SetDefaultCamera() void View::SetDefaultCamera()
{ {
if (!mCamera || !mCamera->IsSimple()) if (!mCamera || !mCamera->IsSimple())
{
mCamera = new lcCamera(true); mCamera = new lcCamera(true);
mCameras[mModel] = mCamera;
}
mCamera->SetViewpoint(LC_VIEWPOINT_HOME); mCamera->SetViewpoint(LC_VIEWPOINT_HOME);
} }

View file

@ -80,6 +80,7 @@ public:
void LookAt(); void LookAt();
void ZoomExtents(); void ZoomExtents();
void ClearCameras();
void RemoveCamera(); void RemoveCamera();
void SetCamera(lcCamera* Camera, bool ForceCopy); void SetCamera(lcCamera* Camera, bool ForceCopy);
void SetCameraIndex(int Index); void SetCameraIndex(int Index);
@ -95,6 +96,7 @@ public:
lcModel* mModel; lcModel* mModel;
lcCamera* mCamera; lcCamera* mCamera;
QMap<lcModel*, lcCamera*> mCameras;
lcVector3 ProjectPoint(const lcVector3& Point) const lcVector3 ProjectPoint(const lcVector3& Point) const
{ {