-/* $Id$
-
-This file is part of the MSP Märklin suite
-Copyright © 2010 Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
#include <cmath>
#include <msp/input/keys.h>
+#include "3d/layout.h"
#include "cameracontroller.h"
-#include "designer.h"
using namespace std;
using namespace Msp;
-using namespace Marklin;
+using namespace R2C2;
-CameraController::CameraController(Designer &d, Graphics::EventSource &es, GL::Camera &c):
- designer(d),
+CameraController::CameraController(View3D &v, Graphics::EventSource &es):
+ view(v),
event_source(es),
- camera(c),
+ camera(view.get_camera()),
move_x(0),
move_y(0),
drag_mode(NONE)
void CameraController::view_all()
{
- Point minp;
- Point maxp;
-
- const Layout3D::TrackMap &tracks = designer.get_layout_3d().get_tracks();
- for(Layout3D::TrackMap::const_iterator i=tracks.begin(); i!=tracks.end(); ++i)
- {
- Point tmin;
- Point tmax;
- i->second->get_bounds(0, tmin, tmax);
- minp.x = min(minp.x, tmin.x);
- minp.y = min(minp.y, tmin.y);
- maxp.x = max(maxp.x, tmax.x);
- maxp.y = max(maxp.y, tmax.y);
- }
-
- float t = tan(camera.get_field_of_view()/2)*2;
- float size = max((maxp.y-minp.y+0.1), (maxp.x-minp.x+0.1)/camera.get_aspect());
- float dist = size/t+size*0.25;
- GL::Vector3 center((minp.x+maxp.x)/2, (minp.y+maxp.y)/2, 0);
- const GL::Vector3 &look = camera.get_look_direction();
- camera.set_position(GL::Vector3(center.x-look.x*dist, center.y-look.y*dist, center.z-look.z*dist));
+ view.view_all();
}
void CameraController::move(float x, float y)
{
const GL::Vector3 &pos = camera.get_position();
const GL::Vector3 &look = camera.get_look_direction();
+ float dist = get_distance();
+ float low = view.get_layout().get_layout().get_catalogue().get_gauge()*5;
+ if(dist+delta<low)
+ delta = low-dist;
camera.set_position(GL::Vector3(pos.x-look.x*delta, pos.y-look.y*delta, pos.z-look.z*delta));
+ dist += delta;
+ camera.set_depth_clip(dist*0.02, dist*50);
}
void CameraController::rotate(float angle)