How to get the points a, b of the segment shape? #29
-
How to get the points a, b of the segment shape?
example code: package main
import (
"fmt"
"github.com/jakecoffman/cp/v2"
)
func main() {
space := cp.NewSpace()
space.SetGravity(cp.Vector{X: 0, Y: -20})
space.Iterations = 10
seg := &cp.Segment{}
body := cp.NewStaticBody()
seg.Shape = cp.NewSegment(
body,
cp.Vector{X: 50, Y: 10},
cp.Vector{X: 350, Y: 13},
0)
body.SetPosition(cp.Vector{10, 10})
space.AddBody(body)
space.AddShape(seg.Shape)
space.Step(1. / 60.)
fmt.Printf("%T %T \n", seg.Shape.Point(0), seg.Shape.Point(1))
fmt.Printf("%v %v \n", seg.Shape.Point(0), seg.Shape.Point(1))
fmt.Printf("%v %v \n", seg.A(), seg.B())
// Output:
// cp.SupportPoint cp.SupportPoint
// {{60 20} 0} {{360 23} 1}
// 0.000000,0.000000 0.000000,0.000000 I think I need this function. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Right, it gets weird if you initialize structs directly. I would do it like this: func main() {
space := cp.NewSpace()
space.SetGravity(cp.Vector{X: 0, Y: -20})
space.Iterations = 10
body := cp.NewStaticBody()
segShape := cp.NewSegment(
body,
cp.Vector{X: 50, Y: 10},
cp.Vector{X: 350, Y: 13},
0)
body.SetPosition(cp.Vector{10, 10})
space.AddBody(body)
space.AddShape(segShape)
space.Step(1. / 60.)
fmt.Printf("%T %T \n", segShape.Point(0), segShape.Point(1))
fmt.Printf("%v %v \n", segShape.Point(0), segShape.Point(1))
seg := segShape.Class.(*cp.Segment)
fmt.Printf("%v %v \n", seg.A(), seg.B())
} |
Beta Was this translation helpful? Give feedback.
-
Here are the missing functions: https://chipmunk-physics.net/release/ChipmunkLatest-Docs/#cpShape-Segments |
Beta Was this translation helpful? Give feedback.
Right, it gets weird if you initialize structs directly. I would do it like this: