Пример #1
0
func (self *Viewport) ClipPlanes() *[6][4]float32 {

	var pm32 []float64 = make([]float64, 16)
	gl.GetDoublev(gl.PROJECTION_MATRIX, pm32)
	var projectionMatrix64 *Matrix4 = NewMatrix(pm32[0], pm32[1], pm32[2], pm32[3], pm32[4], pm32[5], pm32[6], pm32[7], pm32[8], pm32[9], pm32[10], pm32[11], pm32[12], pm32[13], pm32[14], pm32[15])
	mvpmatrix := projectionMatrix64.Multiply(ModelMatrix())
	// mvpmatrix := ModelMatrix()

	planes64 := [6][4]float64{
		{mvpmatrix[3] + mvpmatrix[0], mvpmatrix[7] + mvpmatrix[4], mvpmatrix[11] + mvpmatrix[8], mvpmatrix[15] + mvpmatrix[12]},
		{mvpmatrix[3] - mvpmatrix[0], mvpmatrix[7] - mvpmatrix[4], mvpmatrix[11] - mvpmatrix[8], mvpmatrix[15] - mvpmatrix[12]},
		{mvpmatrix[3] + mvpmatrix[1], mvpmatrix[7] + mvpmatrix[5], mvpmatrix[11] + mvpmatrix[9], mvpmatrix[15] + mvpmatrix[13]},
		{mvpmatrix[3] - mvpmatrix[1], mvpmatrix[7] - mvpmatrix[5], mvpmatrix[11] - mvpmatrix[9], mvpmatrix[15] - mvpmatrix[13]},
		{mvpmatrix[3] + mvpmatrix[2], mvpmatrix[7] + mvpmatrix[6], mvpmatrix[11] + mvpmatrix[10], mvpmatrix[15] + mvpmatrix[14]},
		{mvpmatrix[3] - mvpmatrix[2], mvpmatrix[7] - mvpmatrix[6], mvpmatrix[11] - mvpmatrix[10], mvpmatrix[15] - mvpmatrix[14]},
	}

	var planes32 [6][4]float32
	for p := 0; p < 6; p++ {
		length := math.Sqrt(math.Pow(planes64[p][0], 2) + math.Pow(planes64[p][1], 2) + math.Pow(planes64[p][2], 2) + math.Pow(planes64[p][3], 2))
		planes32[p] = [4]float32{float32(planes64[p][0] / length), float32(planes64[p][1] / length), float32(planes64[p][2] / length), float32(planes64[p][3] / length)}
	}

	return &planes32
}
Пример #2
0
func (self *Viewport) HandleKeys(keys []uint8) {
	if keys[sdl.K_UP] != 0 {
		if keys[sdl.K_LCTRL] != 0 || keys[sdl.K_RCTRL] != 0 {
			self.Zoomin()
		} else {
			self.Rotx(5)
		}
	}
	if keys[sdl.K_DOWN] != 0 {
		if keys[sdl.K_LCTRL] != 0 || keys[sdl.K_RCTRL] != 0 {
			self.Zoomout()
		} else {
			self.Rotx(-5)
		}
	}
	if keys[sdl.K_LEFT] != 0 {
		if keys[sdl.K_LCTRL] != 0 || keys[sdl.K_RCTRL] != 0 {
			self.viewRadius -= 4
			if self.viewRadius < 8 {
				self.viewRadius = 8
			}
		} else {
			self.Roty(9)
		}
	}
	if keys[sdl.K_RIGHT] != 0 {
		if keys[sdl.K_LCTRL] != 0 || keys[sdl.K_RCTRL] != 0 {
			self.viewRadius += 4

		} else {
			self.Roty(-9)
		}
	}

	if keys[sdl.K_SLASH] != 0 {

		var pm32 []float64 = make([]float64, 16)
		gl.GetDoublev(gl.PROJECTION_MATRIX, pm32)
		var projectionMatrix64 *Matrix4 = NewMatrix(pm32[0], pm32[1], pm32[2], pm32[3], pm32[4], pm32[5], pm32[6], pm32[7], pm32[8], pm32[9], pm32[10], pm32[11], pm32[12], pm32[13], pm32[14], pm32[15])
		mvpmatrix := projectionMatrix64.Multiply(ModelMatrix())
		// mvpmatrix := ModelMatrix()

		planes64 := [6][4]float64{
			{mvpmatrix[3] + mvpmatrix[0], mvpmatrix[7] + mvpmatrix[4], mvpmatrix[11] + mvpmatrix[8], mvpmatrix[15] + mvpmatrix[12]},
			{mvpmatrix[3] - mvpmatrix[0], mvpmatrix[7] - mvpmatrix[4], mvpmatrix[11] - mvpmatrix[8], mvpmatrix[15] - mvpmatrix[12]},
			{mvpmatrix[3] + mvpmatrix[1], mvpmatrix[7] + mvpmatrix[5], mvpmatrix[11] + mvpmatrix[9], mvpmatrix[15] + mvpmatrix[13]},
			{mvpmatrix[3] - mvpmatrix[1], mvpmatrix[7] - mvpmatrix[5], mvpmatrix[11] - mvpmatrix[9], mvpmatrix[15] - mvpmatrix[13]},
			{mvpmatrix[3] + mvpmatrix[2], mvpmatrix[7] + mvpmatrix[6], mvpmatrix[11] + mvpmatrix[10], mvpmatrix[15] + mvpmatrix[14]},
			{mvpmatrix[3] - mvpmatrix[2], mvpmatrix[7] - mvpmatrix[6], mvpmatrix[11] - mvpmatrix[10], mvpmatrix[15] - mvpmatrix[14]},
		}

		var planes32 [6][4]float32
		for p := 0; p < 6; p++ {
			length := math.Sqrt(math.Pow(planes64[p][0], 2) + math.Pow(planes64[p][1], 2) + math.Pow(planes64[p][2], 2) + math.Pow(planes64[p][3], 2))
			fmt.Printf("Length: %d: %0.2f\n", p, length)
			planes32[p] = [4]float32{float32(planes64[p][0] / length), float32(planes64[p][1] / length), float32(planes64[p][2] / length), float32(planes64[p][3] / length)}

			fmt.Printf("Plane: %d: [%0.6f, %0.6f, %0.6f, %0.6f]\n", p, planes32[p][0], planes32[p][1], planes32[p][2], planes32[p][3])

		}
	}

}