Ejemplo n.º 1
0
Archivo: ovr.go Proyecto: krux02/libovr
func c_fovPort(that FovPort) (this C.ovrFovPort) {
	this.DownTan = C.float(that.DownTan)
	this.LeftTan = C.float(that.LeftTan)
	this.RightTan = C.float(that.RightTan)
	this.UpTan = C.float(that.UpTan)
	return
}
Ejemplo n.º 2
0
// Image returns image for given page number
func (f *Document) Image(page int) (image.Image, error) {
	var ctm C.fz_matrix
	C.fz_scale(&ctm, C.float(4.0), C.float(4.0))

	cs := C.fz_device_rgb(f.ctx)
	defer C.fz_drop_colorspace(f.ctx, cs)

	pixmap := C.fz_new_pixmap_from_page_number(f.ctx, f.doc, C.int(page), &ctm, cs)
	if pixmap == nil {
		return nil, errors.New("fitz: cannot create pixmap")
	}
	defer C.fz_drop_pixmap(f.ctx, pixmap)

	var bbox C.fz_irect
	C.fz_pixmap_bbox(f.ctx, pixmap, &bbox)

	pixels := C.fz_pixmap_samples(f.ctx, pixmap)
	if pixels == nil {
		return nil, errors.New("fitz: cannot get pixmap samples")
	}

	rect := image.Rect(int(bbox.x0), int(bbox.y0), int(bbox.x1), int(bbox.y1))
	bytes := C.GoBytes(unsafe.Pointer(pixels), 4*bbox.x1*bbox.y1)
	img := &image.RGBA{bytes, 4 * rect.Max.X, rect}

	return img, nil
}
Ejemplo n.º 3
0
func TextField(x, y, w, h int, corners CornerFlags, state WidgetState, label string, cstart, cend int) {
	clabel := C.CString(label)
	defer C.free(unsafe.Pointer(clabel))
	C.bndTextField(vg, C.float(x), C.float(y), C.float(w), C.float(h),
		C.int(corners), C.BNDwidgetState(state), -1, clabel,
		C.int(cstart), C.int(cend))
}
Ejemplo n.º 4
0
func (v *Vector) toC() C.FMOD_VECTOR {
	var cv C.FMOD_VECTOR
	cv.x = C.float(v.X)
	cv.y = C.float(v.Y)
	cv.z = C.float(v.Z)
	return cv
}
Ejemplo n.º 5
0
Archivo: filter.go Proyecto: jlep/steps
func (f *Filter) madgwick(timestamp int64, values []float32) {
	C.madgwick_update_array(
		f.orientation, C.float(sampleFreq), C.float(beta),
		(*_Ctype_float)(&values[0]))

	// quaternion slice
	o := f.orientation
	q := []float32{
		float32(o.q0),
		float32(o.q1),
		float32(o.q2),
		float32(o.q3),
	}
	q1 := float64(o.q0)
	q2 := float64(o.q1)
	q3 := float64(o.q2)
	q4 := float64(o.q3)

	// euler angles in radians (madgwick 2010)
	z := math.Atan2(2*q2*q3-2*q1*q4, 2*q1*q1+2*q2*q2-1) * rad2deg
	y := -math.Asin(2*q2*q4+2*q1*q3) * rad2deg
	x := math.Atan2(2*q3*q4-2*q1*q2, 2*q1*q1+2*q4*q4-1) * rad2deg
	e := []float64{z, y, x}

	if false {
		log.Println("qtn", timestamp, q)
		log.Println("eul", timestamp, e)
	}

	broadcast(timestamp, "qtn", q)
}
Ejemplo n.º 6
0
// DrawRectAt draws a portion of the image specified w
// at the specified position.
func (img *Image) DrawRectAt(rx, ry, rw, rh, x, y int) {
	C.textureDraw(img.id,
		C.int(img.W), C.int(img.H),
		C.int(rx), C.int(ry),
		C.int(rw), C.int(rh),
		C.float(x), C.float(y))
}
Ejemplo n.º 7
0
Archivo: audio.go Proyecto: num5/steven
func SetListenerDirection(x, y, z float32) {
	C.sfListener_setDirection(C.sfVector3f{
		C.float(x),
		C.float(y),
		C.float(z),
	})
}
Ejemplo n.º 8
0
Archivo: audio.go Proyecto: num5/steven
func (s Sound) SetPosition(x, y, z float32) {
	C.sfSound_setPosition(s.internal, C.sfVector3f{
		C.float(x),
		C.float(y),
		C.float(z),
	})
}
Ejemplo n.º 9
0
func PickRay(cameraNode H3DNode, nwx float32, nwy float32, ox *float32, oy *float32, oz *float32,
	dx *float32, dy *float32, dz *float32) {
	C.h3dutPickRay(C.H3DNode(cameraNode), C.float(nwx), C.float(nwy), (*C.float)(unsafe.Pointer(ox)),
		(*C.float)(unsafe.Pointer(oy)), (*C.float)(unsafe.Pointer(oz)),
		(*C.float)(unsafe.Pointer(dx)), (*C.float)(unsafe.Pointer(dy)),
		(*C.float)(unsafe.Pointer(dz)))
}
Ejemplo n.º 10
0
// \brief Change a 3-components vector parameter of a shader
// \a name is the name of the variable to change in the shader.
// The corresponding parameter in the shader must be a 3x1 vector
// (vec3 GLSL type).
// Example:
// \code
// uniform vec3 myparam; // this is the variable in the shader
// \endcode
// \code
// sfShader_setFloat3Parameter(shader, "myparam", 5.2f, 6.0f, -8.1f);
// \endcode
// \param shader Shader object
// \param name   Name of the parameter in the shader
// \param x      First component of the value to assign
// \param y      Second component of the value to assign
// \param z      Third component of the value to assign
// void sfShader_setFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z);
func (self Shader) SetFloat3Parameter(name string, x, y, z float32) {
	n := C.CString(name)
	x1 := C.float(x)
	y1 := C.float(y)
	z1 := C.float(z)
	C.sfShader_setFloat3Parameter(self.Cref, n, x1, y1, z1)
}
Ejemplo n.º 11
0
func (b *Bitmap) DrawTintedRotated(cx, cy, dx, dy, angle float32, flags int, color Color) {

	C.al_draw_tinted_rotated_bitmap((*C.ALLEGRO_BITMAP)(b), (C.ALLEGRO_COLOR)(color),
		C.float(cx), C.float(cy),
		C.float(dx), C.float(dy), C.float(angle), C.int(flags))

}
Ejemplo n.º 12
0
func (b *Bitmap) DrawRotated(cx, cy, dx, dy, angle float32, flags int) {

	C.al_draw_rotated_bitmap((*C.ALLEGRO_BITMAP)(b),
		C.float(cx), C.float(cy), C.float(dx), C.float(dy),
		C.float(angle), C.int(flags))

}
Ejemplo n.º 13
0
Archivo: ovr.go Proyecto: krux02/libovr
// Used to generate projection from ovrEyeDesc::Fov.
func MatrixProjection(fov FovPort, znear, zfar float32, rightHanded bool) Matrix4f {
	if rightHanded {
		return matrix4f(C.ovrMatrix4f_Projection(c_fovPort(fov), C.float(znear), C.float(zfar), 1))
	} else {
		return matrix4f(C.ovrMatrix4f_Projection(c_fovPort(fov), C.float(znear), C.float(zfar), 0))
	}
}
Ejemplo n.º 14
0
Archivo: ovr.go Proyecto: krux02/libovr
func c_quatf(that Quatf) (this C.ovrQuatf) {
	this.x = C.float(that.X)
	this.y = C.float(that.Y)
	this.z = C.float(that.Z)
	this.w = C.float(that.W)
	return
}
Ejemplo n.º 15
0
func (f *Font) DrawJustified(color Color, x1, x2, y, diff float32, flags int, text string) {
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))

	C.al_draw_justified_text((*C.ALLEGRO_FONT)(f), C.ALLEGRO_COLOR(color),
		C.float(x1), C.float(x2), C.float(y), C.float(diff), C.int(flags), ctext)

}
Ejemplo n.º 16
0
// \brief Change a 4-components vector parameter of a shader
// \a name is the name of the variable to change in the shader.
// The corresponding parameter in the shader must be a 4x1 vector
// (vec4 GLSL type).
// Example:
// \code
// uniform vec4 myparam; // this is the variable in the shader
// \endcode
// \code
// sfShader_setFloat4Parameter(shader, "myparam", 5.2f, 6.0f, -8.1f, 0.4f);
// \endcode
// \param shader Shader object
// \param name   Name of the parameter in the shader
// \param x      First component of the value to assign
// \param y      Second component of the value to assign
// \param z      Third component of the value to assign
// \param w      Fourth component of the value to assign
// void sfShader_setFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w);
func (self Shader) Setfloat4parameter(name string, x, y, z, w float32) {
	n := C.CString(name)
	x1 := C.float(x)
	y1 := C.float(y)
	z1 := C.float(z)
	w1 := C.float(w)
	C.sfShader_setFloat4Parameter(self.Cref, n, x1, y1, z1, w1)
}
Ejemplo n.º 17
0
func SetMaterialUniform(materialRes H3DRes, name string, a float32, b float32,
	c float32, d float32) bool {
	cName := C.CString(name)
	defer C.free(unsafe.Pointer(cName))

	return Bool[int(C.h3dSetMaterialUniform(C.H3DRes(materialRes), cName,
		C.float(a), C.float(b), C.float(c), C.float(d)))]
}
Ejemplo n.º 18
0
func (v *Vector) toCp() **C.FMOD_VECTOR {
	var cv C.FMOD_VECTOR
	cv.x = C.float(v.X)
	cv.y = C.float(v.Y)
	cv.z = C.float(v.Z)
	data := *(**C.FMOD_VECTOR)(unsafe.Pointer(&cv))
	return &data
}
Ejemplo n.º 19
0
Archivo: ovr.go Proyecto: krux02/libovr
// Calculates texture size recommended for rendering one eye within HMD, given FOV cone.
// Higher FOV will generally require larger textures to maintain quality.
//  - pixelsPerDisplayPixel specifies that number of render target pixels per display
//    pixel at center of distortion; 1.0 is the default value. Lower values
//    can improve performance.
func (hmd *Hmd) GetFovTextureSize(eye EyeType, fov FovPort, pixelsPerDisplayPixel float32) Sizei {
	var cFov C.ovrFovPort
	cFov.DownTan = C.float(fov.DownTan)
	cFov.LeftTan = C.float(fov.LeftTan)
	cFov.RightTan = C.float(fov.RightTan)
	cFov.UpTan = C.float(fov.UpTan)
	return sizei(C.ovrHmd_GetFovTextureSize(hmd.cptr(), C.ovrEyeType(eye), cFov, C.float(pixelsPerDisplayPixel)))
}
Ejemplo n.º 20
0
func (f *Font) Draw(color Color, x, y float32, flags int, text string) {
	ctext := C.CString(text)
	defer C.free(unsafe.Pointer(ctext))

	C.al_draw_text((*C.ALLEGRO_FONT)(f), (C.ALLEGRO_COLOR)(color),
		C.float(x), C.float(y), C.int(flags), ctext)

}
Ejemplo n.º 21
0
Archivo: pplot.go Proyecto: DaviWei/iup
func Transform(ih *iup.Ihandle, x, y float64) (int, int) {
	cIX := new(C.int)
	cIY := new(C.int)

	C.IupPPlotTransform(ih.C(), C.float(x), C.float(y), cIX, cIY)

	return int(*cIX), int(*cIY)
}
Ejemplo n.º 22
0
Archivo: ovr.go Proyecto: postfix/ovr
func (fov FovPort) toC() C.ovrFovPort {
	return C.ovrFovPort{
		UpTan:    C.float(fov.UpTan),
		DownTan:  C.float(fov.DownTan),
		LeftTan:  C.float(fov.LeftTan),
		RightTan: C.float(fov.RightTan),
	}
}
Ejemplo n.º 23
0
// Pushes a new Go closure onto the stack.
//
// When a Go function is created, it is possible to associate some
// values with it, thus creating a Go closure; these values are then
// accessible to the function whenever it is called. To associate values
// with a Go function, first these values should be pushed onto the stack
// (when there are multiple values, the first value is pushed first). Then
// Pushclosure is called to create and push the Go function onto the
// stack, with the argument n telling how many values should be associated
// with the function. Pushclosure also pops these values from the stack.
//
// The maximum value for n is 254.
func (this *State) Pushclosure(fn Gofunction, n int) {
	if !this.Checkstack(1) {
		panic("STATE: unable to grow lua_state stack")
	}

	C.lua_pushnumber(this.luastate, C.lua_Number(C.float(float64(this.gvindex))))
	C.lua_pushnumber(this.luastate, C.lua_Number(C.float(float64(Gvregistry.AddValue(fn)))))
	C.goluajit_pushclosure(this.luastate, C.int(n+2))
}
Ejemplo n.º 24
0
Archivo: ovr.go Proyecto: postfix/ovr
func (data SensorData) toC() C.ovrSensorData {
	return C.ovrSensorData{
		Accelerometer: data.Accelerometer.toC(),
		Gyro:          data.Gyro.toC(),
		Magnetometer:  data.Magnetometer.toC(),
		Temperature:   C.float(data.Temperature),
		TimeInSeconds: C.float(data.TimeInSeconds),
	}
}
Ejemplo n.º 25
0
// Renderer (https://wiki.libsdl.org/SDL_RenderSetScale)
func (renderer *Renderer) SetScale(scaleX, scaleY float32) error {
	_scaleX := C.float(scaleX)
	_scaleY := C.float(scaleY)
	_ret := C.SDL_RenderSetScale(renderer.cptr(), _scaleX, _scaleY)
	if _ret < 0 {
		return GetError()
	}
	return nil
}
Ejemplo n.º 26
0
// Pushes a new Go closure onto the stack.
//
// When a Go function is created, it is possible to associate some
// values with it, thus creating a Go closure; these values are then
// accessible to the function whenever it is called. To associate values
// with a Go function, first these values should be pushed onto the stack
// (when there are multiple values, the first value is pushed first). Then
// Pushclosure is called to create and push the Go function onto the
// stack, with the argument n telling how many values should be associated
// with the function. Pushclosure also pops these values from the stack.
//
// The maximum value for n is 254.
func (this *State) Pushclosure(fn lua.Function, n int) {
	if !this.Checkstack(1) {
		panic("STATE: unable to grow lua_state stack")
	}

	C.lua_pushnumber(this.luastate, C.lua_Number(C.float(float64(this.grindex))))
	C.lua_pushnumber(this.luastate, C.lua_Number(C.float(float64(lua.GlobalRegistry.AddValue(fn)))))
	C.lua51_pushclosure(this.luastate, C.int(n+2))
}
Ejemplo n.º 27
0
func SetGamma(red, green, blue float32) error {
	c_red := C.float(red)
	c_green := C.float(green)
	c_blue := C.float(blue)
	ret := C.SDL_SetGamma(c_red, c_green, c_blue)
	if ret == 0 {
		return nil
	}
	return GetError()
}
Ejemplo n.º 28
0
/******* Rotate *******/
func (img *Image) RotateTo(dest *Image, angle float64) {
	dest.InitializeAs(img)

	center := C.CvPoint2D32f{C.float(img.Size().Width / 2), C.float(img.Size().Height / 2)}
	var rot *C.CvMat = C.cvCreateMat(2, 3, C.CV_32F)
	defer C.cvReleaseMat(&rot)
	C.cv2DRotationMatrix(center, C.double(angle), C.double(1.0), rot)

	C.cvWarpAffine(img.ptr, dest.ptr, rot, C.CV_INTER_LINEAR+C.CV_WARP_FILL_OUTLIERS, C.cvScalarAll(C.double(0.0)))
}
Ejemplo n.º 29
0
func NewFloatRect(left, top, width, height float32) FloatRect {
	fr := C.sfFloatRect{
		C.float(left),
		C.float(top),
		C.float(width),
		C.float(height),
	}

	//func SetFinalizer(x, f interface{})
	return FloatRect{&fr}
}
Ejemplo n.º 30
0
func (g Generator) GenerateNormal(output uintptr, n int64, mean, stddev float32) {
	err := Status(C.curandGenerateNormal(
		C.curandGenerator_t(unsafe.Pointer(uintptr(g))),
		(*C.float)(unsafe.Pointer(uintptr(output))),
		C.size_t(n),
		C.float(mean),
		C.float(stddev)))
	if err != SUCCESS {
		panic(err)
	}
}