Skip to content

Rays not hit nearest object (Sphere)  #4

@WithSJ

Description

@WithSJ

When Objects

Sphere Objects[] = {obj1,obj2};

Screenshot from 2021-05-08 19-30-36

But when I change the order of the list

Sphere Objects[] = {obj2,obj1};

Screenshot from 2021-05-08 19-31-08

Maybe Ray does not find the nearest Sphere. It iterates all objects in a sequence.

[CODE HERE]

#include <iostream>
#include <chrono>

#include "Engine/renderengine.h"

using namespace std::chrono;

int main(int argc, char const *argv[])
{
    /* code */
    // Eclectus Testing 1.0
    auto start = high_resolution_clock::now();

    short int WIDTH = 320;
    short int HEIGHT = 200;
    
    Vector Camera(0,0,-1);
    Color col = Color::from_hex("#ff751a");
    Material material1(col);
    Sphere obj1(Vector(0,0,0),0.3,material1);

    Color col2 = Color::from_hex("#9fff80");
    Material material2(col2);
    Sphere obj2(Vector(0,5,0),5,material2);
    Sphere Objects[] = {obj1,obj2}; 
    
    Color light_col(255,255,255);
    Light point_light(Vector(1.5,-0.5,-3.0),light_col);
    Light Lights[] = {point_light};

    Scene scene(Camera,Objects,2,Lights,1,WIDTH,HEIGHT);

    RenderEngine engine;

    Image img =  engine.render(scene);

    img.write_ppm("Eclectus_test.ppm");

    auto stop = high_resolution_clock::now();
    auto duration = duration_cast<microseconds>(stop - start);
    float d = float(duration.count())/1000000.0;
    std::cout<<"\n#Time takes in microseconds: "<< duration.count();
    std::cout<<"\n#Time takes in seconds: "<< d<<std::endl;
    
    return 0;
}```

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions