HMDCamera.hh 2.47 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/***********************************************************************
 * Copyright 2011-2013 Computer Graphics Group RWTH Aachen University. *
 * All rights reserved.                                                *
 * Distributed under the terms of the MIT License (see LICENSE.TXT).   *
 **********************************************************************/
#pragma once

/**
 * This camera class extends the GenericCamera to better support a
 * HeadMountedDisplay.
 *
 * The usual GenericCamera API controls the position and orientation
 * of the *neck* of the camera while the added API add a head rotation
 * and an offset of the neck to the eyes.
 * These additional values should be set by the HMD hardware.
 *
 * The projection matrix can also handle an offset applied from the *left*
 * to the projection matrix from the GenericCamera. This is needed for
 * some HMDs.
 *
 */

#include <ACGL/ACGL.hh>
#include <ACGL/Scene/GenericCamera.hh>

namespace ACGL{
namespace Scene{

class HMDCamera : public GenericCamera
{
public:

    HMDCamera();
    virtual ~HMDCamera() {}

    //! View plus the neck transformation
    virtual glm::mat4 getViewMatrix() const;

    //! projection of the current eye translated by the projection center offset
    virtual glm::mat4 getProjectionMatrix() const;

    //! projection offset for the left eye, the right eye will mult the X component with -1
    void setProjectionCenterOffset( const glm::vec2 &_projectionCenterOffset );

    /*
     * o = eye
     * x = neck == point of rotation
     *
     *   |---| <- mNeckToEyeHorizontalDistance
     *
     *  /----\
     *  |o   | ---
     *  |    |  |  <- mNeckToEyeVerticalDistance
     *  \__  |  |
     *     |x| ---
     */
    void setNeckToEyeVerticalDistance( float _f );
    void setNeckToEyeHorizontalDistance( float _f );

    void setHMDRotation( const glm::mat3 &_rotation );

62
63
64
65
    void  setEyeHeight( float _eyeHeight) { if (_eyeHeight>0.0f) mEyeHeight = _eyeHeight; }
    float getEyeHeight() { return mEyeHeight; }


66
67
68
69
70
71
72
73
74
75
76
77
private:
    //! stored as a translation vector
    glm::vec2 mProjectionCenterOffset;

    //! height of the eyes above the neck, just height difference in meters
    float mNeckToEyeVerticalDistance;

    //! distance eyes to neck without the height in meters
    float mNeckToEyeHorizontalDistance;

    //! rotation of the HMD
    glm::mat4 mHMDRotation;
78
79
80

    //! distance floor to eyes in meters (player height is a few cm more)
    float mEyeHeight;
81
82
83
84
85
};
ACGL_SMARTPOINTER_TYPEDEFS(HMDCamera)

}
}