B
B
Bulat Antonov2021-10-10 10:21:58
3D
Bulat Antonov, 2021-10-10 10:21:58

How to throw a beam?

I'm making a 3D game, please don't pay attention to the title of the question, just qna.habr.com has too strict rules for creating a title, I need to make a ray throw function that will return the color of the object, so far no lighting needs to be done, just a ray throw and it cube collision:

#include <cstdlib>
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf;
int WIDTH=800;
int HEIGHT=600;
int bits_per_pixel=32;
/*
 * 
 */
Color cast_ray() {
    return Color(0,0,0);
}
int main(int argc, char** argv) {
    RenderWindow window(VideoMode(WIDTH,HEIGHT,32),"GAME");
    while(window.isOpen()){
        Event event;
        while(window.pollEvent(event)){if(event.type==Event::Closed){window.close();}}
        window.clear(Color(100,200,255,0));
        RectangleShape floor(Vector2f(WIDTH,HEIGHT/2));
        floor.setPosition(0,HEIGHT/2);
        floor.setFillColor(Color(150,100,100));
        window.draw(floor);
        window.display();
    }
    return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-10-10
@boulat5280

There is a whole article on the topic: https://habr.com/ru/post/533932/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question