#Error

69 messages · Page 1 of 1 (latest)

marsh fable
#

whats causing this error?

steel coralBOT
#

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.

marsh fable
#
#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

marsh fable
#

does anyone know why im getting this error?

marsh fable
#

im following a guide and copied and pasted everything but i dont know why i got this error

marsh fable
#
#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.

marsh fable
#

Is this a simple fix?

wintry storm
#

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"

wintry storm
#

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

wintry storm
#

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

marsh fable
#

could you show me how

wintry storm
#

put
color ray_color(const ray& r, const hittable& world) { ... } just before
class camera { public: ... }
should do the trick.

marsh fable
#

i made a bit of an error. it was supposed to be in camera.h

wintry storm
#

It works now?

marsh fable
#

no. there is another error

#

let me just check and ill show you

wintry storm
#

Did you implement all the abstract method in Sphere?

marsh fable
#

in sphere.h?

wintry storm
#

in class Sphere

#

it's derived from Hittable?

marsh fable
#

yeah

#

let me check on sphere

wintry storm
#

every purely abstract method of Hittable need to be defined(implemented) in class Sphere

marsh fable
#

this what i done

wintry storm
#

can I see the definition of class Hittable?

marsh fable
wintry storm
#

you only implemented the second abstract method. The first one need to be defined too

#

the one that takes ray_tmin and ray_tmax

marsh fable
#

i implement it in sphere.h

wintry storm
#

so, does it compile now?

marsh fable
#

is what i did so far correct?

#

is this how i implement it @wintry storm ?

wintry storm
#

No, can I see the definition of class interval?

marsh fable
wintry storm
#

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 ⤴️ .

marsh fable
#

i have no idea what you're saying

#

sorry

#

i dont know what a hit method is

wintry storm
#
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);
}
marsh fable
wintry storm
#

just keep that one line

marsh fable
#

ok

#

i still have the same error though

wintry storm
#

Wait, you should put this in class Sphere, not hittable_list

marsh fable
#

ok ill switch it

wintry storm
#

right. Keep that one line, delete the rest lines in the method.

marsh fable
#

like this

wintry storm
#

exactly

marsh fable
#

what do i do about the other error that popped up?

wintry storm
#

You defined the constructor of Sphere again, just above method hit, delete it.

marsh fable
#

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

steel coralBOT
#

@marsh fable Has your question been resolved? If so, type !solved :)

marsh fable
#

!solved

steel coralBOT
#

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

wintry storm
#

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.

marsh fable
#

do you recommend anything for me to read to get better?