-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTexture.cc
56 lines (43 loc) · 1.15 KB
/
Texture.cc
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
#include "Texture.hh"
#include <math.h>
using namespace std;
Vec3f Texture::GetTexel(float u, float v)
{
/* float u_, v_;
u_ = floor(u);
v_ = floor(v);
u_ = u - u_;
v_ = v - v_;
//cout << "[" << u << "," << v << "]" << endl;
int x = (int)(u_ * resX);
int y = (int)(v_ * resY);
*/
int px = max(0, min(int(u*resX), resX - 1));
int py = max(0, min(int(v*resY), resY - 1));
/*
int px = int(resX*u);
int py = int(resY*v);
//esse funciona
px = int(resX + px % resX) % resX;
py = int(resY + py % resY) % resY;
*/
return GetValuePixel(px, py);
}
/*
Vec3f Texture::GetTexel(float u, float v) {
u -= (int)u;
if (u < 0) u += 1;
v -= (int)v;
if (v < 0) v += 1;
return GetValuePixel((int)(u*resX), resY-1-(int)(v*resY));
//return (*this)[resY-1-(int)(v*resY)][(int)(u*resX)];
}
/*Vec3f Texture::GetTexel(float u, float v) {
// compute texel coordinates
// we add 0.5, since the texel is sampled in the middle of the pixel (see OpenGL linear interpolation)
float px = resX * u + 0.5;
float py = resY * v + 0.5;
return GetValuePixel(px,py);
// return new value
//return result;
}*/