예제 #1
0
// Creates a new system using (temorarily) hard-coded constants
func NewSystem(X, Y int) System {
	numStars := 1
	numPlanets := rand.Int() % 12

	// Make the slice of Planet

	planets := make([]*data.Planet, numPlanets+1)

	// TODO get rid of hard coded constants
	for i := 0; i <= numPlanets; i++ {
		orbitSizeX := rand.Float64()*4000 + 2000
		orbitSizeY := rand.Float64()*4000 + 2000
		orbitSpeed := rand.Float64() / ((orbitSizeX + orbitSizeY) / 10)

		size := gl.Float(rand.Float64() * 100)

		planets[i] = &data.Planet{data.GameObject{PlanetTextures[0], 0, 0, size, size, 0},
			orbitSizeX, orbitSizeY, orbitSpeed, float64(X), float64(Y)}
	}

	// Make the slice of Stars for each system
	stars := make([]*data.Star, numStars+1)

	for i := 0; i <= numStars; i++ {
		stars[i] = &data.Star{data.GameObject{PlanetTextures[0], gl.Float(X), gl.Float(Y), gl.Float(X + 300), gl.Float(Y + 300), 0}}
	}

	return System{X, Y, numStars, numPlanets, planets, stars}
}
예제 #2
0
파일: shapes.go 프로젝트: knickers/GOpenGL
func Cylinder(r, h gl.Float, slices int, hollow, solid bool) {
	res := 2 * math.Pi / float64(slices)
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.QUADS
	}
	gl.Begin(gl.Enum(mode))
	for a := 0.0; a < 2*math.Pi; a += res {
		gl.Normal3f(gl.Float(math.Cos(a)), gl.Float(math.Sin(a)), 0)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), 0)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), h)
		a += res
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), h)
		gl.Vertex3f(r*gl.Float(math.Cos(a)), r*gl.Float(math.Sin(a)), 0)
	}
	gl.End()
	if !hollow {
		// X Y plane
		if h < 0 {
			gl.Normal3f(0, 0, 1)
		} else {
			gl.Normal3f(0, 0, -1)
		}
		Circle(r, slices, solid)
		// Top (or bottom)
		if h < 0 {
			gl.Normal3f(0, 0, -1)
		} else {
			gl.Normal3f(0, 0, 1)
		}
		gl.Translatef(0, 0, h)
		Circle(r, slices, solid)
	}
}
예제 #3
0
파일: game.go 프로젝트: jaredly/rocks
func drawMatrix(m *[][]Point, xby, yby gl.Float) {
	for x, row := range *m {
		for y, p := range row {
			UseColor(PointColor(p))
			// fmt.Println(p, PointColor(p))
			// gl.Color4f(1, 0, 0, 1)
			gl.Vertex2f(gl.Float(x)*xby, gl.Float(y)*yby)
		}
	}
}
예제 #4
0
/* Updates o's position using its movement function.

The movemet function looks something like
	(x,y) = (f(t),g(t)) where for elliptic orbits

	f = Acos(t)
	g = Bsin(t)
*/
func PlanetOrbit(o *data.Planet, t float64) {
	A := o.OrbitParam1
	B := o.OrbitParam2
	C := o.OrbitParam3

	x0 := o.OrbitParam4
	y0 := o.OrbitParam5

	o.AbsMove(gl.Float(A*math.Sin(t*C)+x0), gl.Float(B*math.Cos(t*C)+y0))
}
예제 #5
0
파일: shader.go 프로젝트: dgthunder/glop
func SetUniform4F(shader, variable string, vs []float32) error {
	prog, ok := shader_progs[shader]
	if !ok {
		return shaderError(fmt.Sprintf("Tried to set a uniform in an unknown shader '%s'", shader))
	}
	bvariable := []byte(fmt.Sprintf("%s\x00", variable))
	loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0])))
	gl.Uniform4f(loc, gl.Float(vs[0]), gl.Float(vs[1]), gl.Float(vs[2]), gl.Float(vs[3]))
	return nil
}
예제 #6
0
파일: shaders.go 프로젝트: runningwild/jota
func SetUniformV2(shader, variable string, v linear.Vec2) {
	prog, ok := shader_progs[shader]
	if !ok {
		if !warned_names[shader] {
			Warn().Printf("Tried to set a uniform in an unknown shader '%s'", shader)
			warned_names[shader] = true
		}
		return
	}
	bvariable := []byte(fmt.Sprintf("%s\x00", variable))
	loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0])))
	gl.Uniform2f(loc, gl.Float(v.X), gl.Float(v.Y))
}
예제 #7
0
파일: effect.go 프로젝트: velovix/paunch
// SetVariable4f sets a specified variable to the four supplied integers to
// be passed into an effect.
func (effect *Effect) SetVariable4f(variable string, val1 float32, val2 float32, val3 float32, val4 float32) error {

	var currEffect gl.Int
	gl.GetIntegerv(gl.CURRENT_PROGRAM, &currEffect)
	if gl.Uint(currEffect) != effect.program {
		return errors.New("effect is not currently in use")
	}

	effect.checkUniformVariable(variable)

	gl.Uniform4f(effect.uniforms[variable], gl.Float(val1), gl.Float(val2), gl.Float(val3), gl.Float(val4))
	return nil
}
예제 #8
0
파일: shapes.go 프로젝트: knickers/GOpenGL
func Ellipse(rX, rY gl.Float, slices int, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.POLYGON
	}
	res := 2 * math.Pi / float64(slices)
	gl.Begin(gl.Enum(mode))
	gl.Vertex2f(0, 0)
	for a := 0.0; a < 2*math.Pi; a += res {
		gl.Vertex2f(rX*gl.Float(math.Cos(a)), rY*gl.Float(math.Sin(a)))
	}
	gl.End()
}
예제 #9
0
파일: shapes.go 프로젝트: knickers/GOpenGL
func Box(x, y, z float32, solid bool) {
	mode := gl.LINE_LOOP
	if solid {
		mode = gl.QUADS
	}
	X := gl.Float(x) / 2
	Y := gl.Float(y) / 2
	Z := gl.Float(z) / 2
	gl.Begin(gl.Enum(mode))

	gl.Normal3f(0, 0, 1) // Positive Z Face
	gl.Vertex3f(-X, -Y, Z)
	gl.Vertex3f(X, -Y, Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(-X, Y, Z)

	gl.Normal3f(0, 0, -1) // Negative Z Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(-X, Y, -Z)
	gl.Vertex3f(X, Y, -Z)
	gl.Vertex3f(X, -Y, -Z)

	gl.Normal3f(0, 1, 0) // Positive Y Face
	gl.Vertex3f(-X, Y, -Z)
	gl.Vertex3f(-X, Y, Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(X, Y, -Z)

	gl.Normal3f(0, -1, 0) // Negative Y Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(X, -Y, -Z)
	gl.Vertex3f(X, -Y, Z)
	gl.Vertex3f(-X, -Y, Z)

	gl.Normal3f(1, 0, 0) // Positive X Face
	gl.Vertex3f(X, -Y, -Z)
	gl.Vertex3f(X, Y, -Z)
	gl.Vertex3f(X, Y, Z)
	gl.Vertex3f(X, -Y, Z)

	gl.Normal3f(-1, 0, 0) // Negative X Face
	gl.Vertex3f(-X, -Y, -Z)
	gl.Vertex3f(-X, -Y, Z)
	gl.Vertex3f(-X, Y, Z)
	gl.Vertex3f(-X, Y, -Z)

	gl.End()
}
예제 #10
0
파일: main.go 프로젝트: dskinner/cell
func drawScene() {
	fps()
	gl.Clear(gl.COLOR_BUFFER_BIT)

	gl.MatrixMode(gl.PROJECTION)
	gl.LoadIdentity()
	if input.Zoom > 0 {
		gl.Ortho(0, gl.Double(float64(*flagSize)/input.Zoom), gl.Double(float64(*flagSize)/input.Zoom), 0, -1, 1.0)
	}

	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(gl.Float(input.TransX*1), gl.Float(input.TransY*1), 0)
	drawGrid()
	drawCells()
}
예제 #11
0
파일: game.go 프로젝트: jaredly/rocks
func PointColor(p Point) Color {
	n := gl.Float(float64(p.Intensity) / 10.0)
	/*
	  if p.Color == WHITE {
	    return Color{1.0, 1.0, 1.0, 1}
	  }
	  if p.Color == RED {
	    return Color{1, 1-n, 1-n, 1}
	  }
	  if p.Color == GREEN {
	    return Color{1-n, 1, 1-n, 1}
	  }
	  return Color{1-n, 1-n, 1, 1}
	*/
	if p.Color == WHITE {
		return Color{0, 0, 0, 1}
	}
	if p.Color == RED {
		return Color{n, 0, 0, 1}
	}
	if p.Color == GREEN {
		return Color{0, n, 0, 1}
	}
	return Color{0, 0, n, 1}
}
예제 #12
0
func factor(t time.Time, tc0 time.Time, tc1 time.Time) gl.Float {
	num := t.Sub(tc0)
	den := tc1.Sub(tc0)
	res := num.Seconds() / den.Seconds()
	res = math.Max(res, 0)
	res = math.Min(res, 1)
	return gl.Float(res)
}
예제 #13
0
파일: shaders.go 프로젝트: runningwild/jota
func SetUniformV2Array(shader, variable string, vs []linear.Vec2) {
	prog, ok := shader_progs[shader]
	if !ok {
		if !warned_names[shader] {
			Warn().Printf("Tried to set a uniform in an unknown shader '%s'", shader)
			warned_names[shader] = true
		}
		return
	}
	bvariable := []byte(fmt.Sprintf("%s\x00", variable))
	loc := gl.GetUniformLocation(prog, (*gl.Char)(unsafe.Pointer(&bvariable[0])))
	var fs []gl.Float
	for i := range vs {
		fs = append(fs, gl.Float(vs[i].X))
		fs = append(fs, gl.Float(vs[i].Y))
	}
	gl.Uniform2fv(loc, gl.Sizei(len(vs)), (*gl.Float)(unsafe.Pointer(&fs[0])))
}
예제 #14
0
파일: matrix.go 프로젝트: drasich/ridley
func (m *Matrix3) toGLFloat() Matrix3GLFloat {
	var glm Matrix3GLFloat

	for i := range m {
		glm[i] = gl.Float(m[i])
	}

	return glm
}
예제 #15
0
파일: main.go 프로젝트: dskinner/cell
func drawCells() {

	if input.Zoom > 0 {
		gl.PointSize(gl.Float(float64(Width) / float64(*flagSize) * input.Zoom))
	}

	gl.Color4f(1, 1, 1, 1)
	gl.Enable(gl.POINT_SMOOTH)
	gl.Begin(gl.POINTS)

	for i, j := 0, 0; i < (life.Size * life.Size); i, j = i+life.Size, j+1 {
		for k, v := range life.Cells[i : i+life.Size] {
			if v {
				gl.Vertex2f(gl.Float(k), gl.Float(j))
			}
		}
	}

	gl.End()
	gl.Disable(gl.POINT_SMOOTH)
}
예제 #16
0
파일: input.go 프로젝트: shenyp09/mx3
// Set the GL modelview matrix to match view position and orientation.
func UpdateViewpos() {
	gl.MatrixMode(gl.MODELVIEW)
	gl.LoadIdentity()
	gl.Translatef(gl.Float(Viewpos[0]), gl.Float(Viewpos[1]), gl.Float(Viewpos[2]))
	gl.Rotatef(gl.Float(Rot[0]*2), 1, 0, 0)
	gl.Rotatef(gl.Float(Rot[1]*2), 0, 1, 0)
	gl.Rotatef(gl.Float(Rot[2]*2), 0, 0, 1)
}
예제 #17
0
파일: main.go 프로젝트: dskinner/cell
func drawGrid() {
	gl.Color4f(0.2, 0.2, 0.2, 1)
	gl.Begin(gl.LINES)
	for i := -0.5; i < Width; i += 1 {
		gl.Vertex2f(gl.Float(-0.5), gl.Float(i))
		gl.Vertex2f(gl.Float(life.Size), gl.Float(i))

		gl.Vertex2f(gl.Float(i), -0.5)
		gl.Vertex2f(gl.Float(i), gl.Float(life.Size))
	}
	gl.End()
}
예제 #18
0
파일: gomandel.go 프로젝트: nsf/gomandel
func drawQuad(x, y, w, h int, u, v, u2, v2 float32) {
	gl.Begin(gl.QUADS)

	gl.TexCoord2f(gl.Float(u), gl.Float(v))
	gl.Vertex2i(gl.Int(x), gl.Int(y))

	gl.TexCoord2f(gl.Float(u2), gl.Float(v))
	gl.Vertex2i(gl.Int(x+w), gl.Int(y))

	gl.TexCoord2f(gl.Float(u2), gl.Float(v2))
	gl.Vertex2i(gl.Int(x+w), gl.Int(y+h))

	gl.TexCoord2f(gl.Float(u), gl.Float(v2))
	gl.Vertex2i(gl.Int(x), gl.Int(y+h))

	gl.End()
}
예제 #19
0
파일: Go.go 프로젝트: ReneSac/ParticleBench
func renderPts() {
	gl.MatrixMode(gl.MODELVIEW)
	for i := minPt; i <= maxPt; i++ {
		if Pts[i].is == false {
			continue
		}
		pt := &Pts[i]
		gl.PopMatrix()
		gl.PushMatrix()
		gl.Translatef(gl.Float(pt.X), gl.Float(pt.Y), -gl.Float(pt.Z))
		gl.Scalef(gl.Float(pt.R*2), gl.Float(pt.R*2), gl.Float(pt.R*2))
		gl.DrawArrays(gl.QUADS, 0, 24)
	}
}
예제 #20
0
func DrawStarTex(t *data.Star) {

	// Find the center point of the texture to rotate around
	xav := (t.X1 + t.X2) / 2
	yav := (t.Y1 + t.Y2) / 2

	//Translate there, rotate, translate back
	gl.MatrixMode(gl.MODELVIEW)
	gl.Translatef(xav, yav, 0)
	gl.Rotatef(gl.Float(t.Theta), 0, 0, 1)
	gl.Translatef(-xav, -yav, 0)

	//Bind our texture to be drawn by id
	gl.Color3f(1, 1, 1)
	gl.Enable(gl.TEXTURE_2D)
	gl.BindTexture(gl.TEXTURE_2D, t.TexId)

	// Draw a rectangle with the texture stretched to the corners
	gl.Begin(gl.QUADS)

	// Stretch the texture to its 4 corners.
	gl.TexCoord2d(0, 0)
	gl.Vertex2f(t.X1, t.Y1)

	gl.TexCoord2d(0, 1)
	gl.Vertex2f(t.X1, t.Y2)

	gl.TexCoord2d(1, 1)
	gl.Vertex2f(t.X2, t.Y2)

	gl.TexCoord2d(1, 0)
	gl.Vertex2f(t.X2, t.Y1)

	gl.End()

	// Unbind the texture in case something else wants to draw
	gl.Disable(gl.TEXTURE_2D)

	// Reset the matrix
	gl.LoadIdentity()

}
예제 #21
0
파일: poly.go 프로젝트: shenyp09/mx3
// Wraps gl.Normal3f
func Normal3f(x, y, z float32) {
	gl.Normal3f(gl.Float(x), gl.Float(y), gl.Float(z))
}
예제 #22
0
파일: draw.go 프로젝트: velovix/paunch
// SetClearColor sets the color the screen will become after a call to the
// Clear function.
func SetClearColor(r uint8, g uint8, b uint8) {

	gl.ClearColor(gl.Float(r)/255, gl.Float(g)/255, gl.Float(b)/255, 1.0)
}
예제 #23
0
func (mr *ModelReader) readModel(path string, m *Model) {

	var num uint16
	mr.readuint16(&num)

	for i := 0; i < int(num); i++ {
		var x, y, z float32
		mr.readfloat32(&x)
		mr.readfloat32(&y)
		mr.readfloat32(&z)

		m.vertices = append(m.vertices, gl.Float(x), gl.Float(y), gl.Float(z))
		//fmt.Printf("vertices %f, %f, %f \n", x, y, z)
	}
	//fmt.Printf("m.vertices size %d \n", len(m.vertices))

	var faces uint16
	mr.readuint16(&faces)
	//fmt.Println("nb faces  : ", faces)

	for i := 0; i < int(faces); i++ {
		var x, y, z uint16
		mr.readuint16(&x)
		mr.readuint16(&y)
		mr.readuint16(&z)

		m.indices = append(m.indices, gl.Uint(x), gl.Uint(y), gl.Uint(z))
		//fmt.Printf("face indices :%d, %d, %d \n", x, y, z)
	}

	var normals_num uint16
	mr.readuint16(&normals_num)

	for i := 0; i < int(normals_num); i++ {
		var x, y, z float32
		mr.readfloat32(&x)
		mr.readfloat32(&y)
		mr.readfloat32(&z)

		m.normals = append(m.normals, gl.Float(x), gl.Float(y), gl.Float(z))
		//fmt.Printf("normal %f, %f, %f \n", x, y, z)
	}

	var uvs_num uint16
	mr.readuint16(&uvs_num)
	//fmt.Printf("uvs num  %d \n", uvs_num)

	m.has_uv = uvs_num > 0

	if m.has_uv {
		for i := 0; i < int(uvs_num); i++ {
			var x, y float32
			mr.readfloat32(&x)
			mr.readfloat32(&y)

			m.uvs = append(m.uvs, gl.Float(x), gl.Float(y))
			//fmt.Printf("uvs %f, %f \n", x, y)
		}
	}

}
예제 #24
0
func (w *glfwBackend) SetScreenColor(color RGB) {
	r := gl.Float(float64(color.R) / 255.0)
	g := gl.Float(float64(color.G) / 255.0)
	b := gl.Float(float64(color.B) / 255.0)
	gl.ClearColor(r, g, b, gl.Float(1.0))
}
예제 #25
0
파일: poly.go 프로젝트: shenyp09/mx3
// Wraps gl.Vertex3f
func Vertex3f(x, y, z float32) {
	gl.Vertex3f(gl.Float(x), gl.Float(y), gl.Float(z))
}