//void glMap1d (GLenum target, float64 u1, float64 u2, int stride, int order, const float64 *points) func Map1d(target GLenum, u1 float64, u2 float64, stride int, order int, points []float64) { if len(points) == 0 { panic("Invalid points size") } C.glMap1d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2), C.GLint(stride), C.GLint(order), (*C.GLdouble)(&points[0])) }
func Perspective(fovy, aspect, zNear, zFar float64) { C.gluPerspective( C.GLdouble(fovy), C.GLdouble(aspect), C.GLdouble(zNear), C.GLdouble(zFar), ) }
// Project object coordinates to screen coordinates. func Project(objx, objy, objz float64, model, proj []float64, view []int32) (x, y, z float64) { var wx, wy, wz C.GLdouble C.gluProject( C.GLdouble(objx), C.GLdouble(objy), C.GLdouble(objz), (*C.GLdouble)(&model[0]), (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &wx, &wy, &wz, ) return float64(wx), float64(wy), float64(wz) }
// Project screen coordinates to object coordinates. func Unproject(wx, wy, wz float64, model, proj []float64, view []int32) (objx, objy, objz float64) { var ox, oy, oz C.GLdouble C.gluUnProject( C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), (*C.GLdouble)(&model[0]), (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), &ox, &oy, &oz, ) return float64(ox), float64(oy), float64(oz) }
//void glMap2d (GLenum target, float64 u1, float64 u2, int ustride, int uorder, float64 v1, float64 v2, int vstride, int vorder, const float64 *points) func Map2d(target GLenum, u1 float64, u2 float64, ustride int, uorder int, v1 float64, v2 float64, vstride int, vorder int, points []float64) { if len(points) == 0 { panic("Invalid points size") } C.glMap2d(C.GLenum(target), C.GLdouble(u1), C.GLdouble(u2), C.GLint(ustride), C.GLint(uorder), C.GLdouble(v1), C.GLdouble(v2), C.GLint(vstride), C.GLint(vorder), (*C.GLdouble)(&points[0])) }
func LookAt(eyeX, eyeY, eyeZ, centerX, centerY, centerZ, upX, upY, upZ float64) { C.gluLookAt( C.GLdouble(eyeX), C.GLdouble(eyeY), C.GLdouble(eyeZ), C.GLdouble(centerX), C.GLdouble(centerY), C.GLdouble(centerZ), C.GLdouble(upX), C.GLdouble(upY), C.GLdouble(upZ), ) }
func init() { // right[0], front[1], top[2] = 1.0, 1.0, 1.0 matrix[3][3] = 1. for l := 0; l < MaxL; l++ { lightSource[l] = vect.New() } w := 2.0 * math.Pi / float64(nLamp) sin[0], cos[0] = C.GLdouble(0.0), C.GLdouble(1.0) sin[nLamp], cos[nLamp] = sin[0], cos[0] for g := 1; g < nLamp; g++ { sin[g] = C.GLdouble(math.Sin(float64(g) * w)) cos[g] = C.GLdouble(math.Cos(float64(g) * w)) } sin[nLamp+1], sin[1] = cos[nLamp+1], cos[1] // C.glDepthFunc (C.GL_LESS) // default C.glEnable(C.GL_DEPTH_TEST) C.glShadeModel(C.GL_SMOOTH) for i := 0; i < 3; i++ { lmAmb[i] = C.GLfloat(0.2) } // default: 0.2 lmAmb[3] = C.GLfloat(1.0) // default: 1.0 C.glLightModelfv(C.GL_LIGHT_MODEL_AMBIENT, &lmAmb[0]) for i := 0; i < 3; i++ { mAmbi[i] = C.GLfloat(0.2) } // default: 0.2 mAmbi[3] = C.GLfloat(1.0) // default: 1.0 // C.glLightModelfv (C.GL_LIGHT_MODEL_TWO_SIDE, 1) C.glMaterialfv(C.GL_FRONT_AND_BACK, C.GL_AMBIENT_AND_DIFFUSE, &mAmbi[0]) for i := 0; i < 3; i++ { mDiff[i] = C.GLfloat(0.8) } // default: 0.8 mDiff[3] = C.GLfloat(1.0) // default: 1.0 w = 1. C.glClearDepth(C.GLclampd(w)) // C.glMaterialfv (C.GL_FRONT_AND_BACK, C.GL_DIFFUSE, mDiff) // C.glColorMaterial (C.GL_FRONT_AND_BACK, C.GL_DIFFUSE) // C.glColorMaterial (C.GL_FRONT, C.GL_AMBIENT) C.glColorMaterial(C.GL_FRONT_AND_BACK, C.GL_AMBIENT_AND_DIFFUSE) C.glEnable(C.GL_COLOR_MATERIAL) C.glEnable(C.GL_LIGHTING) initialize() }
func lamp(n uint) { // if !lightInitialized[n] { return } xx, yy, zz := lightSource[n].Coord3() x, y, z := C.GLdouble(xx), C.GLdouble(yy), C.GLdouble(zz) r := C.GLdouble(0.1) C.glBegin(TRIANGLE_FAN) C.glColor3ub(C.GLubyte(lightColour[n].R), C.GLubyte(lightColour[n].G), C.GLubyte(lightColour[n].B)) C.glNormal3d(C.GLdouble(0.0), C.GLdouble(0.0), C.GLdouble(-1.0)) C.glVertex3d(C.GLdouble(x), C.GLdouble(y), C.GLdouble(z+r)) r0 := r * sin[1] z0 := z + r*cos[1] for l := 0; l <= nLamp; l++ { C.glNormal3d(-sin[1]*cos[l], -sin[1]*sin[l], -cos[1]) C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0) } C.glEnd() C.glBegin(QUAD_STRIP) var r1, z1 C.GLdouble for b := 1; b <= nLamp/2-2; b++ { r0, z0 = r*sin[b], z+r*cos[b] r1, z1 = r*sin[b+1], z+r*cos[b+1] for l := 0; l <= nLamp; l++ { C.glNormal3d(-sin[b+1]*cos[l], -sin[b+1]*sin[l], -cos[b+1]) C.glVertex3d(x+r1*cos[l], y+r1*sin[l], z1) C.glNormal3d(-sin[b]*cos[l], -sin[b]*sin[l], -cos[b]) C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0) } } C.glEnd() C.glBegin(TRIANGLE_FAN) C.glNormal3d(0., 0., 1.) C.glVertex3d(x, y, z-r) r0, z0 = r*sin[1], z-r*cos[1] b := nLamp/2 - 1 for l := 0; l <= nLamp; l++ { C.glNormal3d(-sin[b]*cos[l], -sin[b]*sin[l], -cos[b]) C.glVertex3d(x+r0*cos[l], y+r0*sin[l], z0) } C.glEnd() }
func UnProject(winX, winY, winZ float64, model, proj *[16]float64, view *[4]int32) (float64, float64, float64) { var ox, oy, oz C.GLdouble m := (*C.GLdouble)(unsafe.Pointer(model)) p := (*C.GLdouble)(unsafe.Pointer(proj)) v := (*C.GLint)(unsafe.Pointer(view)) C.gluUnProject( C.GLdouble(winX), C.GLdouble(winY), C.GLdouble(winZ), m, p, v, &ox, &oy, &oz, ) return float64(ox), float64(oy), float64(oz) }
func Init(fern float64) { // called by points.Start () // const ( D = 2.0 // -fache Bildschirmbreite nah = C.GLdouble(0.2) ) if !initialized { initialize() } C.glMatrixMode(C.GL_PROJECTION) C.glLoadIdentity() deg := D * math.Atan((0.5/D)/scr.Proportion()) deg /= 0.9 // experimentelle Weitwinkelkorrektur var m [4][4]C.GLdouble m[1][1] = 1.0 / C.GLdouble(math.Tan(deg)) // Cot m[0][0] = m[1][1] / C.GLdouble(scr.Proportion()) // delta:= C.GLdouble(fern) - nah // m[2][2] = - (C.GLdouble(fern) + nah) / delta // m[2][3] = GLdouble(-1.0) // m[3][2] = -2. * nah * C.GLdouble(fern) / delta m[2][2] = C.GLdouble(-1.0) m[2][3] = C.GLdouble(-1.0) m[3][2] = C.GLdouble(-1.0) * nah C.glMultMatrixd(&m[0][0]) // q:= C.GLdouble(0.75) // GLFrustum (-1.0 * nah, 1.0 * nah, -q * nah, q * nah, 1.0 * nah, C.GLdouble(fern)) C.glMatrixMode(C.GL_MODELVIEW) }
func Write0() { // if !initialized { initialize() } if !scr.UnderX() { ker.Stop(pack, 1) } C.glMatrixMode(C.GL_MODELVIEW) C.glLoadIdentity() for i := 0; i < 3; i++ { matrix[i][0] = C.GLdouble(right[i]) matrix[i][1] = C.GLdouble(top[i]) matrix[i][2] = C.GLdouble(-front[i]) } C.glMultMatrixd(&matrix[0][0]) C.glTranslated(C.GLdouble(-eye[0]), C.GLdouble(-eye[1]), C.GLdouble(-eye[2])) C.glClear(C.GL_COLOR_BUFFER_BIT + C.GL_DEPTH_BUFFER_BIT) for n := uint(0); n < MaxL; n++ { if lightInitialized[n] { ActualizeLight(n) } } C.glBegin(POINTS) nn = 0 }
// Project screen coordinates to object coordinates. func Unproject4(wx, wy, wz, clipw float64, model, proj []float64, view []int32, near, far float64) (objx, objy, objz, objw float64) { var ox, oy, oz, ow C.GLdouble C.gluUnProject4( C.GLdouble(wx), C.GLdouble(wy), C.GLdouble(wz), C.GLdouble(clipw), (*C.GLdouble)(&model[0]), (*C.GLdouble)(&proj[0]), (*C.GLint)(&view[0]), C.GLdouble(near), C.GLdouble(far), &ox, &oy, &oz, &ow, ) return float64(ox), float64(oy), float64(oz), float64(ow) }
//void glTexGend (GLenum coord, GLenum pname, float64 param) func TexGend(coord GLenum, pname GLenum, param float64) { C.glTexGend(C.GLenum(coord), C.GLenum(pname), C.GLdouble(param)) }
func Ortho2D(left, right, bottom, top float64) { C.gluOrtho2D(C.GLdouble(left), C.GLdouble(right), C.GLdouble(bottom), C.GLdouble(top)) }
func PickMatrix(x, y, delx, dely float64, viewport []int32) { C.gluPickMatrix(C.GLdouble(x), C.GLdouble(y), C.GLdouble(delx), C.GLdouble(dely), (*C.GLint)(&viewport[0])) }
func WireCube(size gl.GLdouble) { C.glutWireCube(C.GLdouble(size)) }
func SolidCube(size gl.GLdouble) { C.glutSolidCube(C.GLdouble(size)) }
func WireTorus(innerRadius, outerRadius gl.GLdouble, nsides, rings gl.GLint) { C.glutWireTorus(C.GLdouble(innerRadius), C.GLdouble(outerRadius), C.GLint(nsides), C.GLint(rings)) }
// Set a property of the tesselator. func (tess *Tesselator) Property(which gl.GLenum, data float64) { C.gluTessProperty(tess.tess, C.GLenum(which), C.GLdouble(data)) }
func Cylinder(q unsafe.Pointer, base, top, height float32, slices, stacks int) { C.gluCylinder((*[0]byte)(q), C.GLdouble(base), C.GLdouble(top), C.GLdouble(height), C.GLint(slices), C.GLint(stacks)) }
func Disk(q unsafe.Pointer, inner, outer float32, slices, loops int) { C.gluDisk((*[0]byte)(q), C.GLdouble(inner), C.GLdouble(outer), C.GLint(slices), C.GLint(loops)) }
// And, of course: func SolidTeapot(size gl.GLdouble) { C.glutSolidTeapot(C.GLdouble(size)) }
//void glTexCoord3d (float64 s, float64 t, float64 r) func TexCoord3d(s float64, t float64, r float64) { C.glTexCoord3d(C.GLdouble(s), C.GLdouble(t), C.GLdouble(r)) }
// Set the normal of the plane onto which points are projected onto before tesselation. func (tess *Tesselator) Normal(valueX, valueY, valueZ float64) { cx := C.GLdouble(valueX) cy := C.GLdouble(valueY) cz := C.GLdouble(valueZ) C.gluTessNormal(tess.tess, cx, cy, cz) }
//void glTexCoord1d (float64 s) func TexCoord1d(s float64) { C.glTexCoord1d(C.GLdouble(s)) }
func WireCone(base, height gl.GLdouble, slices, stacks gl.GLint) { C.glutWireCone(C.GLdouble(base), C.GLdouble(height), C.GLint(slices), C.GLint(stacks)) }
//void glTexCoord2d (float64 s, float64 t) func TexCoord2d(s float64, t float64) { C.glTexCoord2d(C.GLdouble(s), C.GLdouble(t)) }
func WireTeapot(size gl.GLdouble) { C.glutWireTeapot(C.GLdouble(size)) }
//void glTexCoord4d (float64 s, float64 t, float64 r, float64 q) func TexCoord4d(s float64, t float64, r float64, q float64) { C.glTexCoord4d(C.GLdouble(s), C.GLdouble(t), C.GLdouble(r), C.GLdouble(q)) }
func Sphere(q unsafe.Pointer, radius float32, slices, stacks int) { C.gluSphere((*[0]byte)(q), C.GLdouble(radius), C.GLint(slices), C.GLint(stacks)) }