Golang float示例

说明

golang float示例是从最受好评的开源项目中提取的实现代码,你可以参考下面示例的使用方式。

编程语言: Golang

命名空间/包名称: C

示例#1
文件: ovr.go 项目: 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
}

示例#2
文件: fitz.go 项目: lambdaX/go-fitz

// 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
}

示例#3
文件: blendish.go 项目: james4k/exp

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))
}

示例#4
文件: vector.go 项目: theaidem/fmod

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
}

示例#5
文件: filter.go 项目: 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)
}

示例#6
文件: image.go 项目: PragmaticCypher/gogol

// 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))
}

示例#7
文件: audio.go 项目: num5/steven

func SetListenerDirection(x, y, z float32) {
	C.sfListener_setDirection(C.sfVector3f{
		C.float(x),
		C.float(y),
		C.float(z),
	})
}

示例#8
文件: audio.go 项目: 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),
	})
}

示例#9
文件: horde3dUtils.go 项目: floffel03/gohorde

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)))
}

示例#10
文件: gfx-shader.go 项目: drhodes/go-sfml

// \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)
}

示例#11
文件: graphics.go 项目: bluepeppers/allegro

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))

}

示例#12
文件: graphics.go 项目: bluepeppers/allegro

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))

}

示例#13
文件: ovr.go 项目: 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))
	}
}

示例#14
文件: ovr.go 项目: 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
}

示例#15
文件: font.go 项目: bluepeppers/allegro

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)

}

示例#16
文件: gfx-shader.go 项目: drhodes/go-sfml

// \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)
}

示例#17
文件: horde3d.go 项目: floffel03/gohorde

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)))]
}

示例#18
文件: vector.go 项目: theaidem/fmod

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
}

示例#19
文件: ovr.go 项目: 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)))
}

示例#20
文件: font.go 项目: bluepeppers/allegro

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)

}

示例#21
文件: pplot.go 项目: 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)
}

示例#22
文件: ovr.go 项目: 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),
	}
}

示例#23
文件: State.go 项目: rdlaitila/leaf

// 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))
}

示例#24
文件: ovr.go 项目: 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),
	}
}

示例#25
文件: render.go 项目: emlai/go-sdl2

// 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
}

示例#26
文件: State.go 项目: rdlaitila/leaf

// 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))
}

示例#27
文件: video.go 项目: badgerodon/go

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()
}

示例#28
文件: image.go 项目: mottalli/go-cv

/******* 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)))
}

示例#29
文件: gfx-rect.go 项目: acieroid/go-sfml

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}
}

示例#30
文件: generator.go 项目: LStoleriu/hotspin

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)
	}
}

展开阅读全文