OpenVDB: nanovdb/examples/benchmark/Camera.h Source File

OpenVDB 10.0.1

Loading...
Searching...
No Matches
Camera.h
Go to the documentation of this file.
1// Copyright Contributors to the OpenVDB Project
2// SPDX-License-Identifier: MPL-2.0
3
4/// @file Camera.h
5///
6/// @author Ken Museth
7///
8/// @brief A simple camera class.
9
10#ifndef NANOVDB_CAMERA_H_HAS_BEEN_INCLUDED
11#define NANOVDB_CAMERA_H_HAS_BEEN_INCLUDED
12
13#include <nanovdb/NanoVDB.h> // for Vec3
14#include <nanovdb/util/Ray.h>
15
16namespace nanovdb {
17
18/// @brief A minimal perspective camera for ray generation
19template<typename RealT = float, typename Vec3T = Vec3<RealT>, typename RayT = Ray<RealT>>
20 class Camera
21{
22 Vec3T mEye, mW, mU, mV;
23
24 __hostdev__ void init(RealT vfov, RealT aspect)
25 {
26 const RealT halfHeight = RealT(tan(vfov * 3.14159265358979323846 / 360));
27 const RealT halfWidth = aspect * halfHeight;
28 mW = halfWidth * mU + halfHeight * mV + mW; // remove eye here and in getRay
29 mU *= 2 * halfWidth;
30 mV *= 2 * halfHeight;
31 }
32
33public:
34 /// @brief default Ctor.
35 Camera() = default;
36
37 /// @brief Ctor. // vfov is top to bottom in degrees
38 /// @note up is assumed to be a unit-vector
39 __hostdev__ Camera(const Vec3T& eye, const Vec3T& lookat, const Vec3T& up, RealT vfov, RealT aspect)
40 : mEye(eye)
41 , mW((eye - lookat).normalize())
42 , mU(up.cross(mW))
43 , mV(up)
44 {
45 this->init(vfov, aspect);
46 }
47 __hostdev__ void update(const Vec3T& eye, const Vec3T& lookat, const Vec3T& up, RealT vfov, RealT aspect)
48 {
49 mEye = eye;
50 mV = up;
51 mW = mEye - lookat;
52 mW.normalize();
53 mU = mV.cross(mW);
54 this->init(vfov, aspect);
55 }
56 /// @brief {u,v} are are assumed to be [0,1]
57 __hostdev__ RayT getRay(RealT u, RealT v) const {
58 auto dir = u * mU + v * mV - mW;
59 dir.normalize();
60 return RayT(mEye, dir);
61 }
62
63 __hostdev__ const Vec3T& P() const { return mEye; }
64 __hostdev__ const Vec3T& U() const { return mU; }
65 __hostdev__ const Vec3T& V() const { return mV; }
66 __hostdev__ const Vec3T& W() const { return mW; }
67
68}; // Camera
69
70} // namespace nanovdb
71
72#endif // NANOVDB_CAMERA_HAS_BEEN_INCLUDED
NanoVDB.h
Implements a light-weight self-contained VDB data-structure in a single file! In other words,...
__hostdev__
#define __hostdev__
Definition NanoVDB.h:192
nanovdb::Camera
A minimal perspective camera for ray generation.
Definition Camera.h:21
nanovdb::Camera::Camera
Camera()=default
default Ctor.
nanovdb::Camera::U
__hostdev__ const Vec3T & U() const
Definition Camera.h:64
nanovdb::Camera::Camera
__hostdev__ Camera(const Vec3T &eye, const Vec3T &lookat, const Vec3T &up, RealT vfov, RealT aspect)
Ctor. // vfov is top to bottom in degrees.
Definition Camera.h:39
nanovdb::Camera::P
__hostdev__ const Vec3T & P() const
Definition Camera.h:63
nanovdb::Camera::getRay
__hostdev__ RayT getRay(RealT u, RealT v) const
{u,v} are are assumed to be [0,1]
Definition Camera.h:57
nanovdb::Camera::V
__hostdev__ const Vec3T & V() const
Definition Camera.h:65
nanovdb::Camera::update
__hostdev__ void update(const Vec3T &eye, const Vec3T &lookat, const Vec3T &up, RealT vfov, RealT aspect)
Definition Camera.h:47
nanovdb::Camera::W
__hostdev__ const Vec3T & W() const
Definition Camera.h:66
nanovdb
Definition NanoVDB.h:208
Ray.h
A Ray class.