Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[leisure] balz 3d

25 views
Skip to first unread message

fir

unread,
May 18, 2019, 6:21:45 PM5/18/19
to
i once wrote some basic app for simple phisics
made from 2d balls, heres the vide from that app

https://www.youtube.com/watch?v=qEi6pXU8hLk

recently i wrote 3d version of it

too tired to make video but heres the screenshot

http://minddetonator.htw.pl/balz3d.png

and here is the exe /win32

http://minddetonator.htw.pl/balz3d.zip

(not malware, if youre paranoid try uplowading it to online scanner like virustotal or maybe run in wirtual machine,
should also work in wine/linux)

use space to fire some balls to hit objects on scene
use tilda key to unhide/hide cursor and reize window
hold shift when moving mouse to strafe camera move


this doesnt maybe look to much soectacular,
but i only worked on it 1-2 days (basen on 2d version, also might have small bugs becouse i dont bopther to repair them)

hovever it is potentially sorta fun , i mean its potentially fun to discuss it (even in various aspects, like

1) hov improve look
2) discss physics behind that
3) i could turn it to dll library allowing some do defining its ovn constructs and test it
4) etc

so maybe some opinions/hints what to do with that?

Alf P. Steinbach

unread,
May 19, 2019, 7:27:59 AM5/19/19
to
An executable and screenshots/video is not very relevant to comp.lang.c++.

How about posting the C++ source code for review?


Cheers!,

- Alf



fir

unread,
May 19, 2019, 8:06:55 AM5/19/19
to
i could do that eventually but in fact im not thinking it is quite true

i mean discussing some ideas and algorithms (in a head) may be more useful and pleasurable than 'reiewing' source which
a) is harder for read (than ideas to discuss)
b) will not give much becouse source is just a 'cast' of algorithms and is kinda strightforward
c) ideas are more funny
d) it is fun so it is relevant

first of all though,m this app should be run, and seen.. then i could say more on it if someone curious

fir

unread,
May 19, 2019, 8:53:28 AM5/19/19
to
if someone is interested in those algorithms/ideas:

GRAPHICS

I) the graphics part is i think to strightforward to more widely describe (you simply fire drawing calls, transform if form global coordinates to camera cordinates, and draw it as 2d routines on screen)

here i use my own rasterizer which is even kinda messy and maybe even slightly buggy (i cast 3d balls as a 2d balls which is afair not proper, also i cast 3d line as a 2 points to 2d than draw 2d line which also is not proper)

i also got a messy block of code related to 'mouse wrapping' which sometimes scaries me (but tnk to the windows for it [longer story])

PHYSICS

II) physical part is just like that, if
balls overlap i generate force equal to

float force = (pen*.3)*(pen*.3)

where pen is this penetration (balls overlaping in neutral units) this .3 was taken experimentally

then i change velocity from newton law

ball[i].vx+= (dx/d)* force /Mi;

//dx/d is a part of 'normal' (unity vector) just pointing the direction

thats about it (it taked some think to think it up but finally it showed thsi works fine)

as to border collisions:

ball[i].vx += H* pen ;

where pen is wall penetration and H = - 1.0; in that case

as to link forces (last form 3 that are acts here, two mentioned was ball-ball, ball-wall) it is

ball[i].vx+= -(dx/d)*force/Mi;

where that link force is in that case

force = (dev*.9)*(dev*.9)*sign(dev);

where dev is in that case 'deiation' (?)
from the distance that 'join' (link) prefers to keep between balls


thise all 3 magic numbers and all formulas i worged out experimentally

i could also give you numbers on sizes and masses but i need rest a bit

the containing box is from -700 to 700
in all 3 dimensions

ball radiuses are 8, 16, 18 and 20

most join distances are keeped at 100
masses of balls are usually set to 18 or 20

i give those numbers btw as quality of simulations seem to depend on them, and its important to find some well chosen valiues (what i set is not quite carefully chosen)

also maybe should note i calcilate 7 physical iteretions on one graphical draw of frame, and also dumping force of
ball[i].vx*=0.99990;
is set


fir

unread,
May 19, 2019, 10:14:31 AM5/19/19
to
some potential question:

fron the equations of those sources it
come thet when ball is placed in some locations, like out of the bos or one in another or (most annoying) distant from its join preffered distance, the ball takes very strong force, reaches immediately extreme velocity, and that makes kinda bug

this makes i must then set initial bals with care,
question what is the most soft end easy
way of resolving it? (easy to code and making most good behaviour in cases of mislplaced initialisations?)

fir

unread,
May 19, 2019, 4:19:41 PM5/19/19
to
i upgraded this a little by adding gravity

and as i must said when i initialy moved that thing to 3d i was initially dissapointed, as it initially was not looking good in turn, oppositely, gravity looks better than i thought

http://minddetonator.htw.pl/ballz3d2.zip

especially it looks cooll when you throw some tens or hundreds balls and then press a d (increasa a dump for a moment)

it looks a bit like neo stopping the bullets and lettin them fall down

also generally low gravity looks like underwater sometimes also cool

the problem is hovever at about that
amout of balls/bills

http://minddetonator.htw.pl/graity.png

(this is also apropos sand topics)
the simulation begen to strongly choke

(50 ms per frame is upper choking limit)

Sal LO

unread,
May 19, 2019, 5:57:50 PM5/19/19
to
0 new messages