|
Author |
Topic: overRect vs java Rectangle (Read 344 times) |
|
st33d
|
overRect vs java Rectangle
« on: Jan 20th, 2005, 3:25pm » |
|
For most of my collision detection I've just copy/pasted the overRect boolean thats repeated all over processing.org. http://processing.org/learning/examples/handles.html I'm writing a sort of bacterium simulator now that works in squares and was looking up what would be the most efficient method of collision detection when I discover java's Rectangle class. So instead of doing overRect I could have been doing: Code: Rectangle r1 = new Rectangle(0,0,20,20); void setup(){} void loop(){ if (r1.contains(mouseX,mouseY)){ println("true"); }else{ println("false"); } } |
| Add so to detect if the square bacterium are overlapping I'm thinking along these lines: Code: square s1 = new square(0,0,20); square s2 = new square(10,10,20); //void setup(){} void draw(){ s1.d(); s2.d(); if (s1.intersects(s2)){ println("true"); } } class square extends Rectangle { square (int x, int y, int s){ this.x = x; this.y = y; this.width = s; this.height = s; } void d(){ rect(x,y,width,height); } } |
| I know that when starting off coding it's good practice to write your own collision detection from scratch. But am I saving time here by accessing the java's Rectangle or am I slowing things down?
|
I could murder a pint.
|
|
|
|