- #1
XNTEABDSC
- 4
- 1
- TL;DR Summary
- For a 2D game, how to simulate gas and its interaction with objects?
I want to make a 2D game with gas (stardust) simulation. (I'm lazy to learn statistical physics and integrate thing by my self so) I want to know how gas spread, and how gas interact with circle object.
There will be 2D square grid. Each cell contains values of the state of the gas (a struct
V:Volume(in 2D it means area)
M:Total Mass
Momentum: ##\sum_A(m_A \cdot \vec{v_A} )##
Kinetic energy: ##\frac{1}{2}\sum_A(m_A \cdot v_A^2 )##
If you find better choice, fell free to use them.
##d GasCell## means state changes of states of gas
All objects in the game are circles (a struct
Mass,Radius,Velocity,Angular Velocity, and Velocity Variance? or Temperature?
We consider classical mechanics only.
I want to know following situations. (if you need, dt=1/32s)
fn evaluate_over_time(GasCell) -> 5 d GasCell :how the gas cell and its neighborhoods change over dt.
fn interact_with_object(GasCell,Body) -> (d GasCell,d Body) :how the gas cell and object change over dt.
fn receive_momentum(GasCell,Momentum)-> d GasCell :how the gas cell changes when receive momentum, assume all atom receive same dv.(##GasCell.Momentum+=Momentum##,##GasCell.Kinetic+=\frac{Momentum}{ GasCell.Mass}(1/2 Momentum + GasCell.Momentum)##. is this true?)
fn mass_transfer(GasCell,Body,MassFromGasCellToBody) -> (d GasCell,d Body) :how the gas cell and object change when some mass are transferred from gas cell to body (e.g. use gas to build ship).(easy)
Notes that we just need simulation that is close enough to the real state (e.g. While a object contacts multiple gas cell, I will only calculate interaction between it and the gas cell where object's center is).
You can expect that the diameter of circles is smaller than the length of side of gas cells.
If you want to write code directly, I'm using rust and crate fixed and cordic, while it is ok if you write them in another language. If you find out that use code directly (e.g. simulates 100 atoms) is faster than formulas and precise enough, then use code.
About the game: It is a rts game where stardust is the resource to build units.
There may be 64x64 grid of gas and about 1000 objects in the game.
Notes again that all of this is in 2d world. (If you can let it run in 3D world, and know how to control units well, please tell me)
There will be 2D square grid. Each cell contains values of the state of the gas (a struct
GasCell
). I expect the values are (assume we have a list of atoms, each atom has mass ##m## and velocity ##v##. ##\sum_A## means for each atom)V:Volume(in 2D it means area)
M:Total Mass
Momentum: ##\sum_A(m_A \cdot \vec{v_A} )##
Kinetic energy: ##\frac{1}{2}\sum_A(m_A \cdot v_A^2 )##
If you find better choice, fell free to use them.
##d GasCell## means state changes of states of gas
All objects in the game are circles (a struct
Body
).Mass,Radius,Velocity,Angular Velocity, and Velocity Variance? or Temperature?
We consider classical mechanics only.
I want to know following situations. (if you need, dt=1/32s)
fn evaluate_over_time(GasCell) -> 5 d GasCell :how the gas cell and its neighborhoods change over dt.
fn interact_with_object(GasCell,Body) -> (d GasCell,d Body) :how the gas cell and object change over dt.
Notes that we just need simulation that is close enough to the real state (e.g. While a object contacts multiple gas cell, I will only calculate interaction between it and the gas cell where object's center is).
You can expect that the diameter of circles is smaller than the length of side of gas cells.
If you want to write code directly, I'm using rust and crate fixed and cordic, while it is ok if you write them in another language. If you find out that use code directly (e.g. simulates 100 atoms) is faster than formulas and precise enough, then use code.
About the game: It is a rts game where stardust is the resource to build units.
There may be 64x64 grid of gas and about 1000 objects in the game.
Notes again that all of this is in 2d world. (If you can let it run in 3D world, and know how to control units well, please tell me)