|
||||||
| Programming Theory Discuss programming theory, algorithm efficiency, logic, and other any other category where math and computer science overlap. |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
|
|||
|
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. |
| Sponsored Links |
|
|
|
|||
|
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" 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. |
|
|||||
|
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 |
|
|||||
|
Hmm... Have you read this tutorial?
Ray Casting Tutorial
__________________
Quote:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
| Sponsored Links |
|
|
|
|||
|
Quote:
.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 . |
|
|||||
|
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:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
|
|||
|
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
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 ^^; |
|
|||||
|
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:
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
![]() |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|
| 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 |
Goal: 100,000 Posts
Complete: 79%