#Error
69 messages · Page 1 of 1 (latest)
When your question is answered use !solved to mark the question as resolved.
Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.
#ifndef CAMERA_H
#define CAMERA_H
#include "rtweekend.h"
#include "color.h"
#include "hittable.h"
#include <iostream>
class camera {
public:
double aspect_ratio = 1.0; // Ratio of image width over height
int image_width = 100; // Rendered image width in pixel count
int samples_per_pixel = 10; // Count of random samples for each pixel
void render(const hittable& world) {
initialize();
std::cout << "P3\n" << image_width << ' ' << image_height << "\n255\n";
for (int j = 0; j < image_height; ++j) {
std::clog << "\rScanlines remaining: " << (image_height - j) << ' ' << std::flush;
for (int i = 0; i < image_width; ++i) {
color pixel_color(0, 0, 0);
for (int sample = 0; sample < samples_per_pixel; ++sample) {
ray r = get_ray(i, j);
pixel_color += ray_color(r, world);
}
write_color(std::cout, pixel_color, samples_per_pixel);
}
}
std::clog << "\rDone. \n";
}
my code
does anyone know why im getting this error?
im following a guide and copied and pasted everything but i dont know why i got this error
#include "rtweekend.h"
#include "camera.h"
#include "hittable_list.h"
#include "sphere.h"
color ray_color(const ray& r, const hittable& world) {
hit_record rec;
if (world.hit(r, 0, infinity, rec)) {
return 0.5 * (rec.normal + color(1, 1, 1));
}
vec3 unit_direction = unit_vector(r.direction());
auto a = 0.5 * (unit_direction.y() + 1.0);
return (1.0 - a) * color(1.0, 1.0, 1.0) + a * color(0.5, 0.7, 1.0);
}
int main() {
hittable_list world;
world.add(make_shared<sphere>(point3(0, 0, -1), 0.5));
world.add(make_shared<sphere>(point3(0, -100.5, -1), 100));
camera cam;
cam.aspect_ratio = 16.0 / 9.0;
cam.image_width = 400;
cam.samples_per_pixel = 100;
cam.render(world);
}
im a beginner so i dont know what is going on here.
Is this a simple fix?
Your source files have circular dependencies: color.h includes camera.h, and camera.h includes color.h. I think you need to remove the #include "camera.h" line in "color.h"
that's assuming this is color.h
I saw you have main() defined there, so I guess that's the main file? If so, just move ray_color definition to color.h or camera.h
this is main.ccp
ok, you need to have the definition of ray_color() ready before you can use it. So you need to move it to somewhere that camera.h includes
could you show me how
put
color ray_color(const ray& r, const hittable& world) { ... } just before
class camera { public: ... }
should do the trick.
i made a bit of an error. it was supposed to be in camera.h
It works now?
Did you implement all the abstract method in Sphere?
in sphere.h?
every purely abstract method of Hittable need to be defined(implemented) in class Sphere
this what i done
can I see the definition of class Hittable?
you only implemented the second abstract method. The first one need to be defined too
the one that takes ray_tmin and ray_tmax
i implement it in sphere.h
so, does it compile now?
No, can I see the definition of class interval?
try: ```
return hit(r, interval{ray_tmin, ray_tmax}, rec);
just this one line inside your second hit method
it reuses the first one.
replace your current definition of the second hit with this one ⤴️ .
bool hit(const ray& r, double ray_tmin, double ray_tmax, hit_record& rec) const override {
return hit(r, interval{ray_tmin, ray_tmax}, rec);
}
just keep that one line
Wait, you should put this in class Sphere, not hittable_list
right. Keep that one line, delete the rest lines in the method.
like this
exactly
what do i do about the other error that popped up?
You defined the constructor of Sphere again, just above method hit, delete it.
ok i done it and now it runs
wow it runs perfectly
since it is a bit different, do you think it'll affect my code?
also thank you, you were very helpful
@marsh fable Has your question been resolved? If so, type !solved :)
!solved
Thank you and let us know if you have any more questions!
This thread is now set to auto-hide after an hour of inactivity
I think what's important is to understand the book's content, not just try to copy the code exactly. If you understand the thoery, you won't be afraid of being different from the book.
Also I don’t know too much about c++ syntax
do you recommend anything for me to read to get better?