Beispiel #1
0
func (cmd *ChainReaction) SpawnExplosion() {

	// Build pick ray vector
	window_y := (WinH - MouseY) - WinH/2
	norm_y := gl.GLdouble(window_y) / gl.GLdouble(WinH/2)
	window_x := MouseX - WinW/2
	norm_x := gl.GLdouble(window_x) / gl.GLdouble(WinW/2)

	// find pos on znear plane
	aspect := gl.GLdouble(WinW) / gl.GLdouble(WinH)
	ny := NearHeight * norm_y
	nx := NearHeight * aspect * norm_x

	// Now your pick ray vector is (x, y, -zNear).
	nx = nx * (gl.GLdouble(PlayArea) / gl.GLdouble(0.04))
	ny = ny * (gl.GLdouble(PlayArea) / gl.GLdouble(0.04))

	// Add a new exploding trigger at this point
	p := &Vector3{Real(nx), Real(ny), -5.0}
	v := &Vector3{0.0, 0.0, 0.0}
	c := ExplodeColor
	cmd.Triggers = cmd.Triggers[0 : len(cmd.Triggers)+1]
	cmd.Triggers[len(cmd.Triggers)-1] = trigger{TS_ExplodeInflate, 0.0, 0.1, *p, *v, c, 0.0, 0}
	fmt.Println(nx, ny)
	cmd.NumExploding = 1
	cmd.NumExploded = 1
}
// reset our viewport after a window resize
func resizeWindow(width, height int) {
	// protect against a divide by zero
	if height == 0 {
		height = 1
	}

	// Setup our viewport
	gl.Viewport(0, 0, width, height)

	// change to the projection matrix and set our viewing volume.
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()

	// aspect ratio
	aspect := gl.GLdouble(width / height)

	// Set our perspective.
	// This code is equivalent to using gluPerspective as in the original tutorial.
	var fov, near, far gl.GLdouble
	fov = 45.0
	near = 0.1
	far = 100.0
	top := gl.GLdouble(math.Tan(float64(fov*math.Pi/360.0))) * near
	bottom := -top
	left := aspect * bottom
	right := aspect * top
	gl.Frustum(float64(left), float64(right), float64(bottom), float64(top), float64(near), float64(far))

	// Make sure we're changing the model view and not the projection
	gl.MatrixMode(gl.MODELVIEW)

	// Reset the view
	gl.LoadIdentity()
}
Beispiel #3
0
func reshape(w, h int) {
	gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))
	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	gl.Ortho(0, gl.GLdouble(w), 0, gl.GLdouble(h), -1, 1)
	gl.Scalef(1, -1, 1)
	gl.Translatef(0, gl.GLfloat(-h), 0)
	gl.MatrixMode(gl.MODELVIEW)
}
Beispiel #4
0
func main() {

	sdl.Init(sdl.INIT_VIDEO)

	var screen = sdl.SetVideoMode(640, 480, 32, sdl.OPENGL)

	if screen == nil {
		panic("sdl error")
	}

	if gl.Init() != 0 {
		panic("glew error")
	}

	pen := Pen{}

	gl.MatrixMode(gl.PROJECTION)

	gl.Viewport(0, 0, gl.GLsizei(screen.W), gl.GLsizei(screen.H))
	gl.LoadIdentity()
	gl.Ortho(0, gl.GLdouble(screen.W), gl.GLdouble(screen.H), 0, -1.0, 1.0)

	gl.ClearColor(1, 1, 1, 0)
	gl.Clear(gl.COLOR_BUFFER_BIT)

	var running = true

	for running {

		e := &sdl.Event{}

		for e.Poll() {
			switch e.Type {
			case sdl.QUIT:
				running = false
				break
			case sdl.KEYDOWN:
				running = false
				break
			case sdl.MOUSEMOTION:
				me := e.MouseMotion()
				if me.State != 0 {
					pen.lineTo(Point{int(me.X), int(me.Y)})
				} else {
					pen.moveTo(Point{int(me.X), int(me.Y)})
				}
				break
			}
		}

		sdl.GL_SwapBuffers()
		sdl.Delay(25)
	}

	sdl.Quit()

}
Beispiel #5
0
func reshape(w, h int) {
	/* Because Gil specified "screen coordinates" (presumably with an
	   upper-left origin), this short bit of code sets up the coordinate
	   system to correspond to actual window coodrinates.  This code
	   wouldn't be required if you chose a (more typical in 3D) abstract
	   coordinate system. */

	gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))       /* Establish viewing area to cover entire window. */
	gl.MatrixMode(gl.PROJECTION)                          /* Start modifying the projection matrix. */
	gl.LoadIdentity()                                     /* Reset project matrix. */
	gl.Ortho(0, gl.GLdouble(w), 0, gl.GLdouble(h), -1, 1) /* Map abstract coords directly to window coords. */
	gl.Scalef(1, -1, 1)                                   /* Invert Y axis so increasing Y goes down. */
	gl.Translatef(0, gl.GLfloat(-h), 0)                   /* Shift origin up to upper-left corner. */
}
Beispiel #6
0
func glEnable2D() {

	var vPort [4]gl.GLint

	gl.GetIntegerv(gl.VIEWPORT, &vPort[0])

	gl.MatrixMode(gl.PROJECTION)
	gl.PushMatrix()
	gl.LoadIdentity()

	gl.Ortho(0.0, gl.GLdouble(vPort[2]), 0.0, gl.GLdouble(vPort[3]), -1.0, 1.0)
	gl.MatrixMode(gl.MODELVIEW)
	gl.PushMatrix()
	gl.LoadIdentity()
}
Beispiel #7
0
func ResizeWindow(w int32, h int32) {
	// resizeWindow
	gl.MatrixMode(gl.PROJECTION)
	gl.Viewport(0, 0, gl.GLsizei(w), gl.GLsizei(h))
	gl.LoadIdentity()

	//	glu.Perspective( 45.0, ratio, 0.1, 100.0)

	aspect := gl.GLdouble(w) / gl.GLdouble(h)
	zNear := gl.GLdouble(0.1)
	zFar := gl.GLdouble(100.0)

	gl.Frustum(-NearHeight*aspect,
		NearHeight*aspect,
		-NearHeight,
		NearHeight, zNear, zFar)

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()

	WinW = int(w)
	WinH = int(h)

}
Beispiel #8
0
	sdl.HWPALETTE | sdl.HWSURFACE | sdl.HWACCEL | sdl.RESIZABLE

// List of possible commands to present to stdout
var cmds []Cmd = make([]Cmd, 0, 200)

// Scheduler to run functions at specified times
var sch *sched.Scheduler

var MouseX int
var MouseY int
var MouseState uint8
var WinW int = 1080 // 640
var WinH int = 1024 // 480
var KeySym uint32 = sdl.K_UNKNOWN

const NearHeight = gl.GLdouble(0.05)

// Show the commands available to stdout and prompt the
// user to select one
func selectCommand(def_cmd int) *Cmd {
	fmt.Printf("Select a job to run:\n")
	for i := 0; i < len(cmds); i++ {
		fmt.Printf("%v : %v\n", i, cmds[i].Name())
	}
	var idx int
	fmt.Printf("> ")
	if def_cmd == -1 {
		fmt.Scan(&idx)
	} else {
		idx = def_cmd
	}