Jump to bottom

Closed Thread Icon

Topic awaiting preservation: FINALLY started controlling my movements with vectors (Page 2 of 2) Pages that link to <a href="https://ozoneasylum.com/backlink?for=8338" title="Pages that link to Topic awaiting preservation: FINALLY started controlling my movements with vectors (Page 2 of 2)" rel="nofollow" >Topic awaiting preservation: FINALLY started controlling my movements with vectors <span class="small">(Page 2 of 2)</span>\

 
Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-10-2002 19:56

> In reality the acceleration is based on one over the cube of the distance.

No, it's not; It's one over the square of the distance =)

But, you did point out one important thing. Your simplified code:

code:
lengthtosun = Math.sqrt((distancetosunX*distancetosunX) + (distancetosunY*distancetosunY));
Zobjects[x].velX -= ((distancetosunX/(lengthtosun*lengthtosun))*fudge_factor);



Can be simplified even farther like so:

code:
lengthtosun_squared = (distancetosunX*distancetosunX) + (distancetosunY*distancetosunY);
Zobjects[x].velX -= ((distancetosunX/lengthtosun_squared)*fudge_factor);



This gets rid of the Math.sqrt(), which should prove to be an *immense* speedup (calculating square roots is slooooow). Doc, this means you may be able to increase the number of planets, if you want. =)

andy_j
Nervous Wreck (II) Inmate

From: uk
Insane since: Aug 2002

posted posted 10-10-2002 21:57

Wow this is fantastic stiuff. I love the demos..

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-10-2002 23:26

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 10-10-2002 23:57

Slime.
OK I agree. The accelleration is proportional to 1 over the square of the distance.
However - I think the x component should be over distance cubed.
Take a look
<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>

Forces - The force acts from mass 'm' towards mass 'm2'
fx
m----->

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-11-2002 00:03

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 10-11-2002 00:06

Wow, that worked perfectly! It's still kind of slow when you go crazy on the planets, especially when you add too many suns. Check it out with 99, http://www.bigbonfire.com/bugs/?howMany=99 - or add in a new number if it works for you. You can also add the control ?howFast=[x] where [x] is the refresh rate of the setInterval function. Thanks for the help, this is going to end up as a short sweet neat function, I love it!

Your pal, -doc-

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 10-11-2002 01:46

Hi Ini,
It is difficult to post equations.
m and m2 are 2 different parameters. The parameter 'm' is the mass I am moving 'm2' is the mass of the other object.
The only squared parameter is 'r'. (It is m.(r^2) but it the equation it may look like (m.r)^2 which it is not)

If I write it like this

F = (G.m.M)/(r^2)
F = m.A

m.A = (G.m.M)/(r^2)

Can't I illiminate m and just say?
A = (G.M)/(r^2)

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 10-11-2002 02:47

Yes, that part is right, you can cancel out the m's. (It's interesting to realize that this means that the mass of the object being pulled has no effect on how fast it accelerates.)

Now, to be perfectly honest with you, besides the fact that you're saying "sine" when you should be saying "cosine", I'm not sure if there's anything wrong with your calculations. It's possible that yours are really exactly the same as mine. At this point, though, I'm really quite confused. I'm not sure if Doc's final code is actually correct anymore, and I'm just really lost. I'd have to start over from scratch to get it right =)

OK. So I'll do that. Starting over from scratch.

