HMDCamera.cc 1.98 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
/***********************************************************************
 * Copyright 2011-2013 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/

#include <ACGL/Scene/HMDCamera.hh>

namespace ACGL{
namespace Scene{

HMDCamera::HMDCamera()
{
    setStereoMode( GenericCamera::PARALLEL_SHIFT );
    mNeckToEyeVerticalDistance   = 0.0f;
    mNeckToEyeHorizontalDistance = 0.0f;

    mHMDRotation = glm::mat4(1.0f);
}

void HMDCamera::setProjectionCenterOffset( const glm::vec2 &_projectionCenterOffset )
{
    mProjectionCenterOffset = _projectionCenterOffset;
}

void HMDCamera::setNeckToEyeVerticalDistance( float _f )
{
    mNeckToEyeVerticalDistance = _f;
}

void HMDCamera::setNeckToEyeHorizontalDistance( float _f )
{
    mNeckToEyeHorizontalDistance = _f;
}

void HMDCamera::setHMDRotation( const glm::mat3 &_rotation )
{
Robert Menzel's avatar
Robert Menzel committed
38
39
    //mHMDRotation = glm::mat4( _rotation );
    GenericCamera::setRotationMatrix( _rotation );
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
}


glm::mat4 HMDCamera::getViewMatrix() const
{
    glm::mat4 viewMatrix = GenericCamera::getViewMatrix();

    glm::vec3 up      = -mNeckToEyeVerticalDistance   * glm::normalize( getUpDirection() );
    glm::vec3 forward = -mNeckToEyeHorizontalDistance * glm::normalize( getForwardDirection() );

    glm::mat4 neck = glm::translate( up ) * glm::translate( forward );

    return neck * mHMDRotation * viewMatrix;
}


glm::mat4 HMDCamera::getProjectionMatrix() const
{
    glm::mat4 projectionOffset;
    if (getEye() == GenericCamera::EYE_RIGHT) {
        projectionOffset = glm::translate( -mProjectionCenterOffset.x, mProjectionCenterOffset.y, 0.0f );
    } else {
        projectionOffset = glm::translate(  mProjectionCenterOffset.x, mProjectionCenterOffset.y, 0.0f );
    }
    return projectionOffset * GenericCamera::getProjectionMatrix(); // yes, from the left side!
}


}
}