Allow the camera to follow the ball
But when the ground is not textured, this looks just as if the ball was not moving… :(
This commit is contained in:
parent
baaa5e4057
commit
8051f4203f
3 changed files with 23 additions and 5 deletions
|
@ -52,6 +52,7 @@ int main(int argc, char** argv) {
|
||||||
ground_mesh.get_mesh()->set_color(Color(0.13, 0.82, 0.21));
|
ground_mesh.get_mesh()->set_color(Color(0.13, 0.82, 0.21));
|
||||||
render.add_mesh(ground_mesh.get_mesh());
|
render.add_mesh(ground_mesh.get_mesh());
|
||||||
}
|
}
|
||||||
|
//render.follow_implicit_position(ball.get_surface());
|
||||||
|
|
||||||
render.set_idle_func(periodic_update);
|
render.set_idle_func(periodic_update);
|
||||||
render.add_kb_handler(periodic_kb_handler);
|
render.add_kb_handler(periodic_kb_handler);
|
||||||
|
|
|
@ -12,7 +12,7 @@ GlutRender& GlutRender::get_instance() {
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
GlutRender::GlutRender() {
|
GlutRender::GlutRender() : followed_implicit(nullptr) {
|
||||||
std::default_random_engine rand_engine(time(NULL));
|
std::default_random_engine rand_engine(time(NULL));
|
||||||
std::uniform_real_distribution<double> distribution;
|
std::uniform_real_distribution<double> distribution;
|
||||||
rand_color = std::bind(distribution, rand_engine);
|
rand_color = std::bind(distribution, rand_engine);
|
||||||
|
@ -97,6 +97,10 @@ void GlutRender::add_kb_handler(GlutRender::kb_handler_t handler) {
|
||||||
kb_handlers.push_back(handler);
|
kb_handlers.push_back(handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GlutRender::follow_implicit_position(const ImplicitSurface* surf) {
|
||||||
|
followed_implicit = surf;
|
||||||
|
}
|
||||||
|
|
||||||
void GlutRender::reshape(int wid, int hei) {
|
void GlutRender::reshape(int wid, int hei) {
|
||||||
if (hei == 0)
|
if (hei == 0)
|
||||||
hei = 1;
|
hei = 1;
|
||||||
|
@ -187,10 +191,19 @@ void GlutRender::display() {
|
||||||
|
|
||||||
// Camera position and orientation
|
// Camera position and orientation
|
||||||
glLoadIdentity();
|
glLoadIdentity();
|
||||||
//glTranslatef(1., 2., -10.);
|
|
||||||
gluLookAt(0, 2.5, -10,
|
Point look_from(0, 2.5, -10);
|
||||||
|
if(followed_implicit != nullptr) {
|
||||||
|
const Point& look_at = followed_implicit->getCenter();
|
||||||
|
gluLookAt(look_from.x, look_from.y, look_from.z,
|
||||||
|
look_at.x, look_from.y, look_at.z,
|
||||||
|
0, 1, 0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
gluLookAt(look_from.x, look_from.y, look_from.z,
|
||||||
0, 2.5, 0,
|
0, 2.5, 0,
|
||||||
0, 1, 0);
|
0, 1, 0);
|
||||||
|
}
|
||||||
|
|
||||||
for(Mesh* mesh: meshes) {
|
for(Mesh* mesh: meshes) {
|
||||||
display_mesh(*mesh);
|
display_mesh(*mesh);
|
||||||
|
|
|
@ -30,6 +30,8 @@ class GlutRender {
|
||||||
|
|
||||||
void add_kb_handler(kb_handler_t handler);
|
void add_kb_handler(kb_handler_t handler);
|
||||||
|
|
||||||
|
void follow_implicit_position(const ImplicitSurface* surf);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
struct SurfaceDetails {
|
struct SurfaceDetails {
|
||||||
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box,
|
SurfaceDetails(ImplicitSurface* surf, const Cuboid& box,
|
||||||
|
@ -68,4 +70,6 @@ class GlutRender {
|
||||||
std::set<SurfaceDetails> surfaces;
|
std::set<SurfaceDetails> surfaces;
|
||||||
|
|
||||||
std::vector<kb_handler_t> kb_handlers;
|
std::vector<kb_handler_t> kb_handlers;
|
||||||
|
|
||||||
|
const ImplicitSurface* followed_implicit;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue