Trying to implement image mapping.

Something not working yet.
This commit is contained in:
Godzil
2020-03-05 09:48:37 +00:00
parent d6ae062f7f
commit 6a2c5a77ae
5 changed files with 132 additions and 0 deletions

View File

@@ -68,3 +68,10 @@ bool Canvas::SaveAsPNG(const char *filename)
return ret == 0;
}
Canvas::Canvas(const char *pngfile)
{
uint32_t ret = lodepng_decode24_file(&this->bitmap, &this->width, &this->height, pngfile);
if(ret){ printf("error %u: %s\n", ret, lodepng_error_text(ret));}
printf("%p - %d - %d\n", this->bitmap, this->width, this->height);
}

View File

@@ -23,6 +23,8 @@ public:
Canvas(uint32_t width, uint32_t height);
Canvas(const Canvas *c);
Canvas(const Canvas &c);
Canvas(const char *pngfile);
~Canvas();
void putPixel(uint32_t x, uint32_t y, Tuple c);

View File

@@ -0,0 +1,43 @@
/*
* DoRayMe - a quick and dirty Raytracer
* UV Image pattern header
*
* Created by Manoël Trapier
* Copyright (c) 2020 986-Studio.
*
*/
#ifndef DORAYME_UV_IMAGE_H
#define DORAYME_UV_IMAGE_H
#include <stdint.h>
#include <uv_pattern.h>
#include <canvas.h>
#include <tuple.h>
class UVImage : public UVPattern
{
public:
Canvas *image;
UVImage(Canvas *image) : UVPattern(1, 1, Colour(0, 0, 0), Colour(0, 0, 0)),
image(image) {};
UVImage(const char *filepath) : UVPattern(1, 1, Colour(0, 0, 0), Colour(0, 0, 0)) {
this->image = new Canvas(filepath);
this->width = this->image->width;
this->height = this->image->height;
};
Colour uvPatternAt(double u, double v) {
v = 1 - v;
double x = u * (this->image->width/2.0 - 1);
double y = v * (this->image->height/2.0 - 1);
Colour ret = this->image->getPixel(round(x), round(y));
return ret;
};
};
#endif /* DORAYME_UV_IMAGE_H */