We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Raycasting sight and line-line collision
Page Index Toggle Pages: 1
Raycasting sight and line-line collision (Read 863 times)
Raycasting sight and line-line collision
Aug 23rd, 2006, 6:04am
 
Hi, I'm trying to create a little raycasting demo thingy where you can only see what you're looking at (mouselook) and vision is obstructed by objects (polygons, although in this code they are all rectangles).

Try the demo (source below), move with asdw, look with the mouse.

You will notice that there are tiny holes in my objects that appear seeming randomly. That's my problem. The line-line collision function is the last function in the program (boolean lineCollide). It is required to return true of the lines ab (ax,ay,bx,by) and cd (cx,cy,dx,dy) collide, and at the end place the collision point in the global variables: col_x and col_y. Does anyone have a better line-line collision function? Also, can you look at my code and tell me if there are any optomizations to be done? (I've never done raycasting before)

Demo and source:
http://www.staronesw.com/raycast2d/
Re: Raycasting sight and line-line collision
Reply #1 - Aug 23rd, 2006, 10:37am
 
I dont know if it's faster, but it is quite easier to use the java.awt stuff to handling intersections:

Quote:


import java.awt.geom.*;

Line2D.Float l1,l2;


void setup(){
 size(300,300);
 l1=new Line2D.Float(150,0,150,300);
 l2=new Line2D.Float(0,0,0,0);
}

void draw(){
 background(255);
 stroke(0);
 l2.x2=mouseX;
 l2.y2=mouseY;
 if(l1.intersectsLine(l2))stroke(255,0,0);
 line(l1.x1,l1.y1,l1.x2,l1.y2);
 line(l2.x1,l2.y1,l2.x2,l2.y2);
}




Java.awt has a lot of intersection testing also for points, retangles and shapes. take a look at Suns javadoc:
http://java.sun.com/j2se/1.3/docs/api/java/awt/geom/package-summary.html
And a this post at processing hacks:
http://www.processinghacks.com/hacks/using-awt-s-polygon-class-to-test-for-insideness



Page Index Toggle Pages: 1