Jump to content
  • Advertisement
Sign in to follow this  
redsplat

Bug in raycasting engine

This topic is 3161 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello! I'm tryin to make a raycasting engine in javascript. But something is wrong in the way the rays are being casted. I don't know what.. This is the current state of my engine http://redsplat.org/FPS/ You control with the arrow keys. It is supposed to work like this http://devfiles.myopera.com/articles/580/2dmap_raycast.htm , except that I haven't added vertical collusion detection.. [Edited by - redsplat on October 17, 2009 10:42:57 AM]

Share this post


Link to post
Share on other sites
Advertisement
Your issue is a bug in how you're adding angles, but let's ignore that. You're relying on trigonometry to do the work of linear algebra. Stop doing that. A raycaster doesn't need to use any trig at all.

Determine your image plane (or, in the 2D case, your image line). For each point on the image plane corresponding to a pixel, find the point on the image plane, then find the vector from the eyepoint through that point. Presto-- no weirdnesses when your signed angles wrap around, and no fisheye (your raycasting is producing fisheye, though you haven't noticed it yet).

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
Your issue is a bug in how you're adding angles, but let's ignore that.

I've been spending many hours trying to find that bug. It might not be important because I will have to rewrite the trigonometry parts of my code anyway. But I'm curious and would REALLY like to know what the bug is..

Quote:
Original post by SneftelYou're relying on trigonometry to do the work of linear algebra. Stop doing that. A raycaster doesn't need to use any trig at all.

Determine your image plane (or, in the 2D case, your image line). For each point on the image plane corresponding to a pixel, find the point on the image plane, then find the vector from the eyepoint through that point. Presto-- no weirdnesses when your signed angles wrap around, and no fisheye (your raycasting is producing fisheye, though you haven't noticed it yet).

Do you mean that I should cast my rays like this instead of this? How do I do that? I'm not very good at this you see.. :(

[Edited by - redsplat on October 17, 2009 10:23:13 AM]

Share this post


Link to post
Share on other sites
No, that's related to but not the same thing as I'm talking about. Check this out:



To find a ray, you take a point on the viewing plane (say, 0.7 units to the left of the center of the image plane), and then find the ray from the observer point that passes through that point on the viewing plane.

Share this post


Link to post
Share on other sites
Isn't that what I'm already doing? In my castRays() function I check where on the projection plane the ray goes trough and calculates the rays.

Share this post


Link to post
Share on other sites
Quote:
Original post by redsplat
Isn't that what I'm already doing? In my castRays() function I check where on the projection plane the ray goes trough and calculates the rays.

You do, actually; I missed that. But then you throw out the ray's vector and keep only its angle. Change castSingleRay to take in a 2-element vector, and use it (times some appropriate amount) as the x and y step. There's other ways to handle that part, but the current morass of trig in castSingleRay is most assuredly where this problem lies.

Share this post


Link to post
Share on other sites
You have a bug because you are trying to make things work in an overly complicated way. A simpler way has been suggested to you. The implication is that if you just do things in the simpler way, the bug will disappear, because you'll get the simple way right the first time.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
You have a bug because you are trying to make things work in an overly complicated way. A simpler way has been suggested to you. The implication is that if you just do things in the simpler way, the bug will disappear, because you'll get the simple way right the first time.

I have no idea about what is "overly complicated" in the way I'm doing it and I have no idea about how to make it simpler..

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!