Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Raycasting Sprites?
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Silinter




PostPosted: Wed Jun 18, 2008 9:51 pm   Post subject: Raycasting Sprites?

So yeh, I was working on a raycasting engine , cuz i really have nothing better to do, and I got stuck on a little problem.
It turns out, I don't know the first thing about raycasting a sprite. I have a little engine set up. It's got textures, variable quality, tile sizes and you can look up and down. Nothing special.
What are the general steps (and maybe some equations) to finding sprites and then drawing them on screen ? There are no tutorials that, just in general, outline the steps to doing sprites. There is one written in C++ but I can't follow that one very far.

Also, and this is somewhat related, how would i go about raycasting floors? I've looked at the famous tutorial that everyone refers to, (the one on permadi.com) but it's vague on floors/ceilings. I also found several other sources, but none of them seem to work. It'd be great if someone could help me with this. I saw in particular that codemonkey had a pretty good engine up, as well as one other whose name escapes me Shocked
Sponsor
Sponsor
Sponsor
sponsor
SNIPERDUDE




PostPosted: Thu Jun 19, 2008 10:11 am   Post subject: RE:Raycasting Sprites?

for the sprites, I kinda cheated and used whatdotcolour. So I would have the character's position drawn on the map in a specific colour (so it wouldn't be drawn as a wall). The programme would then read his position and you would draw it accordingly.

For floors and ceiling, it would be easier to just draw a gradient to make the illusion of depth.
Silinter




PostPosted: Thu Jun 19, 2008 5:58 pm   Post subject: Re: Raycasting Sprites?

Well, it would be MUCH easier to make a simple gradient for the floor, but that takes all the fun away :p

I just need some general directions like the ones on permadi.com to get me on my way. That tutorial really is great, but does not mention sprites and is WAY too old (written in 1996)
for reference, here it is: http://www.permadi.com/tutorial/raycast/index.html
CodeMonkey2000




PostPosted: Thu Jun 19, 2008 6:37 pm   Post subject: RE:Raycasting Sprites?

For raycasting I think you might be better of with a BSP tree. I believe that's how Doom was done. You load the world at the beginning and keep inserting and deleting moving sprites. Be warned, it's fairly complected (but fast).

Another thing you could do is when you are raycasting wall slices, check if that ray is also intersecting with sprite slices, and draw the slice if it's closer than the wall slice, but draw the wall anyway. Remember, the sprite will always be perpendicular to the viewing vector.
Silinter




PostPosted: Thu Jun 19, 2008 10:40 pm   Post subject: Re: Raycasting Sprites?

Yes, thank you, I believe i have the gist of it now, I'll try and figure the rest out myself. And as for the BSP tree, I don't think I'm anywhere near the level to understand such... complications Crying or Very sad I'll make due in gr.11 with my PLAIN OLD raycaster, even though more then 98% of my class doesn't even believe 3D can be done on turing. Well, it's not technically 3D, but it sure does look good :p
Euphoracle




PostPosted: Fri Jun 20, 2008 10:43 am   Post subject: RE:Raycasting Sprites?

The final project in my class turned out to be (because that's what people made) 4, 000 line trivia games. You're doing far better than my classmates did, and I would guess far better than your classmates are. Keep up the good work (:
CodeMonkey2000




PostPosted: Fri Jun 20, 2008 1:44 pm   Post subject: RE:Raycasting Sprites?

4, 000 lines for trivia? That sounds trivial and redundant :S Do the teachers not have a sense of good programming habits?
Silinter




PostPosted: Fri Jun 20, 2008 3:47 pm   Post subject: Re: Raycasting Sprites?

codemonkey, i looked at the source for your raycaster, and noticed that you have a tangent function, which returns the tangent of the angle in degrees.
I didn't understand this when i started to program the raycaster, but i soon found out that tand() returns an error while your tangent function does not. Why does this happen?
Also, why do you have a distance function? the Math.Distance works fine. Is it to make it more compatible with older versions of Turing?

EDIT: Also, i can't seem to get the sprites to always face the player Shocked i guess i'm using the same drawing method that i use for the walls. how could i make it so that it always draws it towards the player?
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Fri Jun 20, 2008 10:35 pm   Post subject: Re: Raycasting Sprites?

Silinter @ Fri Jun 20, 2008 3:47 pm wrote:
codemonkey, i looked at the source for your raycaster, and noticed that you have a tangent function, which returns the tangent of the angle in degrees.
I didn't understand this when i started to program the raycaster, but i soon found out that tand() returns an error while your tangent function does not. Why does this happen?
Also, why do you have a distance function? the Math.Distance works fine. Is it to make it more compatible with older versions of Turing?



That's because the version of turing I had at the time was old. About the error, I have no idea, and I asked that question a while ago, and nobody seemed to know either.

Silinter @ Fri Jun 20, 2008 3:47 pm wrote:

EDIT: Also, i can't seem to get the sprites to always face the player Shocked i guess i'm using the same drawing method that i use for the walls. how could i make it so that it always draws it towards the player?


This will give a fishbowl effect, but you can correct it the say way you did with walls.

EDIT: If the distance is less than sprite width/2 then you need to compare it to the intersected wall. If the distance from you to the sprite intersection is less than that of the wall, draw the wall slice then the sprite slice.



sprite.bmp
 Description:
 Filesize:  184.62 KB
 Viewed:  174 Time(s)

sprite.bmp


SNIPERDUDE




PostPosted: Sat Jun 21, 2008 7:39 am   Post subject: RE:Raycasting Sprites?

wow, that was the same tutorial I used for raycasting back in the day. It may be old, but it sure is helpful.

And using the floor/ceiling method they used may look better in some cases, gradient would be faster in the end.
Silinter




PostPosted: Sat Jun 21, 2008 3:29 pm   Post subject: Re: Raycasting Sprites?

alright, i just looked at the math.tu in turing's predefs folder, and found the tand function.
here's what it says

Turing:
function tand (r : real) : real
        if r mod 180 = 90 then
            quit < : excpRealOverflow
        else
            result sind (r) / cosd (r)
        end if
end tand


so as you can see, if the angle % 180 is 90, then it returns an overflow. other then that it does the same thing that your function does Confused
CodeMonkey2000




PostPosted: Sat Jun 21, 2008 6:35 pm   Post subject: RE:Raycasting Sprites?

cos 90 is 0, therefore tan 0 is undefined.
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 12 Posts ]
Jump to:   


Style:  
Search: