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.
IndexProgramming Questions & HelpSyntax Questions › Let's talk Gravity!
Page Index Toggle Pages: 1
Let's talk Gravity! (Read 1513 times)
Let's talk Gravity!
Oct 12th, 2009, 7:50am
 
Hey everyone!

I am a total newbie when it comes to processing.

I am trying to write an app involving gravity. I have tried out a few tutorials on gravity, but I can't seem to find the right one for my needs.

I want to make a "room" filled with misc stuff like cats, dogs, milk cartons etc. I then want the items to be affected by different gravity data by the means of a potentiometer through Arduino.
The one that I got to "work" is just in 2D wheres I want the items to float inside the whole room in a 3D fashion.

I hope you can understand what I am trying to make Smiley

Thanks !
Re: Let's talk Gravity!
Reply #1 - Oct 12th, 2009, 8:42am
 
Depending on your experience with other languages I'd suggest you stick to getting it working properly in 2D first.  Also, when you say you got it to "work" what does that mean?  Gravity isn't a complicated concept: it's easy enough to simulate by simply adjusting an object's velocity on the y axis each frame, and it's not particularly difficult to apply that in 3D.  However I guess you might mean that each object has its own gravity and influence on all other objects, more like a solar system than standing on a planet.

You clearly need to be a little clearer about what you hope to achieve and what help you want in getting there...
Re: Let's talk Gravity!
Reply #2 - Oct 12th, 2009, 9:43am
 
blindfish wrote on Oct 12th, 2009, 8:42am:
Depending on your experience with other languages I'd suggest you stick to getting it working properly in 2D first.  Also, when you say you got it to "work" what does that mean  Gravity isn't a complicated concept: it's easy enough to simulate by simply adjusting an object's velocity on the y axis each frame, and it's not particularly difficult to apply that in 3D.  However I guess you might mean that each object has its own gravity and influence on all other objects, more like a solar system than standing on a planet.

You clearly need to be a little clearer about what you hope to achieve and what help you want in getting there...




This is the tutorial that I have used so far; processing.org/learning/topics/bouncybubbles.html
and kind of want to take the gravity code from that tutorial and fuse it with this; processing.org/learning/topics/bouncybubbles.html .

What I want is about ten different items. These items start on earth's gravity, so not moving at all. Then if I change the gravity with a potentiometer and with a push of a button, the items in the room will float around in the given gravity.
The items do not have to have different data for each item as I will try to simulate the gravity of say, the moon. So a car and a cat "falls" at the same velocity wether it's on the moon or on earth

10 items located in a 3d cube
all the items are randomly located on the floor of the cube
initial gravity is earths gravity
by turning the potentiometer the gravity data changes
push of a button, the items scatter around the room at the given gravity


hope this is a bit clearer Smiley
Re: Let's talk Gravity!
Reply #3 - Oct 12th, 2009, 10:05am
 
If you have some gravity, even the one on the Moon (1/6th of Earth's one), objects won't "float around" but will still fall. They might fall at a slower speed, but still falling.

When you push your button, you can give an initial force: upward vector to be subtracted from the downward gravity vector, although it can also have an horizontal component to make things more interesting.
Re: Let's talk Gravity!
Reply #4 - Oct 12th, 2009, 10:21am
 
PhiLho  wrote on Oct 12th, 2009, 10:05am:
If you have some gravity, even the one on the Moon (1/6th of Earth's one), objects won't "float around" but will still fall. They might fall at a slower speed, but still falling.

When you push your button, you can give an initial force: upward vector to be subtracted from the downward gravity vector, although it can also have an horizontal component to make things more interesting.


yeah I know, and it's what I am after, gonna try to make a few "stops", to have different scenarios that adapt to the data of the potentiometer. So I need different gravity data.

About what you suggested, I think that I understand what you mean... I'm gonna try to see what I can do.. Thanks!
Re: Let's talk Gravity!
Reply #5 - Oct 12th, 2009, 2:46pm
 
MarMan wrote on Oct 12th, 2009, 9:43am:
What I want is about ten different items. These items start on earth's gravity, so not moving at all. Then if I change the gravity with a potentiometer and with a push of a button, the items in the room will float around in the given gravity.
<snip />
hope this is a bit clearer Smiley


As PhiLho says: If all the objects are on the ground under the influence of Earth's gravity, when you switch to a 'lighter' gravity they're not going to move: they're still under a downwards pull; so you'd need to simulate some movement to make things interesting, or place them at a random height above the ground...

Anyway I remember posting a question a while ago that may be relevant...  OOP is obviously very useful in this type of situation.
Re: Let's talk Gravity!
Reply #6 - Oct 15th, 2009, 5:07am
 
Could someone please help me out with this code?

Processing says that I cannot cast from Float to PVector... How do I pass it?
Code:

for (int i = 0; i < numBalls; i++) {
balls[i] = new Ball(random(width), random(height),(PVector) random(80, 90), i, balls);

}


class Ball {
PVector pos;
//pvector this function
PVector diameter;
PVector w, h;
PVector vel;
int id;
Ball[] others;

Ball(float pos, float vel, PVector z, int vel, Ball[] oin) {
//x = xin;
//y = yin;
vel = new PVector(0,0);
pos = new PVector( xin, yin );

diameter = din;
id = idin;
others = oin;
}

thanks!

Re: Let's talk Gravity!
Reply #7 - Oct 15th, 2009, 5:09am
 
Well, don't use PVector for scalar values like diameter, w, h...
Page Index Toggle Pages: 1