-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImagePlane.cpp
32 lines (26 loc) · 936 Bytes
/
ImagePlane.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
#include "ImagePlane.h"
ImagePlane::ImagePlane(STPoint3* LL, STPoint3* UL, STPoint3* LR, STPoint3* UR) {
this->LL = LL;
this->UL = UL;
this->LR = LR;
this->UR = UR;
pixels = new Pixel[screenWidth * screenHeight];
}
//imX and imY are like x and y
STPoint3* ImagePlane::imgToWorld(int imX, int imY) {
float xRatio = imX * 1.0 / screenWidth;
float yRatio = imY * 1.0 / screenHeight;
//bilinear interpolation
STPoint3 bottom = *LL * (1 - xRatio) + STVector3(*LR * xRatio);
STPoint3 top = *UL * (1 - xRatio) + STVector3(*UR * xRatio);
return new STPoint3(bottom * (1 - yRatio) + STVector3(top * yRatio));
}
//imX and imY are like rows and columns!
void ImagePlane::setPixel(int imX, int imY, Pixel color) {
pixels[imX * screenWidth + imY] = color;
}
void ImagePlane::writeImage() {
/*STImage* screenshot = new STImage(;
screenshot->Read(0,0);
screenshot->Save("screenshot.jpg");*/
}