Oops, up vector is needed.
authorKahrl <kahrl@gmx.net>
Sun, 18 Sep 2011 00:24:43 +0000 (02:24 +0200)
committerKahrl <kahrl@gmx.net>
Sun, 18 Sep 2011 00:24:43 +0000 (02:24 +0200)
src/camera.cpp

index 0c6fe1df5dff9ffcd6a0050a8074b737f3f789c9..a9497152b44f29d33c1303d7eacbdad116f417a2 100644 (file)
@@ -120,10 +120,12 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
        v3f eye_offset = player->getEyePosition() - player->getPosition();
        m_headnode->setPosition(eye_offset);
        m_headnode->setRotation(v3f(player->getPitch(), 0, 0));
+       m_headnode->updateAbsolutePosition();
 
        // Compute relative camera position and target
        v3f rel_cam_pos = v3f(0,0,0);
        v3f rel_cam_target = v3f(0,0,1);
+       v3f rel_cam_up = v3f(0,1,0);
 
        s32 bobframe = m_view_bobbing_anim & (BOBFRAMES/2-1);
        if (bobframe != 0)
@@ -140,7 +142,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
                        0.);
 
                rel_cam_pos += bobvec * 3.;
-               rel_cam_target += bobvec * 1.5;
+               rel_cam_target += bobvec * 4.5;
        }
 
        // Compute absolute camera position and target
@@ -148,8 +150,13 @@ void Camera::update(LocalPlayer* player, f32 frametime, v2u32 screensize)
        m_headnode->getAbsoluteTransformation().transformVect(m_camera_direction, rel_cam_target);
        m_camera_direction -= m_camera_position;
 
+       v3f abs_cam_up;
+       m_headnode->getAbsoluteTransformation().transformVect(abs_cam_up, rel_cam_pos + rel_cam_up);
+       abs_cam_up -= m_camera_position;
+
        // Set camera node transformation
        m_cameranode->setPosition(m_camera_position);
+       m_cameranode->setUpVector(abs_cam_up);
        m_cameranode->setTarget(m_camera_position + m_camera_direction);
 
        // FOV and and aspect ratio