Sign in to follow this  
Mosh

Adding items to raycasted level

Recommended Posts

I've just finished my first raycasting engine, its very basic at the minute with just some walls (not textured), floor, sky, and collision detection. I have been trying to add objects to my level, like health packs or weapons or whatever, but I can't figure it out. Could someone point me in the right direction maybe? Because I'm completely lost. [help] Thanks in advance for any help!

Share this post


Link to post
Share on other sites
Unlike raycasting walls, sprites/objects are done using similar techniques to 3D polygon engines, using translation and rotation with respect to the camera's position and orientation to work out whether they are in view (albeit just in 2D).

Translate each sprite's coordinates so they are relative to the camera position, then rotate sprite's position around the camera depending what direction the camera is pointing. If the sprite is within the camera's field of view it could be visible so work out its distance. Order the sprites by distance (furthest away first), work out which screen Y column to display sprite, calculate height whilst compensating for fish eye effect, then display sprite's columns if a wall element at a particular screen Y column isn't closer.

Share this post


Link to post
Share on other sites
abstractworlds' method is correct.

The basic procedure is that when you cast a ray and it hits an object, put that object in a list or such (marking it for drawing) and continue with the ray until you hit a wall. Draw the wall first and then the objects.

Depending on the way you've done your engine, you could have problems on the way to draw the objects. If you just have a sprite for objects, you should divide that sprite into columns (the same way it's done for walls) and procees like the drawing of walls (drawing the scaled column) . If you don't divide the sprite into columns, and just draw the whole sprite, you can have problems with an entire object poping up when you start to see it arround a corner, know what i mean?

Another detail is to have a notion of a transparent color when you draw your sprites. When you're drawing a column of the sprite and come up with this color, don't draw it. This is for things such as the gap between the arm and body of a monster for example (and the fact the if you don't do this, all your sprites will be rectangles :) ). Since the walls are draw before the objects, you'll never have parts that are not painted.

Share this post


Link to post
Share on other sites
Quote:
Original post by Mosh

I've just finished my first raycasting engine, its very basic at the minute with just some walls (not textured), floor, sky, and collision detection.


I have been trying to add objects to my level, like health packs or weapons or whatever, but I can't figure it out. Could someone point me in the right direction maybe? Because I'm completely lost. [help]

Thanks in advance for any help!


trees keeping ringing in my head, a simple scene graph which is tradionally implementated using the composite design pattern which will provide a unified inteface for all your high-level graphical (even non-graphical) entities where you could integrate a kind of bounding volume hierarchies into the scene graph structure. Also special kinds of trees on the lower-level for spatial sorting & other things these could also be nodes/leafs of the scene graph.

Share this post


Link to post
Share on other sites
Excellent, that helped no end! Your all officially entitled to a free copy of my super duper game when it gets finished [cool]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this