Skip to content

How to get the points a, b of the segment shape? #29

Closed Locked Answered by jakecoffman
setanarut asked this question in Q&A
Discussion options

You must be logged in to vote

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())
}

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
1 reply
@setanarut
Comment options

setanarut Jan 5, 2024
Collaborator Author

Answer selected by setanarut
Comment options

setanarut
Jan 5, 2024
Collaborator Author

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants