-
Notifications
You must be signed in to change notification settings - Fork 0
/
SphereMap.cpp
62 lines (42 loc) · 1.54 KB
/
SphereMap.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
#include "SphereMap.h"
// ---------------------------------------------------------------- default constructor
SphereMap::SphereMap(void) {}
// ---------------------------------------------------------------- copy constructor
SphereMap::SphereMap(const SphereMap &sm) {}
// ---------------------------------------------------------------- assignment operator
SphereMap &
SphereMap::operator=(const SphereMap &rhs)
{
if (this == &rhs)
return (*this);
return (*this);
}
// ---------------------------------------------------------------- destructor
SphereMap::~SphereMap(void) {}
// ---------------------------------------------------------------- clone
SphereMap *
SphereMap::clone(void) const
{
return (new SphereMap(*this));
}
// ---------------------------------------------------------------- get_texel_coordinates
// Given a hit point on a generic sphere, and the image resolution, this function
// returns the texel coordinates in the image
void SphereMap::get_texel_coordinates(const Point3D &local_hit_point,
const int xres,
const int yres,
int &row,
int &column) const
{
// first, compute theta and phi
float theta = acos(local_hit_point.y);
float phi = atan2(local_hit_point.x, local_hit_point.z);
if (phi < 0.0)
phi += TWO_PI;
// next, map theta and phi to (u, v) in [0, 1] X [0, 1]
float u = phi * invTWO_PI;
float v = 1.0 - theta * invPI;
// finally, map u and v to the texel coordinates
column = (int)((xres - 1) * u); // column is across
row = (int)((yres - 1) * v); // row is up
}