i 'm trying to make a program in which objects(circles) will move around and follow 3 rules:
1. try to fly towards the centre of mass of neighbouring objects.
2. try to keep a small distance away from other objects.
3. try to match velocity with near objects.
the problem is that the objects don't move..

as i am new to java any ideas that might help would be appreciated!!!

11-21-2008, 02:46 AM

Fubarable

Suggestion: break the big problem into lots of little problems and try to solve each one, one at a time. If you run into a block with a "little" problem, then try to solve it in isolation of the rest of your program -- create a small program just to solve the small problem. If you still are not getting any where, then come back with this code. Good luck.

11-21-2008, 12:28 PM

x_maria

yes,you are right..it's just i don't have much time left and i am desperate!i will try only the first rule and ,if need be,i post again...thanks

11-22-2008, 11:41 PM

x_maria

hello again!
now i am having another problem..my groups of objects go only from left to right whereas i want them to move from one point to another to all directions.
how am i able to do that?can anyone help me please??

11-23-2008, 02:34 AM

Nicholas Jordan

Vector Points = new Vector();

for ( ...... )
{
Points.add(Random.nextInt(),Random.nextInt());
}

Grossly oversimplified, you could just place the Random.nextPoint() in the Shapes code but one would have to scale the ints down to something in the scale of:

Code:

double cx=0;
double cy=0;

in the void near() method......

The approach is known, this code is likely sample code and if you have not worked out the movement yet LOL on getting it running tonight.

Can be done, if you write hundreds of lines of code every day for fun. Remember, you have to do delta-X, delta-Y to get 2D movement. ( delta is fancy word for change of position )

11-23-2008, 01:13 PM

serjant

Quote:

Originally Posted by scherukumalli

Hi

I need 2nd hand Bike

9243067072

Buy it in the 2nd hand shop,got to ebay shop

11-23-2008, 11:55 PM

x_maria

Hi!
Thanks very much for the reply.!Yes,but if i do that ( use Random.nextInt() ), how am i going to check if one is close to each other(near method)?Is it possible for them to move to all directions by doing something with the variable direction or cos/sin?

12-07-2008, 07:55 PM

x_maria

hello!!

can anybody tell me what's wrong with the program and it doesn't run?
it appears the following message:

Hi!
In the following program there is an obstacle(ball) and some shapes that move around..
Does anybody know how am i going to add collision detection between the shapes and the obstacle??
Thanks in advance!

12-12-2008, 08:27 PM

xcallmejudasx

I havn't looked at the code but the general idea is your shape will have an area it takes up. Just check if the obstacle(x,y coords) is in bounds then a collision occurred.

12-12-2008, 08:42 PM

x_maria

Thanks for the quick reply!!
Could you be more specific?From what i have read i know that there is the " Rectangle getBounds()" and the "boolean intersects(Rectangle2D r)" but i am not able to use them in the code attached.So any help will be appreciated!

12-13-2008, 09:41 PM

x_maria

I tried to add collision detection but the shapes that fly straight do not follow the rule checkCollision()..Any ideas?What is that i am doing wrong?

Thanks very much for the reply!
the thing is that I use the methods getBounds() and intersects() but when shapes move straight ahead they do not turn in order to avoid the obstacle(method checkCollision)..

12-14-2008, 03:13 PM

Nicholas Jordan

Beastly Boids Boldy Blunder

I intended to work on this, have a full day ahead .... won't get much done on it today. HTH:

Code:

b.currentDirection= b.currentDirection*(float)(0.45 * Math.PI/180);

would seem to be moving the Boids and Beasts

current direction is += x/y ....

hmm,.. are you doing clean project and full rebuild?

sometimes there are boundary conditions that only show up on special casing like straight ahead and so on. The only fix is to pull short sections of code and do unit testing. This would have to focus on the results of Math.cosine() / sine() ... there are obscure compiler "optimizations" that are not even remotely optimizations, I have one of these I intend to get back to on a grapics UI where I coded probably ten lines to force the double or float to an int and got typing error.

Thanks for the reply!It helped!
Actually the code posted is not my "original" code.Mine is quite big that 's why I have this (smaller) one where I just try things and then put them in the original one..
Thanks again

12-15-2008, 01:40 AM

Nicholas Jordan

custom code looks bizzare.

It is normal to have bulky code and snip parts for posting, what helped? I looked at the code and seems to me it should run without having to do major modifications. Here's a few lines away from where I am talking about in my code:

I could tell it was not your original code, it has the hallmarks of sample code. Try taking a few lines and doing the System.out.println(value); approach in a modular fashion...gets things working better than any other approach.

When and if you get to a commercial code shop, be SURE to make your comments a great deal clearer than what I have here. The comments here are solely a fast copy-paste buffer for me....the code is self documenting. That only comes from writing a lot of code,....what happens in a commercial code shop is comments do not get changed to tell what people did - but for posting I suggest copious commenting to save people trying to guess what is needed by poster.