Removed some of the old viewport code.

This commit is contained in:
leo 2012-01-30 07:31:29 +00:00
parent 8a5cab7acc
commit 9fb7a6cb6f
2 changed files with 110 additions and 132 deletions

View file

@ -1626,7 +1626,7 @@ void Project::Render(View* view, bool ToMemory)
RenderSceneObjects(view); RenderSceneObjects(view);
if (m_OverlayActive) if (m_OverlayActive || ((m_nCurAction == LC_ACTION_SELECT) && (m_nTracking == LC_TRACK_LEFT) && (m_ActiveView == view)))
RenderOverlays(view); RenderOverlays(view);
RenderViewports(view); RenderViewports(view);
@ -3169,15 +3169,10 @@ unsigned char Project::GetLastStep()
// Create a series of pictures // Create a series of pictures
void Project::CreateImages (Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite) void Project::CreateImages (Image* images, int width, int height, unsigned short from, unsigned short to, bool hilite)
{ {
int oldx, oldy;
unsigned short oldtime; unsigned short oldtime;
void* render = Sys_StartMemoryRender (width, height); void* render = Sys_StartMemoryRender (width, height);
unsigned char* buf = (unsigned char*)malloc (width*height*3); unsigned char* buf = (unsigned char*)malloc (width*height*3);
oldtime = m_bAnimation ? m_nCurFrame : m_nCurStep; oldtime = m_bAnimation ? m_nCurFrame : m_nCurStep;
oldx = m_nViewX;
oldy = m_nViewY;
m_nViewX = width;
m_nViewY = height;
View view(this, m_ActiveView); View view(this, m_ActiveView);
view.OnSize(width, height); view.OnSize(width, height);
@ -3213,8 +3208,6 @@ void Project::CreateImages (Image* images, int width, int height, unsigned short
images[i-from].FromOpenGL (width, height); images[i-from].FromOpenGL (width, height);
} }
// pDoc->m_ViewCameras[pDoc->m_nActiveViewport] = pOld; // pDoc->m_ViewCameras[pDoc->m_nActiveViewport] = pOld;
m_nViewX = oldx;
m_nViewY = oldy;
if (m_bAnimation) if (m_bAnimation)
m_nCurFrame = oldtime; m_nCurFrame = oldtime;
else else
@ -6401,11 +6394,9 @@ void Project::GetPieceInsertPosition(Piece* OffsetPiece, Vector3& Position, Vect
// Try to find a good starting position/orientation for a new piece. // Try to find a good starting position/orientation for a new piece.
void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Rotation) void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Rotation)
{ {
// See if the mouse is over a piece. // Check if the mouse is over a piece.
LC_CLICKLINE ClickLine; Piece* HitPiece = (Piece*)FindObjectFromPoint(view, MouseX, MouseY, true);
FindObjectFromPoint(MouseX, MouseY, &ClickLine, true);
Piece* HitPiece = (Piece*)ClickLine.pClosest;
if (HitPiece) if (HitPiece)
{ {
GetPieceInsertPosition(HitPiece, Position, Rotation); GetPieceInsertPosition(HitPiece, Position, Rotation);
@ -6440,46 +6431,45 @@ void Project::GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3
Rotation = Vector4(0, 0, 1, 0); Rotation = Vector4(0, 0, 1, 0);
} }
void Project::FindObjectFromPoint(int x, int y, LC_CLICKLINE* pLine, bool PiecesOnly) Object* Project::FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly)
{ {
GLdouble px, py, pz, rx, ry, rz; int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
GLdouble modelMatrix[16], projMatrix[16]; float Aspect = (float)Viewport[2]/(float)Viewport[3];
GLint viewport[4]; Camera* Cam = m_pViewCameras[m_nActiveViewport];
Piece* pPiece;
Camera* pCamera;
Light* pLight;
LoadViewportProjection(m_nActiveViewport); Matrix44 ModelView, Projection;
glGetDoublev(GL_MODELVIEW_MATRIX,modelMatrix); ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
glGetDoublev(GL_PROJECTION_MATRIX,projMatrix); Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
glGetIntegerv(GL_VIEWPORT,viewport);
// Unproject the selected point against both the front and the back clipping plane Vector3 Start = UnprojectPoint(Vector3((float)x, (float)y, 0.0f), ModelView, Projection, Viewport);
gluUnProject(x, y, 0, modelMatrix, projMatrix, viewport, &px, &py, &pz); Vector3 End = UnprojectPoint(Vector3((float)x, (float)y, 1.0f), ModelView, Projection, Viewport);
gluUnProject(x, y, 1, modelMatrix, projMatrix, viewport, &rx, &ry, &rz);
pLine->a1 = (float)px; LC_CLICKLINE ClickLine;
pLine->b1 = (float)py;
pLine->c1 = (float)pz;
pLine->a2 = (float)(rx-px);
pLine->b2 = (float)(ry-py);
pLine->c2 = (float)(rz-pz);
pLine->mindist = FLT_MAX;
pLine->pClosest = NULL;
for (pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext) ClickLine.a1 = Start[0];
ClickLine.b1 = Start[1];
ClickLine.c1 = Start[2];
ClickLine.a2 = End[0] - Start[0];
ClickLine.b2 = End[1] - Start[1];
ClickLine.c2 = End[2] - Start[2];
ClickLine.mindist = FLT_MAX;
ClickLine.pClosest = NULL;
for (Piece* pPiece = m_pPieces; pPiece; pPiece = pPiece->m_pNext)
if (pPiece->IsVisible(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation)) if (pPiece->IsVisible(m_bAnimation ? m_nCurFrame : m_nCurStep, m_bAnimation))
pPiece->MinIntersectDist(pLine); pPiece->MinIntersectDist(&ClickLine);
if (!PiecesOnly) if (!PiecesOnly)
{ {
for (pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext) for (Camera* pCamera = m_pCameras; pCamera; pCamera = pCamera->m_pNext)
if (pCamera != m_pViewCameras[m_nActiveViewport]) if (pCamera != m_pViewCameras[m_nActiveViewport])
pCamera->MinIntersectDist(pLine); pCamera->MinIntersectDist(&ClickLine);
for (pLight = m_pLights; pLight; pLight = pLight->m_pNext) for (Light* pLight = m_pLights; pLight; pLight = pLight->m_pNext)
pLight->MinIntersectDist(pLine); pLight->MinIntersectDist(&ClickLine);
} }
return ClickLine.pClosest;
} }
void Project::FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects) void Project::FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects)
@ -6701,14 +6691,7 @@ bool Project::StopTracking(bool bAccept)
case LC_ACTION_ZOOM_REGION: case LC_ACTION_ZOOM_REGION:
{ {
int Viewport[4] = int Viewport[4] = { 0, 0, m_ActiveView->GetWidth(), m_ActiveView->GetHeight() };
{
(int)(viewports[m_nViewportMode].dim[m_nActiveViewport][0] * (float)m_nViewX),
(int)(viewports[m_nViewportMode].dim[m_nActiveViewport][1] * (float)m_nViewY),
(int)(viewports[m_nViewportMode].dim[m_nActiveViewport][2] * (float)m_nViewX),
(int)(viewports[m_nViewportMode].dim[m_nActiveViewport][3] * (float)m_nViewY)
};
float Aspect = (float)Viewport[2]/(float)Viewport[3]; float Aspect = (float)Viewport[2]/(float)Viewport[3];
Camera* Cam = m_pViewCameras[m_nActiveViewport]; Camera* Cam = m_pViewCameras[m_nActiveViewport];
@ -7577,9 +7560,6 @@ void Project::BeginColorDrop()
void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bShift) void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bShift)
{ {
GLdouble modelMatrix[16], projMatrix[16], point[3];
GLint viewport[4];
if (m_nTracking != LC_TRACK_NONE) if (m_nTracking != LC_TRACK_NONE)
if (StopTracking(false)) if (StopTracking(false))
return; return;
@ -7593,13 +7573,16 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
m_MouseTotalDelta = Vector3(0, 0, 0); m_MouseTotalDelta = Vector3(0, 0, 0);
m_MouseSnapLeftover = Vector3(0, 0, 0); m_MouseSnapLeftover = Vector3(0, 0, 0);
LoadViewportProjection(m_nActiveViewport); int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); float Aspect = (float)Viewport[2]/(float)Viewport[3];
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); Camera* Cam = m_pViewCameras[m_nActiveViewport];
glGetIntegerv(GL_VIEWPORT, viewport);
gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); Matrix44 ModelView, Projection;
m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
Vector3 point = UnprojectPoint(Vector3((float)x, (float)y, 0.9f), ModelView, Projection, Viewport);
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
if (Sys_KeyDown(KEY_ALT)) if (Sys_KeyDown(KEY_ALT))
{ {
@ -7613,18 +7596,17 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
case LC_ACTION_ERASER: case LC_ACTION_ERASER:
case LC_ACTION_PAINT: case LC_ACTION_PAINT:
{ {
LC_CLICKLINE ClickLine; Object* Closest = FindObjectFromPoint(view, x, y);
FindObjectFromPoint (x, y, &ClickLine);
if (m_nCurAction == LC_ACTION_SELECT) if (m_nCurAction == LC_ACTION_SELECT)
{ {
if (ClickLine.pClosest != NULL) if (Closest != NULL)
{ {
switch (ClickLine.pClosest->GetType ()) switch (Closest->GetType ())
{ {
case LC_OBJECT_PIECE: case LC_OBJECT_PIECE:
{ {
Piece* pPiece = (Piece*)ClickLine.pClosest; Piece* pPiece = (Piece*)Closest;
Group* pGroup = pPiece->GetTopGroup(); Group* pGroup = pPiece->GetTopGroup();
bool bFocus = pPiece->IsFocused (); bool bFocus = pPiece->IsFocused ();
@ -7645,7 +7627,7 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
case LC_OBJECT_LIGHT_TARGET: case LC_OBJECT_LIGHT_TARGET:
{ {
SelectAndFocusNone (bControl); SelectAndFocusNone (bControl);
ClickLine.pClosest->Select (true, true, bControl); Closest->Select (true, true, bControl);
} break; } break;
} }
} }
@ -7654,18 +7636,18 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
UpdateSelection(); UpdateSelection();
UpdateAllViews(); UpdateAllViews();
SystemUpdateFocus(ClickLine.pClosest); SystemUpdateFocus(Closest);
StartTracking(LC_TRACK_START_LEFT); StartTracking(LC_TRACK_START_LEFT);
} }
if ((m_nCurAction == LC_ACTION_ERASER) && (ClickLine.pClosest != NULL)) if ((m_nCurAction == LC_ACTION_ERASER) && (Closest != NULL))
{ {
switch (ClickLine.pClosest->GetType ()) switch (Closest->GetType ())
{ {
case LC_OBJECT_PIECE: case LC_OBJECT_PIECE:
{ {
Piece* pPiece = (Piece*)ClickLine.pClosest; Piece* pPiece = (Piece*)Closest;
RemovePiece(pPiece); RemovePiece(pPiece);
delete pPiece; delete pPiece;
// CalculateStep(); // CalculateStep();
@ -7676,10 +7658,10 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
case LC_OBJECT_CAMERA_TARGET: case LC_OBJECT_CAMERA_TARGET:
{ {
Camera* pCamera; Camera* pCamera;
if (ClickLine.pClosest->GetType () == LC_OBJECT_CAMERA) if (Closest->GetType () == LC_OBJECT_CAMERA)
pCamera = (Camera*)ClickLine.pClosest; pCamera = (Camera*)Closest;
else else
pCamera = ((CameraTarget*)ClickLine.pClosest)->GetParent(); pCamera = ((CameraTarget*)Closest)->GetParent();
bool bCanDelete = pCamera->IsUser(); bool bCanDelete = pCamera->IsUser();
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@ -7717,10 +7699,9 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
// AfxGetMainWnd()->PostMessage(WM_LC_UPDATE_INFO, NULL, OT_PIECE); // AfxGetMainWnd()->PostMessage(WM_LC_UPDATE_INFO, NULL, OT_PIECE);
} }
if ((m_nCurAction == LC_ACTION_PAINT) && (ClickLine.pClosest != NULL) && if ((m_nCurAction == LC_ACTION_PAINT) && (Closest != NULL) && (Closest->GetType() == LC_OBJECT_PIECE))
(ClickLine.pClosest->GetType() == LC_OBJECT_PIECE))
{ {
Piece* pPiece = (Piece*)ClickLine.pClosest; Piece* pPiece = (Piece*)Closest;
if (pPiece->GetColor() != m_nCurColor) if (pPiece->GetColor() != m_nCurColor)
{ {
@ -7811,11 +7792,10 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
if (count == max) if (count == max)
break; break;
double tmp[3]; Vector3 tmp = UnprojectPoint(Vector3(x+1.0f, y-1.0f, 0.9f), ModelView, Projection, Viewport);
gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]);
SelectAndFocusNone(false); SelectAndFocusNone(false);
StartTracking(LC_TRACK_START_LEFT); StartTracking(LC_TRACK_START_LEFT);
pLight = new Light (m_fTrack[0], m_fTrack[1], m_fTrack[2], (float)tmp[0], (float)tmp[1], (float)tmp[2]); pLight = new Light (m_fTrack[0], m_fTrack[1], m_fTrack[2], tmp[0], tmp[1], tmp[2]);
pLight->GetTarget ()->Select (true, true, false); pLight->GetTarget ()->Select (true, true, false);
pLight->m_pNext = m_pLights; pLight->m_pNext = m_pLights;
m_pLights = pLight; m_pLights = pLight;
@ -7826,11 +7806,10 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
case LC_ACTION_CAMERA: case LC_ACTION_CAMERA:
{ {
double tmp[3]; Vector3 tmp = UnprojectPoint(Vector3(x+1.0f, y-1.0f, 0.9f), ModelView, Projection, Viewport);
gluUnProject(x+1, y-1, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]);
SelectAndFocusNone(false); SelectAndFocusNone(false);
StartTracking(LC_TRACK_START_LEFT); StartTracking(LC_TRACK_START_LEFT);
Camera* pCamera = new Camera(m_fTrack[0], m_fTrack[1], m_fTrack[2], (float)tmp[0], (float)tmp[1], (float)tmp[2], m_pCameras); Camera* pCamera = new Camera(m_fTrack[0], m_fTrack[1], m_fTrack[2], tmp[0], tmp[1], tmp[2], m_pCameras);
pCamera->GetTarget ()->Select (true, true, false); pCamera->GetTarget ()->Select (true, true, false);
UpdateSelection(); UpdateSelection();
UpdateAllViews(); UpdateAllViews();
@ -7917,34 +7896,32 @@ void Project::OnLeftButtonDown(View* view, int x, int y, bool bControl, bool bSh
void Project::OnLeftButtonDoubleClick(View* view, int x, int y, bool bControl, bool bShift) void Project::OnLeftButtonDoubleClick(View* view, int x, int y, bool bControl, bool bShift)
{ {
GLdouble modelMatrix[16], projMatrix[16], point[3];
GLint viewport[4];
if (SetActiveView(view)) if (SetActiveView(view))
return; return;
LoadViewportProjection(m_nActiveViewport); int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
glGetDoublev (GL_MODELVIEW_MATRIX, modelMatrix); float Aspect = (float)Viewport[2]/(float)Viewport[3];
glGetDoublev (GL_PROJECTION_MATRIX, projMatrix); Camera* Cam = m_pViewCameras[m_nActiveViewport];
glGetIntegerv (GL_VIEWPORT, viewport);
// why this is here ? Matrix44 ModelView, Projection;
gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
LC_CLICKLINE ClickLine; Vector3 point = UnprojectPoint(Vector3((float)x, (float)y, 0.9f), ModelView, Projection, Viewport);
FindObjectFromPoint (x, y, &ClickLine); m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
Object* Closest = FindObjectFromPoint(view, x, y);
// if (m_nCurAction == LC_ACTION_SELECT) // if (m_nCurAction == LC_ACTION_SELECT)
{ {
SelectAndFocusNone(bControl); SelectAndFocusNone(bControl);
if (ClickLine.pClosest != NULL) if (Closest != NULL)
switch (ClickLine.pClosest->GetType ()) switch (Closest->GetType ())
{ {
case LC_OBJECT_PIECE: case LC_OBJECT_PIECE:
{ {
Piece* pPiece = (Piece*)ClickLine.pClosest; Piece* pPiece = (Piece*)Closest;
pPiece->Select (true, true, false); pPiece->Select (true, true, false);
Group* pGroup = pPiece->GetTopGroup(); Group* pGroup = pPiece->GetTopGroup();
@ -7959,13 +7936,13 @@ void Project::OnLeftButtonDoubleClick(View* view, int x, int y, bool bControl, b
case LC_OBJECT_LIGHT: case LC_OBJECT_LIGHT:
case LC_OBJECT_LIGHT_TARGET: case LC_OBJECT_LIGHT_TARGET:
{ {
ClickLine.pClosest->Select (true, true, bControl); Closest->Select (true, true, bControl);
} break; } break;
} }
UpdateSelection(); UpdateSelection();
UpdateAllViews(); UpdateAllViews();
SystemUpdateFocus(ClickLine.pClosest); SystemUpdateFocus(Closest);
} }
} }
@ -8017,9 +7994,6 @@ void Project::OnLeftButtonUp(View* view, int x, int y, bool bControl, bool bShif
void Project::OnMiddleButtonDown(View* view, int x, int y, bool bControl, bool bShift) void Project::OnMiddleButtonDown(View* view, int x, int y, bool bControl, bool bShift)
{ {
GLdouble modelMatrix[16], projMatrix[16], point[3];
GLint viewport[4];
if (StopTracking(false)) if (StopTracking(false))
return; return;
@ -8030,13 +8004,16 @@ void Project::OnMiddleButtonDown(View* view, int x, int y, bool bControl, bool b
m_nDownY = y; m_nDownY = y;
m_bTrackCancel = false; m_bTrackCancel = false;
LoadViewportProjection(m_nActiveViewport); int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); float Aspect = (float)Viewport[2]/(float)Viewport[3];
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); Camera* Cam = m_pViewCameras[m_nActiveViewport];
glGetIntegerv(GL_VIEWPORT, viewport);
gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); Matrix44 ModelView, Projection;
m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
Vector3 point = UnprojectPoint(Vector3((float)x, (float)y, 0.9f), ModelView, Projection, Viewport);
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
if (Sys_KeyDown(KEY_ALT)) if (Sys_KeyDown(KEY_ALT))
{ {
@ -8060,9 +8037,6 @@ void Project::OnMiddleButtonUp(View* view, int x, int y, bool bControl, bool bSh
void Project::OnRightButtonDown(View* view, int x, int y, bool bControl, bool bShift) void Project::OnRightButtonDown(View* view, int x, int y, bool bControl, bool bShift)
{ {
GLdouble modelMatrix[16], projMatrix[16], point[3];
GLint viewport[4];
if (StopTracking(false)) if (StopTracking(false))
return; return;
@ -8073,13 +8047,16 @@ void Project::OnRightButtonDown(View* view, int x, int y, bool bControl, bool bS
m_nDownY = y; m_nDownY = y;
m_bTrackCancel = false; m_bTrackCancel = false;
LoadViewportProjection(m_nActiveViewport); int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); float Aspect = (float)Viewport[2]/(float)Viewport[3];
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); Camera* Cam = m_pViewCameras[m_nActiveViewport];
glGetIntegerv(GL_VIEWPORT, viewport);
gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &point[0], &point[1], &point[2]); Matrix44 ModelView, Projection;
m_fTrack[0] = (float)point[0]; m_fTrack[1] = (float)point[1]; m_fTrack[2] = (float)point[2]; ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
Vector3 point = UnprojectPoint(Vector3((float)x, (float)y, 0.9f), ModelView, Projection, Viewport);
m_fTrack[0] = point[0]; m_fTrack[1] = point[1]; m_fTrack[2] = point[2];
if (Sys_KeyDown(KEY_ALT)) if (Sys_KeyDown(KEY_ALT))
{ {
@ -8168,17 +8145,18 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
if (m_nTracking == LC_TRACK_START_LEFT) if (m_nTracking == LC_TRACK_START_LEFT)
m_nTracking = LC_TRACK_LEFT; m_nTracking = LC_TRACK_LEFT;
GLdouble modelMatrix[16], projMatrix[16], tmp[3];
GLint viewport[4];
float ptx, pty, ptz; float ptx, pty, ptz;
LoadViewportProjection(m_nActiveViewport); int Viewport[4] = { 0, 0, view->GetWidth(), view->GetHeight() };
glGetDoublev(GL_MODELVIEW_MATRIX, modelMatrix); float Aspect = (float)Viewport[2]/(float)Viewport[3];
glGetDoublev(GL_PROJECTION_MATRIX, projMatrix); Camera* Cam = m_pViewCameras[m_nActiveViewport];
glGetIntegerv(GL_VIEWPORT, viewport);
gluUnProject(x, y, 0.9, modelMatrix, projMatrix, viewport, &tmp[0], &tmp[1], &tmp[2]); Matrix44 ModelView, Projection;
ptx = (float)tmp[0]; pty = (float)tmp[1]; ptz = (float)tmp[2]; ModelView.CreateLookAt(Cam->GetEyePosition(), Cam->GetTargetPosition(), Cam->GetUpVector());
Projection.CreatePerspective(Cam->m_fovy, Aspect, Cam->m_zNear, Cam->m_zFar);
Vector3 tmp = UnprojectPoint(Vector3((float)x, (float)y, 0.9f), ModelView, Projection, Viewport);
ptx = tmp[0]; pty = tmp[1]; ptz = tmp[2];
switch (m_nCurAction) switch (m_nCurAction)
{ {
@ -8186,15 +8164,15 @@ void Project::OnMouseMove(View* view, int x, int y, bool bControl, bool bShift)
{ {
int ptx = x, pty = y; int ptx = x, pty = y;
if (ptx >= viewport[0] + viewport[2]) if (ptx >= Viewport[0] + Viewport[2])
ptx = viewport[0] + viewport[2] - 1; ptx = Viewport[0] + Viewport[2] - 1;
else if (ptx <= viewport[0]) else if (ptx <= Viewport[0])
ptx = viewport[0] + 1; ptx = Viewport[0] + 1;
if (pty >= viewport[1] + viewport[3]) if (pty >= Viewport[1] + Viewport[3])
pty = viewport[1] + viewport[3] - 1; pty = Viewport[1] + Viewport[3] - 1;
else if (pty <= viewport[1]) else if (pty <= Viewport[1])
pty = viewport[1] + 1; pty = Viewport[1] + 1;
m_fTrack[0] = (float)ptx; m_fTrack[0] = (float)ptx;
m_fTrack[1] = (float)pty; m_fTrack[1] = (float)pty;

View file

@ -174,7 +174,7 @@ protected:
bool RemoveSelectedObjects(); bool RemoveSelectedObjects();
void GetPieceInsertPosition(Piece* OffsetPiece, Vector3& Position, Vector4& Rotation); void GetPieceInsertPosition(Piece* OffsetPiece, Vector3& Position, Vector4& Rotation);
void GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Orientation); void GetPieceInsertPosition(View* view, int MouseX, int MouseY, Vector3& Position, Vector4& Orientation);
void FindObjectFromPoint(int x, int y, LC_CLICKLINE* pLine, bool PiecesOnly = false); Object* FindObjectFromPoint(View* view, int x, int y, bool PiecesOnly = false);
void FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects); void FindObjectsInBox(float x1, float y1, float x2, float y2, PtrArray<Object>& Objects);
void SelectAndFocusNone(bool bFocusOnly); void SelectAndFocusNone(bool bFocusOnly);
void GetActiveViewportMatrices(Matrix44& ModelView, Matrix44& Projection, int Viewport[4]); void GetActiveViewportMatrices(Matrix44& ModelView, Matrix44& Projection, int Viewport[4]);
@ -191,7 +191,7 @@ protected:
void SnapVector(Vector3& Delta, Vector3& Leftover) const; void SnapVector(Vector3& Delta, Vector3& Leftover) const;
void SnapRotationVector(Vector3& Delta, Vector3& Leftover) const; void SnapRotationVector(Vector3& Delta, Vector3& Leftover) const;
// Rendering // Rendering functions.
void RenderBackground(View* view); void RenderBackground(View* view);
void RenderScenePieces(View* view); void RenderScenePieces(View* view);
void RenderSceneBoxes(View* view); void RenderSceneBoxes(View* view);