-
Notifications
You must be signed in to change notification settings - Fork 47
Open
Description
I followed the instructions for the hello world program, in the PDF linked from the README. And nothing moves. Perhaps I did something wrong.
func main() {
var gravity = d2.MakeB2Vec2(0.0, -10.0)
var world = d2.MakeB2World(gravity)
groundBodyDef := d2.B2BodyDef{}
groundBodyDef.Position.Set(0, -10)
groundBody := world.CreateBody(&groundBodyDef)
groundBox := d2.B2PolygonShape{}
groundBox.SetAsBox(50, 10)
groundBody.CreateFixture(&groundBox, 0)
bodyDef := d2.B2BodyDef{}
bodyDef.Type = d2.B2BodyType.B2_dynamicBody
bodyDef.Position.Set(0, 4)
body := world.CreateBody(&bodyDef)
dynamicBox := d2.B2PolygonShape{}
dynamicBox.SetAsBox(1, 1)
fixtureDef := d2.B2FixtureDef{}
fixtureDef.Shape = &dynamicBox
fixtureDef.Density = 1
fixtureDef.Friction = 0.3
body.CreateFixtureFromDef(&fixtureDef)
timeStep := 1.0 / 60.0
velocityIterations := 6
positionIterations := 2
for i := 0; i < 60; i++ {
world.Step(timeStep, velocityIterations, positionIterations)
position := body.GetPosition()
angle := body.GetAngle()
fmt.Printf("%4.2f %4.2f %4.2f\n", position.X, position.Y, angle)
}
}
$ go run main.go
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
0.00 4.00 0.00
...
Truthfully I tried incorporating this module into another project I'm working on and it failed there. Which is when I took a step back, tried the hello world, and found that didn't work either.
Metadata
Metadata
Assignees
Labels
No labels