Thread: ray casting

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    ray casting

    What is a good API to write a ray casting game engine for? Allegro, Windows GDI, OpenGL or Direct X? Would the Windows GDI be good enough to write a small demo?
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Shadow12345
    Guest
    ray casting game engine? what exactly do you do in the game? is this supposed to be extremely simple? extremely complex/math oriented? what? cheese!

  3. #3
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Ray casting is what Doom used. Here's the tutorial I'm planning to create it based on:
    http://www.permadi.com/tutorial/raycast/index.html. I don't really know what ray casting is myself.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  4. #4
    Shadow12345
    Guest
    uhh which doom, i assume you mean doom iii, look at the post i made that tries to explain how casting shadows works. it's not the easiest thing in the world and when you come down to it there is probably a lot of advanced math involved, plus it brings most systems down to their knees.

  5. #5
    Emotionally Unstable DarkViper's Avatar
    Join Date
    Oct 2002
    Posts
    343
    uhh....i still dont undertsand just what it is, is it like, level lumanance or something?
    ~DJ DarkViper signing out
    ----------------------------------------
    My Site:
    Black Jaguar Studios

    Languages:
    Fluent English, Starter German, HTML, Javascript, Actionscript, Intermediate PHP

    Verteran Despiser of: ASP, Java, BASIC, Pascal, Cobalt

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Shadow12345
    uhh which doom, i assume you mean doom iii, look at the post i made that tries to explain how casting shadows works. it's not the easiest thing in the world and when you come down to it there is probably a lot of advanced math involved, plus it brings most systems down to their knees.
    Since raycasting is an ooooold and ugly trick to make a fake 3D world, It's NOT used in doom 3 .
    It was used in Doom 1 - 2 and Wolfenstein (and numerous others which I don't know).
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  7. #7
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145

    Re: ray casting

    Originally posted by lambs4
    What is a good API to write a ray casting game engine for? Allegro, Windows GDI, OpenGL or Direct X? Would the Windows GDI be good enough to write a small demo?
    I'm not sure why you would like to do a raycaster. With Direct3D or OpenGL it would probably be easier to make a 'real' 3D program/game.

    http://www.gamedev.net/reference/art...article872.asp

    http://www.cs.unc.edu/~hoff/projects...t/raycast.html
    Last edited by Magos; 12-06-2002 at 07:06 PM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  8. #8
    Shadow12345
    Guest
    Since raycasting is an ooooold and ugly trick to make a fake 3D world, It's NOT used in doom 3 .
    uhh actually, you're wrong, carmack has specifically said shadow volumes are used to make the shadows in doom iii, i read that in an interview. if you've read the algorithm for shadow volumes you must be casting rays at some point in the process.

    now im not saying it's use extensively, im just saying it is used in shadow volumes and carmack said he used shadow volumes so he must be casting rays!

    EDIT:
    what i was describing was the silouette edge which is described as being found with casting rays from the light position through the outermost vertices until they intersect a surface. that is how it is descrbed in my game programming book but i must admit not necessarily true all the time, so i guess it is possible that carmack didn't use rays, but it is such a small thing it almost doesn't matter. and btw, how could either of us know what that dude is up to. i'm reading something i think he wrote, and, well, doesn't make sense to me
    http://cvs1.nvidia.com/OpenGL/doc/wh...dowVolumes.txt
    Last edited by Shadow12345; 12-06-2002 at 07:28 PM.

  9. #9
    Registered User
    Join Date
    Apr 2002
    Posts
    1,571
    Originally posted by Shadow12345
    uhh actually, you're wrong, carmack has specifically said shadow volumes are used to make the shadows in doom iii, i read that in an interview. if you've read the algorithm for shadow volumes you must be casting rays at some point in the process.

    now im not saying it's use extensively, im just saying it is used in shadow volumes and carmack said he used shadow volumes so he must be casting rays!
    ACTUALLY he's not using ray casting. He is probably using ray tracing. There is a difference. Yes they both cast rays but they vastly different.

    Ray casting is a very simple way to simulate a 3D world. Some restrictions are put on a ray casted world though. The floor and walls must be orthogonal for instance. Doom doesn't use the same ray casting engine as wolfenstien. Doom ray casting engine is triangle based and do a lot more "tricks". I may post some links if I can remember them. Search on google you'll find a lot.

  10. #10
    Shadow12345
    Guest
    did you even read the rest of my post

  11. #11
    Visionary Philosopher Sayeh's Avatar
    Join Date
    Aug 2002
    Posts
    212
    There are two (slow but highly accurate) methods of ray-based drawing--

    Ray-Tracing -- where you trace Rays of light from a point light source (like the sun or a bulb) and mathematically follow each vector as it bounces, reflects, refracts, and diffuses into the environment.

    Ray-Casting -- where you cast rays out away from the viewer and draw "slices" of the environment whereever the rays strike. This is how Castle Wolfenstein was done (the original 3D version). DOOM never used this method, it used BSP trees.

    It is worth learning how to create a ray-casting engine because it is highly educational and will teach you many of the things necessary that are used in any other higher-level graphic engine, such as working in "slices", dealing with fisheye effects, drawing textures, foreshortening, transparent surfaces, clipping, point of view (POV), and more...

    It relies heavily on sin() and cos() calculations and tables, but other than that it is fairly fun to do.

    If you can do a good quality Ray-Caster, you are way ahead of most developers wanting to "do games" themselves. If you can then modify what you know, such as adding a z-axis, or going further than the Wolfenstein-like abilities, then you are well on your way to moving on to more complex models, such as BSP and portal engines.
    It is not the spoon that bends, it is you who bends around the spoon.

  12. #12
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Originally posted by Sayeh
    This is how Castle Wolfenstein was done (the original 3D version). DOOM never used this method, it used BSP trees.
    BSP trees don't have anything (directly) to do with ray casting/tracing, except ruling out where you shouldn't be tracing to. Just because something uses BSP trees doesn't mean it doesn't use casting.

    BSP is binary space partitioning. The concept of binary space partioning is you keep dividing your 3D world recursively in halves (usually trying to balance out things like polygon count on each side) and you store information about each of those partitions in a binary tree. Then when you want to do things such as figuring out what should be drawn you just traverse through the tree until you find out exactly which sector the player is in, then you can more quickly figure out which sectors should be drawn based on the players view frustum and where the sectors meet. You can also use it to help rule out which objects you want to check collission with.

    Originally, the main reason for this was for draw order. Usually when one would make a BSP tree they'd keep partitioning until all of the leaves of the tree were concave. That way, you draw all of the furthest visible partitions from the user first, all the way until you get up to the one that you are in. This way, the proper walls get drawn "in front" of other walls. The order in which triangles within the partitions themselves get drawn doesn't matter because they are convex partitions -- no wall in a room will ever block another wall in the same room if it's convex IE a box. Since we have hardware acceleration and z-buffers, it's not as necissary that your partitions are convex because the buffer will handle everything for you (though if you can make a convex tree it's better than relying on the zbuffer and will be more accurate than zbuffering could ever be).

    Another reason for this is that is you can easily figure out where a light ray has to go to "get out of" the sector. You can easily make "portals" as you partition which are the "empty pieces of planes" that are shared by adjacent partitions. Then, when you want to see if a light ray escapes one partition and enters an adjacent one you just check for collision with the portal.

    The fact that a game uses BSP trees doesn't mean they don't use Ray-Tracing or casting as well.
    Last edited by Polymorphic OOP; 12-06-2002 at 11:45 PM.

  13. #13
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Originally posted by Shadow12345
    did you even read the rest of my post
    He said Raycaster, not ray tracing.

    BTW: With your avatar, you should know that .
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  14. #14
    Shadow12345
    Guest
    well i was attempting to gracefully explain how i was probably wrong, and maintain some dignity and then provide a helpful resource in that link (which btw you all will find interesting) but he went ahead and corrected me anyway so I called him a slut

    He said Raycaster, not ray tracing.
    uhh so?

    EDIT:

    poly have you read the bsp loading tutorial on www.gametutorials.com? There are three of them, you will like them if you haven't already seem them

  15. #15
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    nah, I don't use the quake BSP format, I made my own I try to stay away from tutorials because it's too tempting to just copy/paste. Also, my programming style is pretty rigid and I'm very particular about the way I implement things, so I feel better just making it myself. Besides, it's so much more rewarding to know you can do it completely from scratch.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help designing a recursive function.
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 07-24-2008, 12:45 PM
  2. Casting
    By morvick in forum C++ Programming
    Replies: 2
    Last Post: 06-17-2007, 11:06 PM
  3. Ray tracer and collision detection
    By hdragon in forum Game Programming
    Replies: 31
    Last Post: 01-19-2006, 11:09 AM
  4. question about casting pointers/other types also??
    By newbie02 in forum C++ Programming
    Replies: 3
    Last Post: 08-07-2003, 05:01 AM