Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (753) Games in Android Showcase (228) games submitted by our members Games in WIP (842) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Collisions between Planets[solved]  (Read 4014 times) 0 Members and 1 Guest are viewing this topic.
trvcic

Senior Newbie

 « Posted 2013-09-09 20:46:48 »

For a 2d sprite simulation I have a grouping of different sized planets. Their size represents their mass. The each have a randomly generated color. When they collide I would like to mix the colors based on their mass, ie a small black + a big white should be slightly gray. How can I do this in a RGB system?

while(true) { be awesome; }
Zhon

Junior Devvie

Medals: 4

 « Reply #1 - Posted 2013-09-09 20:59:05 »

Not sure if I got the question right but... maybe add the colors and divide by two?

color.r = (color1.r + color2.r)/2
color.g = (color1.g + color2.g)/2
color.b = (color1.b+ color2.b)/2
Riven

« JGO Overlord »

Medals: 1336
Projects: 4
Exp: 16 years

 « Reply #2 - Posted 2013-09-09 21:01:39 »

 1  2  3  4 `int totalMass = a.mass + b.mass;int r = ((a.r * a.mass) + (b.r * b.mass)) / totalMass;int g = ((a.g * a.mass) + (b.g * b.mass)) / totalMass;int b = ((a.b * a.mass) + (b.b * b.mass)) / totalMass;`

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
ags1

JGO Kernel

Medals: 363
Projects: 7

Make code not war!

 « Reply #3 - Posted 2013-09-09 21:02:45 »

It is just a weighted average:

(color1 * diameter1 * diameter1) + (color2 * diameter2 * diameter2) / (diameter1 * diameter1 + diameter2 * diameter2)

Er, yes, as per riven's post, my method is 2D which can be considered wrong. Of course the color derives from the surface layer so considering diameter squared is arguably better than considering mass.

Riven

« JGO Overlord »

Medals: 1336
Projects: 4
Exp: 16 years

 « Reply #4 - Posted 2013-09-09 21:03:29 »

It is just a weighted average:

(color1 * diameter1 * diameter1) + (color2 * diameter2 * diameter2) / (diameter1 * diameter1 + diameter2 * diameter2)
Planets are spheres, not circles.

Er, yes, as per riven's post, my method is 2D which can be considered wrong. Of course the color derives from the surface layer so considering diameter squared is arguably better than considering mass.
When planets collide, their original surfaces won't be very important

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings!
ags1

JGO Kernel

Medals: 363
Projects: 7

Make code not war!

 « Reply #5 - Posted 2013-09-09 21:07:41 »

But they aren't the same color the whole way through... :-) And the light crust will rise to the top regardless. If the small black planet is pure iron, and the white planet is mostly quartz, the new planet is going to be white.

trvcic

Senior Newbie

 « Reply #6 - Posted 2013-09-09 21:11:07 »

thanks this is what I needed. I was near doing this, but was confusing the area/ mass with the diameter.

while(true) { be awesome; }
ags1

JGO Kernel

Medals: 363
Projects: 7

Make code not war!

 « Reply #7 - Posted 2013-09-09 21:13:11 »

Actually, if the planets are anywhere near equal in size, the color of the new planet will be glowing red lava! (assuming rocky planets)

Maybe make the planets go red on impact, and then let them cool down over time to the weighted average color?

Abuse

JGO Ninja

Medals: 64

falling into the abyss of reality

 « Reply #8 - Posted 2013-09-22 11:29:58 »

Unless the orbits are almost identical, the two planets wouldn't coalesce anyway
Pages: [1]
 ignore  |  Print

 nelsongames (16 views) 2018-04-24 18:15:36 nelsongames (12 views) 2018-04-24 18:14:32 ivj94 (587 views) 2018-03-24 14:47:39 ivj94 (49 views) 2018-03-24 14:46:31 ivj94 (400 views) 2018-03-24 14:43:53 Solater (64 views) 2018-03-17 05:04:08 nelsongames (110 views) 2018-03-05 17:56:34 Gornova (175 views) 2018-03-02 22:15:33 buddyBro (723 views) 2018-02-28 16:59:18 buddyBro (93 views) 2018-02-28 16:45:17
 KaiHH 13x ByerN 11x SHC 10x NuclearPixels 10x Zemlaynin 10x Guerra2442 9x Damocles 6x VaTTeRGeR 5x Spasi 4x orangepascal 4x philfrei 4x ndnwarrior15 3x mesterh 3x ags1 3x princec 2x Phased 2x
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org