-
Notifications
You must be signed in to change notification settings - Fork 46
/
OSPRayCamera.cpp
86 lines (76 loc) · 2.92 KB
/
OSPRayCamera.cpp
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* Copyright (c) 2015-2016, EPFL/Blue Brain Project
* All rights reserved. Do not distribute without permission.
* Responsible Author: Cyrille Favreau <cyrille.favreau@epfl.ch>
*
* This file is part of Brayns <https://github.com/BlueBrain/Brayns>
*
* This library is free software; you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License version 3.0 as published
* by the Free Software Foundation.
*
* This library is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
* details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this library; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "OSPRayCamera.h"
#include <brayns/common/log.h>
#include <brayns/parameters/ParametersManager.h>
#include <ospray/SDK/common/OSPCommon.h>
namespace brayns
{
OSPRayCamera::OSPRayCamera(const CameraType& type, const std::string& name)
: Camera(type)
, _camera{ospNewCamera(name.c_str())}
{
if (!_camera)
throw std::runtime_error(name + " is not a registered camera");
}
OSPRayCamera::~OSPRayCamera()
{
ospRelease(_camera);
}
void OSPRayCamera::commit()
{
if (!getModified())
return;
const auto& position = getPosition();
const auto& target = getTarget();
const auto dir = normalize(target - position);
const auto& up = getUp();
ospSet3f(_camera, "pos", position.x(), position.y(), position.z());
ospSet3f(_camera, "dir", dir.x(), dir.y(), dir.z());
ospSet3f(_camera, "up", up.x(), up.y(), up.z());
ospSet1f(_camera, "aspect", getAspectRatio());
ospSet1f(_camera, "apertureRadius", getAperture());
ospSet1f(_camera, "focusDistance", getFocalLength());
ospSet1i(_camera, "stereoMode", static_cast<uint>(getStereoMode()));
ospSet1f(_camera, "interpupillaryDistance", getEyeSeparation());
ospSet1f(_camera, "fovy", getFieldOfView());
ospSet1f(_camera, "architectural", true);
// Clip planes
const auto& clipPlanes = getClipPlanes();
if (clipPlanes.size() == 6)
{
const std::string clipPlaneNames[6] = {"clipPlane1", "clipPlane2",
"clipPlane3", "clipPlane4",
"clipPlane5", "clipPlane6"};
for (size_t i = 0; i < clipPlanes.size(); ++i)
{
const auto& clipPlane = clipPlanes[i];
ospSet4f(_camera, clipPlaneNames[i].c_str(), clipPlane.x(),
clipPlane.y(), clipPlane.z(), clipPlane.w());
}
}
ospCommit(_camera);
}
void OSPRayCamera::setEnvironmentMap(const bool environmentMap)
{
ospSet1i(_camera, "environmentMap", environmentMap);
ospCommit(_camera);
}
}