Lost Password?

Go Back   CodeCall Programming Forum > Software Development > General Programming > Programming Theory

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-23-2007, 02:54 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Credits: 0
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default Raycasting I guess

Well, this problem has been making me want to kill keyboard with my head for few hours already, and I feel that if I won't put it on some other shoulders I'll get insane in an instant.

So I have 2D Array containing which squares are occupied by walls and which are not. Every square is 25x25
I have starting X and Y (sX, sY) and I have Mouse X and Y(mX, mY).

So I want to shoot a ray from (sX,sY) going through (mX,mY) (Or trying to go through) which will stop on first encountered Wall returning X and Y position of Intersection, all in one Loop. You can say Bullet instead of Ray if it makes more sense.
I tried using the Grid Traversal which can be easily found through google, but it was so incomprehensible... I'm addicted to examples.
So I need some good way to do what I explained above, but I can't come up with anything (Excepting testing pixel by pixel but I won't even consider it).
And please, if you can, give um, Good explanation, because sometimes I just can't understand something just to realize how simple it was days or weeks later.

Thanks in advance.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 11-23-2007, 03:37 PM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,397
Last Blog:
wxWidgets is NOT code ...
Credits: 685
Rep Power: 27
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

What you are talking about doing is attempting to find the first object encountered along a vector. I'm going to guess that you are working on correctly displaying a map of some sort (like the original Wolfenstein 3d, etc).

(sX,sY) and (mX,mY) define a ray (vector, half-line, etc). It will have slope
m=(mY-sY)/(mX-sX),
which means it lies on the line
y-sY = m(x-sX).
To search for a collision, find the intersections between this line and the lines defined by the walls of the squares. The "actual" collision will satisfy two properties:
1) it will be on the same side of (sX,sY) as (mX,mY) and
2) of those, it will be the one that is closest to (sX,sY).
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 11-23-2007, 03:55 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Credits: 0
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default

Hm but it is rather slow way, since it has to do collision detection with quite a lot objects.
And the second thing is that the walls aren't objects. The whole level array looks actually like this:
Code:
level[0] = "xxxxxxxxxxxx"
level[1] = "x          x"
level[2] = "x          x"
level[3] = "x          x"
Of course I could write code capable of going through such array, but it would be even slower. I guess.

And the thing is for shots/bullets which travel all the way to the wall or enemy in one step.

Last edited by Maurice_Z; 11-23-2007 at 04:00 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 11-26-2007, 11:16 AM
WingedPanther's Avatar   
WingedPanther WingedPanther is offline
Super Moderator
 
Join Date: Jul 2006
Age: 35
Posts: 2,397
Last Blog:
wxWidgets is NOT code ...
Credits: 685
Rep Power: 27
WingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the roughWingedPanther is a jewel in the rough
Default

How many objects are you going to be looking at? Less than 100 would not be an issue.
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
|
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Chat with other CodeCall members on IRC; connect to irc.codecall.net and join #codecall
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 11-26-2007, 02:37 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 18
Posts: 113
Credits: 0
Rep Power: 4
gszauer is on a distinguished road
Default

Hmm... Have you read this tutorial?
Ray Casting Tutorial
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #6 (permalink)  
Old 11-26-2007, 02:44 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Credits: 0
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default

Quote:
Originally Posted by WingedPanther View Post
How many objects are you going to be looking at? Less than 100 would not be an issue.
The number of objects is not the matter, because I won't have much use of slower script when I'll go for more CPU eating projects, so in the end I have to learn the good method sooner or later, and better sooner, because it can make me think of some other good ideas tgo other scripts .

gszauer - I'll look through it, I never seen it before, but as far as I see it might be enough. Tomorrow though, got to get some sleep in a moment, since it is evening already here .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #7 (permalink)  
Old 11-26-2007, 03:24 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 18
Posts: 113
Credits: 0
Rep Power: 4
gszauer is on a distinguished road
Default

It should be enough, the site gives a walktrough of an entire raycasting engine. The Java Source code is also available.
Also, if you want i can recommend some good casting books.
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #8 (permalink)  
Old 11-27-2007, 01:15 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Credits: 0
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default

Ok, I guess I understood it in about 95%, but there is still one thing bugging me:
I concentrated on "Seventh Page" because that's all I need (I guess). I understood it, excepting for this: First I find the horizontal grid intersections and when I find the collision point I go to vertical intersection. Then I compare the distances between these points and the start point. The smaller distance lets me know which point is the good one.
To make it simpler:
Code:
sx=Distance(StartCoords[],HorIntCoords[])
sy=Distance(StartCoords[],VerIntCoords[])
if sx<sy 
          RayCollisionCoords[]=HorIntCoords[]
Else
          RayCollisionCoords[]=VerIntCoords[]
EndIf
That's how the overall "sketch" of what I mean looks.

The question is - Is there any way to make it so both scripts are executed simultaneously... I mean, that when you look at this link, the points A,C and D are determined through testing Horizontal intersections with grid, and points B and E through Vertical. Can I make it so there is more "Complicated" way of making the code so it looks at both Horizontal and Vertical intersections at once?
Sigh, explaining it is a real pain in the butt ^^;
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #9 (permalink)  
Old 11-27-2007, 02:03 PM
gszauer's Avatar   
gszauer gszauer is offline
Programmer
 
Join Date: Nov 2007
Location: Florida
Age: 18
Posts: 113
Credits: 0
Rep Power: 4
gszauer is on a distinguished road
Default

I sort of get what you mean, but why do you want to do that?
I mean, i followed the Permadi tutorial, and ended up with a working ray-caster. Why do you want to "over-complicate" it?
__________________
Quote:
Originally Posted by ~Aristotle
It is the mark of an educated mind to entertain a tought without accepting it
If my post was helpful, please help me build some rep
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #10 (permalink)  
Old 11-27-2007, 02:18 PM
Maurice_Z Maurice_Z is offline
Learning Programmer
 
Join Date: Nov 2007
Location: Poland
Posts: 35
Credits: 0
Rep Power: 4
Maurice_Z is on a distinguished road
Send a message via ICQ to Maurice_Z Send a message via AIM to Maurice_Z Send a message via MSN to Maurice_Z Send a message via Yahoo to Maurice_Z
Default

I dunno, just out of curiosity I guess .
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT -5. The time now is 11:26 PM.

Contest Stats

Xav ........ 1097.16
MeTh0Dz|Reb0rn ........ 986.37
morefood2001 ........ 850.04
John ........ 841.93
WingedPanther ........ 684.54
marwex89 ........ 638.26
Brandon W ........ 492.36
chili5 ........ 292.12
orjan ........ 187.41
Steve.L ........ 183.02

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 79%

Ads