Show 40 post(s) from this thread on one page
Page 1 of 2 12 Last
• 11-20-2008, 11:10 PM
x_maria
hello!

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 ( ...... )
{
}

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:

java.lang.InstantiationException: Beast\$boids
at java.lang.Class.newInstance0(Unknown Source)
at java.lang.Class.newInstance(Unknown Source)
at sun.applet.AppletPanel.createApplet(Unknown Source)
at sun.applet.AppletPanel.run(Unknown Source)
• 12-07-2008, 09:15 PM
x_maria
i fix that..now it can run.
thanks
• 12-12-2008, 08:26 PM
x_maria
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??
• 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
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?
• 12-13-2008, 10:59 PM
Nicholas Jordan
• 12-13-2008, 11:11 PM
x_maria
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.

Suggest try new Float(currentDirection).toInt();

which can be
Code:

```Float nextPosition = new Float((Math.cos(currentDirection) * currentSpeed)); x += nextPosition.toInteger();```
or something like that.
• 12-14-2008, 10:46 PM
x_maria
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:
Code:

```            // else, do some testing and set some reasonable size values if Dimensions sound screwy             else             {                 /****** 2.71828 18284 59045 23536 ******/                 ww = Math.min(screenSize.getWidth(),horzMax);                 hh = Math.min(screenSize.getHeight(),vertMax);//                 // ww and hh have been set but not used                 //                 www = (ww / 2.71828);// Gives pleasing scaling factor                 hhh = (hh / 2.71828);// for Border Layout manager - 0.36787968862663154641905911090837                 wwww = (ww - www );//                 hhhh = (hh - hhh );//                 adjustedSize.setSize(wwww,hhhh);                 super.setSize((Dimension)adjustedSize);// end fancy sizing                 windowSize.setSize(super.getSize());// = ;             }```
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.

You find things like this:
Code:

`Cyrus.this.pointGenerator = new Random(Seytem.currentTimeMillis());// ..`
and discover where your move() is going null on 0.00

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.
• 12-15-2008, 01:50 AM
Nicholas Jordan