a=C/r^2
(C is some constant that we don't care about exactly, related to the mass of the object. fudge_factor. whatever you want to call it.)

ax = cos(theta)/r^2
ax = x/r^3

Wait, yes, you're right! And this helps me understand what I was confused about with the Doc's code. In reality, what he has is only an acceleration proportional to 1/r.

This is why before I was saying

directiontosunX/(lengthtosun^2) // (direction, not distance, to sun; found by dividing X distance by the length to sun)

Which happens to be equivalent to

distancetosunX/(lengthtosun^3)

So, doc, in order to be fully correct, you'll have to use *directiontosun* instead of *distancetosun*. Which means you may have to bring in the direction calculating code again, which may require a square root =\

On the other hand, this may help create correct orbits.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-11-2002 07:59

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 10-11-2002 08:51

Hi Slime,

quote:
(It's interesting to realize that this means that the mass of the object being pulled has no effect on how fast it accelerates)


Drop a feather and a hammer on the moon - they hit the gound at the same time

I am always confused about sine (=opposite or adjascent?) over hypotenuse and cosine, thats why in my first attempt I didn't use sine or cosine, i just used the fact (x/r) == (ax/A).

Er.. anyway - Doc's demo looks cool.
I just had to find out about the calculations because I couldn't find anything in the web about how to calculate the x,y coordinate of a mass in orbit..

Cheers
Roy.


DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 10-11-2002 21:13

Yah, the problem with squaring the value there is that the movement, it scarcely happens at all! Whereas now, it at least appears to be somewhat proper to the eye. I'm already using this...

lengthtosun_squared = (distancetosunX*distancetosunX) + (distancetosunY*distancetosunY);
dirX = distancetosunX/Math.abs(distancetosunX);
dirY = distancetosunY/Math.abs(distancetosunY);
Zobjects[x].velX -= ((distancetosunX/lengthtosun_squared)*fudge_factor);
Zobjects[x].velY -= ((distancetosunY/lengthtosun_squared)*fudge_factor);

Are you saying I should need to square this again? Hmm, my caveman brain sees thing like "Ugh! Gravity work now, caveman scared to fix!" :-)

I've added an additional fudge factor so that things tend to slow down over time, this eventually makes all the planets tend to cluster around the stars at higher gravity, but if I didn't do that all the stars eventually get spun away, showing up only every 5 minutes or so. I have thought about calculating the direction again, so I could use it to flatten out the elliptical orbits, that would end up looking cool, I'd love to see those totally squashed ellipses turn into more circular orbits over time.

Your pal, -doc-

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-11-2002 21:22

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

GRUMBLE
Paranoid (IV) Mad Scientist

From: Omicron Persei 8
Insane since: Oct 2000

posted posted 10-13-2002 20:16

well doc, are you doing this game for fun or is this another strange job?
just wondering?

great JS work, btw.

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 10-14-2002 07:55

Nah, just goofing around, avoiding work, heh. I was thinking it could end up as some kind of cool space game maybe? I could set up a map of stars throught the "galaxy", I'd just have to make sure that I didn't bother calculating stars too far away otherwise the cpu-burn would be heavy. Then I guess, well, you could fly around and maybe.. shoot stuff? Or something.

I guess I was just goofing off. It'll turn into something, I'm sure!

Your pal, -doc-

Bugimus
Maniac (V) Mad Scientist

From: New California
Insane since: Mar 2000

posted posted 10-14-2002 10:21

Space War was one of my favorite arcade games "back in the day".

hmm... shooting stuff? asteroids perhaps? Wouldn't that be superb!

. . : slicePuzzle

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 10-14-2002 19:20

Hah! Bugs, I was wondering when someone would bring up that game, I loved playing that! I was thinking maybe something that'd give me that same thrill, but with an endlessly generating universe. Even if you just "flew" around, picture the thrill as you have to slingshot past a black hole, virtually! Add in a whole mess of stuff you need to shoot along the way, well, that's game enough for me! Heck, maybe I'd even add in scoring as a perk. ;-)

Hmm, just imagined this in 3D, and got dizzy. Wish I was better at that stuff, that'd be way cool.

Your pal, -doc-

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-14-2002 22:14

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

RoyW
Bipolar (III) Inmate

From:
Insane since: Aug 2001

posted posted 10-18-2002 06:13

Hey Doc,
(Hope you don't mind me calling you Doc?)
I was just looking at the latest version of the script (the graphics are fantastic!) and was wondering if you had thought about adding a zoom factor. That way when "planets" fly off into the ether you can zoom out to see where they've gone.
Here is a really crude demo to show what I mean. http://www.javascript-fx.com/post/ozone/orbit/orbit3.html

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-18-2002 09:15

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

DocOzone
Maniac (V) Lord Mad Scientist
Sovereign of all the lands Ozone and just beyond that little green line over there...

From: Stockholm, Sweden
Insane since: Mar 1994

posted posted 10-18-2002 11:21

Actually, I'm building at a different address now, I've been having too many problems with the bigbonfire.com domain. Look now at http://ozoniclabs.com/gravlabs/ - I hope it'll remain here for now. (Last night I had a dream about building this into a spherical, or possibly toroidal world, something you could circumnavigate. You could fly around the screen, or if you got closer to the edge, the background would scroll and you'd see new stars. Hitting planets would be bad, crash! Hitting a star would be nearly impossible, unless it was a black hole. I could set up "fuel depots" around the landscape, each with it's own gravity. (Circle it, press a key, and then land, they'll fill you up.) Run out of fuel? Drift endlessly, eventually you'll end up sucked into the wormhole at the end, or crash into a planet or black hole. Somehow you'd have to fly around and pick up [something worth points] finishing up your foray by crashing into a wormhole, leading to the next level. Levels could be generated from a data file, so this opens the possiblilty of level designers.

Sound like fun?

Your pal, -doc-

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-18-2002 15:02

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

InI
Paranoid (IV) Mad Scientist

From: Somewhere over the rainbow
Insane since: Mar 2001

posted posted 10-20-2002 11:33

The poster has demanded we remove all his contributions, less he takes legal action.
We have done so.
Now Tyberius Prime expects him to start complaining that we removed his 'free speech' since this message will replace all of his posts, past and future.
Don't follow his example - seek real life help first.

« Previous Page1 [2]

« BackwardsOnwards »

Show Forum Drop Down Menu