Пример #1
0
func (t *TestSuite) TestSegmentCenter() {
	segment := shapes.NewSegment(t.renderState.segmentProgram, 10, 15, 20, 20)

	x, y := segment.Center()
	t.Equal(float32(15), x)
	t.Equal(float32(17.5), y)

	size := segment.Bounds().Size()
	w, h := size.X, size.Y
	t.Equal(10, w)
	t.Equal(5, h)
}
Пример #2
0
func newGround(x1, y1, x2, y2 float32) *ground {
	ground := new(ground)

	// Chipmunk body

	ground.physicsBody = chipmunk.NewBodyStatic()
	ground.physicsShape = chipmunk.NewSegment(
		vect.Vect{vect.Float(x1), vect.Float(y1)},
		vect.Vect{vect.Float(x2), vect.Float(y2)},
		GroundRadius,
	)

	ground.physicsBody.AddShape(ground.physicsShape)

	// OpenGL shape

	ground.openglShape = shapes.NewSegment(x1, y1, x2, y2)
	ground.openglShape.Color(color.White)

	return ground
}
Пример #3
0
func (t *TestSuite) TestSegment() {
	filename := "expected_line.png"
	t.rlControl.drawFunc <- func() {
		w, h := t.renderState.window.GetSize()
		world := newWorld(w, h)
		segment := shapes.NewSegment(t.renderState.segmentProgram, 81.5, -40, 238.5, 44)

		// Color is yellow
		segment.SetColor(color.RGBA{255, 0, 0, 255})
		segment.AttachToWorld(world)
		gl.Clear(gl.COLOR_BUFFER_BIT)
		segment.Draw()
		t.testDraw <- testlib.Screenshot(t.renderState.window)
		t.renderState.window.SwapBuffers()
	}
	distance, exp, act, err := testlib.TestImage(filename, <-t.testDraw, imagetest.Center)
	if err != nil {
		panic(err)
	}
	t.True(distance < 0.0009, distanceError(distance, filename))
	if t.Failed() {
		saveExpAct(t.outputPath, "failed_"+filename, exp, act)
	}
}