Skip to content

Commit

Permalink
add Object & Block
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxkad committed Nov 26, 2023
1 parent 5136a24 commit 13324d1
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 5 deletions.
20 changes: 20 additions & 0 deletions block.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package molecular

type Facing uint8

//go:generate stringer -type=Facing
const (
TOP Facing = iota
BOTTOM
LEFT
RIGHT
FRONT
BACK
)

type Block interface {
Mass() float64
Material(f Facing) *Material
Outline() *Cube
Tick(dt float64)
}
6 changes: 6 additions & 0 deletions engine.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package molecular

type Config struct {
// MinSpeed means the minimum positive speed
MinSpeed float64
// MaxSpeed means the maximum positive speed
MaxSpeed float64
}

Expand All @@ -18,3 +20,7 @@ func NewEngine(cfg Config) *Engine {
func (e *Engine) Config() Config {
return e.cfg
}

func (e *Engine) Tick(dt float64) {
// TODO
}
28 changes: 28 additions & 0 deletions facing_string.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions motion.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,24 @@ const (
C = 299792458.0 // The speed of light
)

// RelativeDeltaTime returns the actuall time that relative to the obeserver (server),
// with given speed and the time relative to the moving object
func RelativeDeltaTime(t float64, speed float64) float64 {
return t / math.Sqrt(1-speed*speed/C*C)
// RelativeDeltaTime returns the actual delta time that relative to the moving object,
// with given speed and the delta time relative to the observer (or the server)
func (e *Engine) RelativeDeltaTime(t float64, speed float64) float64 {
if t == 0 {
return 0
}
if t < 0 {
panic("molecular.Engine: delta time cannot be negative")
}
if speed < 0 {
panic("molecular.Engine: speed cannot be negative")
}
if speed >= C {
return math.SmallestNonzeroFloat64
}
t2 := t * math.Sqrt(1-speed*speed/(C*C))
if t2 == 0 {
return math.SmallestNonzeroFloat64
}
return t2
}
25 changes: 25 additions & 0 deletions object.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package molecular

type AnchorObject struct {
rpos map[*AnchorObject]Vec // the pos relative to other known anchors
objs map[*Object]struct{}
}

func (a *AnchorObject) Tick(dt float64) {
for o, _ := range a.objs {
o.Tick(dt)
}
}

type Object struct {
anchor *AnchorObject
pos Vec // the position relative to the anchor
facing Vec
blocks []Block
}

func (o *Object) Tick(dt float64) {
for _, b := range o.blocks {
b.Tick(dt)
}
}
2 changes: 1 addition & 1 deletion package.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

// molecule is a 3D physics engine that designed for realistic gravity
// molecule is a 3D physics engine that designed for realistic star system
//
// The default units used by this package:
// Distance and Position: m (meter)
Expand Down

0 comments on commit 13324d1

Please sign in to comment.