コード例 #1
0
ファイル: cubedrop.go プロジェクト: tbogdala/cubez
func fire() {
	const cubesToMake = 4
	var offset float32 = 0.0
	if len(cubes) > 0 && (len(cubes)/cubesToMake)%2 >= 1 {
		offset = 0.75
	}

	for i := 0; i < cubesToMake; i++ {
		e := new(Entity)
		e.Node = CreateCube(-0.5, -0.5, -0.5, 0.5, 0.5, 0.5)
		e.Node.Shader = diffuseShader
		e.Node.Color = mgl.Vec4{1.0, 1.0, 1.0, 1.0}
		e.Node.Location = mgl.Vec3{float32(i*2.0-cubesToMake/2) - 0.5 + offset, 10.0, 0.0}
		e.Node.Tex0 = crateTexture

		// create the collision box for the the cube
		cubeCollider := cubez.NewCollisionCube(nil, m.Vector3{0.5, 0.5, 0.5})
		cubeCollider.Body.Position = m.Vector3{m.Real(i*2.0-cubesToMake/2) - 0.5 + m.Real(offset), 10.0, 0.0}
		cubeCollider.Body.SetMass(8.0)
		cubeCollider.Body.CanSleep = true

		var cubeInertia m.Matrix3
		cubeInertia.SetBlockInertiaTensor(&cubeCollider.HalfSize, 8.0)
		cubeCollider.Body.SetInertiaTensor(&cubeInertia)

		cubeCollider.Body.CalculateDerivedData()
		cubeCollider.CalculateDerivedData()
		e.Collider = cubeCollider

		cubes = append(cubes, e)
	}
}
コード例 #2
0
ファイル: ballistic.go プロジェクト: tbogdala/cubez
func main() {
	app = NewApp()
	app.InitGraphics("Ballistic", 800, 600)
	app.SetKeyCallback(keyCallback)
	app.OnRender = renderCallback
	app.OnUpdate = updateCallback
	defer app.Terminate()

	// compile the shaders
	var err error
	colorShader, err = LoadShaderProgram(DiffuseColorVertShader, DiffuseColorFragShader)
	if err != nil {
		panic("Failed to compile the shader! " + err.Error())
	}

	// create the ground plane
	groundPlane = cubez.NewCollisionPlane(m.Vector3{0.0, 1.0, 0.0}, 0.0)

	// make a ground plane to draw
	ground = CreatePlaneXZ(-500.0, 500.0, 500.0, -500.0, 1.0)
	ground.Shader = colorShader
	ground.Color = mgl.Vec4{0.6, 0.6, 0.6, 1.0}

	// create a test cube to render
	cubeNode := CreateCube(-1.0, -1.0, -1.0, 1.0, 1.0, 1.0)
	cubeNode.Shader = colorShader
	cubeNode.Color = mgl.Vec4{1.0, 0.0, 0.0, 1.0}

	// create the collision box for the the cube
	var cubeMass m.Real = 8.0
	var cubeInertia m.Matrix3
	cubeCollider := cubez.NewCollisionCube(nil, m.Vector3{1.0, 1.0, 1.0})
	cubeCollider.Body.Position = m.Vector3{0.0, 5.0, 0.0}
	cubeCollider.Body.SetMass(cubeMass)
	cubeInertia.SetBlockInertiaTensor(&cubeCollider.HalfSize, cubeMass)
	cubeCollider.Body.SetInertiaTensor(&cubeInertia)
	cubeCollider.Body.CalculateDerivedData()
	cubeCollider.CalculateDerivedData()

	// make the entity out of the renerable and collider
	cube = NewEntity(cubeNode, cubeCollider)

	// make a slice of entities for bullets
	bullets = make([]*Entity, 0, 16)

	// make the backboard to bound the bullets off of
	backboardNode := CreateCube(-0.5, -2.0, -0.25, 0.5, 2.0, 0.25)
	backboardNode.Shader = colorShader
	backboardNode.Color = mgl.Vec4{0.25, 0.2, 0.2, 1.0}
	backboardCollider := cubez.NewCollisionCube(nil, m.Vector3{0.5, 2.0, 0.25})
	backboardCollider.Body.Position = m.Vector3{0.0, 2.0, -10.0}
	backboardCollider.Body.SetInfiniteMass()
	backboardCollider.Body.CalculateDerivedData()
	backboardCollider.CalculateDerivedData()
	SetGlVector3(&backboardNode.Location, &backboardCollider.Body.Position)

	// make the backboard entity
	backboard = NewEntity(backboardNode, backboardCollider)

	// setup the camera
	app.CameraPos = mgl.Vec3{-3.0, 3.0, 15.0}
	app.CameraRotation = mgl.QuatLookAtV(
		mgl.Vec3{-3.0, 3.0, 15.0},
		mgl.Vec3{0.0, 1.0, 0.0},
		mgl.Vec3{0.0, 1.0, 0.0})

	gl.Enable(gl.DEPTH_TEST)
	app.RenderLoop()
}