Giter Site home page Giter Site logo

raycaster-sdl's Introduction

Raycaster-SDL

A simple Ray Casting 3D engine using SDL as the rendering back-end.

Overview

This project is a typical textured Ray Casting engine akin to games like Wolfenstein 3D, Blake Stone, etc.

The crux of this program is not that it is an efficient implementation, or that it contains special rendering features. Instead, this Ray Caster is unique (as far as I have seen) in that the engine is built almost entirely on top of fundamental Linear Algebra concepts (vectors, transformation matrices, vector projection, etc.), even down to stepping vector calculation, which uses a modified form of vector projection.

The rationale for this is simply that this was designed as a teaching aide for students in a computer graphics course to help solidify their knowledge of fundamental Linear Algebra concepts (and also give them something nice to look at).

On that note, there does exist accompanying teaching material for this Ray Caster which I authored - but since I do not currently have permission from the relevant academic institution, I cannot upload those. If time permits, and if there's interest, I'd be more than happy to produce some new material to help people understand how this engine works.

Requirements

This project requires the following libraries:

  • SDL2

Compiling

Unlike most of my other projects, this project does not rely on any build system. To compile the project, simply navigate to the root of the project and enter the following command:

gcc -lm -lSDL2 -O2 src/*.c -o raycaster

Running

To run the Ray Caster, enter ./raycaster into your shell.

Using the Ray Caster

The Ray Caster accepts the following controls:

Left Turn left.
Right Turn right.
Up Move forward.
Down Move backward.
Shift Hold to move twice as fast.
t Toggle between textured and untextured rendering.
m Toggle the full screen map on/off.
f Toggle the barrel distortion correction on/off.
[ Decrease the distance to the viewplace (increase FOV)
] Increase the distance to the viewplace (decrease FOV)
escape Quit the game.

Screenshots

untextured textured map

Licence

See LICENCE for details.

raycaster-sdl's People

Contributors

drdanick avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

raycaster-sdl's Issues

Feature Request - Teaching Material

Hello @drdanick ,

I have been tinkering with and learning this raycaster as I find the code very clean, well organized. I also find it unique compared to other examples I have seen so I have run into some difficulty understanding parts of it. I find raycasters interesting and would like to learn more about them. I have made minor adjustments for fun like adding mouse look and custom textures. Adding ceiling and floor textures is something I am curious to try out.

The README indicates teaching material existed but you did not have permission to upload it. Has this situation changed or are you able to provide any further documentation on the raycaster?

Thanks!

Compilling error

I tried to compile using the command in README:
gcc -lm -lSDL2 -O2 src/*.c -o raycaster
but didn't work and this was the following error:

/usr/bin/ld: /tmp/ccGCsF4w.o: na função "consumeSDLEvents":
main.c:(.text+0x58): referência não definida para "SDL_PollEvent"
/usr/bin/ld: main.c:(.text+0x9d): referência não definida para "SDL_PollEvent"
/usr/bin/ld: /tmp/ccGCsF4w.o: na função "runGame":
main.c:(.text+0x2be): referência não definida para "SDL_GetTicks"
/usr/bin/ld: main.c:(.text+0x2e6): referência não definida para "SDL_Delay"
/usr/bin/ld: main.c:(.text+0x302): referência não definida para "SDL_GetTicks"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "gfxSetError":
gfx.c:(.text+0x1e): referência não definida para "SDL_GetError"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "initGFX":
gfx.c:(.text+0xcf): referência não definida para "SDL_Init"
/usr/bin/ld: gfx.c:(.text+0xfc): referência não definida para "SDL_CreateWindow"
/usr/bin/ld: gfx.c:(.text+0x115): referência não definida para "SDL_CreateRenderer"
/usr/bin/ld: gfx.c:(.text+0x13b): referência não definida para "SDL_SetWindowTitle"
/usr/bin/ld: gfx.c:(.text+0x15c): referência não definida para "SDL_SetRenderDrawColor"
/usr/bin/ld: gfx.c:(.text+0x168): referência não definida para "SDL_RenderClear"
/usr/bin/ld: gfx.c:(.text+0x174): referência não definida para "SDL_RenderPresent"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "createTexture":
gfx.c:(.text+0x240): referência não definida para "SDL_CreateTexture"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "destroyTexture":
gfx.c:(.text+0x33c): referência não definida para "SDL_DestroyTexture"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "displayFullscreenTexture":
gfx.c:(.text+0x3e5): referência não definida para "SDL_UpdateTexture"
/usr/bin/ld: gfx.c:(.text+0x3f1): referência não definida para "SDL_RenderClear"
/usr/bin/ld: gfx.c:(.text+0x405): referência não definida para "SDL_RenderCopy"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "destroyGFX":
gfx.c:(.text+0x473): referência não definida para "SDL_DestroyRenderer"
/usr/bin/ld: gfx.c:(.text+0x48a): referência não definida para "SDL_DestroyWindow"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "fillRect":
gfx.c:(.text+0x552): referência não definida para "SDL_RenderFillRect"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "drawRect":
gfx.c:(.text+0x5a2): referência não definida para "SDL_RenderDrawRect"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "displayFullscreenTexture":
gfx.c:(.text+0x412): referência não definida para "SDL_RenderPresent"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "destroyGFX":
gfx.c:(.text+0x49e): referência não definida para "SDL_Quit"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "setDrawColor":
gfx.c:(.text+0x4ce): referência não definida para "SDL_SetRenderDrawColor"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "drawLine":
gfx.c:(.text+0x512): referência não definida para "SDL_RenderDrawLine"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "presentRenderer":
gfx.c:(.text+0x5cc): referência não definida para "SDL_RenderPresent"
/usr/bin/ld: /tmp/cc0jcw3x.o: na função "clearRenderer":
gfx.c:(.text+0x5dc): referência não definida para "SDL_RenderClear"
/usr/bin/ld: /tmp/ccTSfJHu.o: na função "normalizeVector":
linalg.c:(.text+0x11d): referência não definida para "sqrtf"
/usr/bin/ld: /tmp/ccTSfJHu.o: na função "homogeneousVectorMagnitude":
linalg.c:(.text+0x1e8): referência não definida para "sqrtf"
/usr/bin/ld: /tmp/cc5qv6jw.o: na função "renderOverheadMap":
map.c:(.text+0x335): referência não definida para "SDL_Delay"
/usr/bin/ld: /tmp/ccYyQlax.o: na função "renderProjectedScene":
renderer.c:(.text+0x4c8): referência não definida para "SDL_Delay"
collect2: error: ld returned 1 exit status

referência não definida = undefined reference

so, I tried this command:
gcc -O2 src/*.c -lm -lSDL2 -o raycaster
and now it works

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.