本文整理汇总了C++中roundf函数的典型用法代码示例。如果您正苦于以下问题:C++ roundf函数的具体用法?C++ roundf怎么用?C++ roundf使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了roundf函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: setWidth
void RenderSVGForeignObject::updateLogicalWidth()
{
// FIXME: Investigate in size rounding issues
// FIXME: Remove unnecessary rounding when layout is off ints: webkit.org/b/63656
setWidth(static_cast<int>(roundf(m_viewport.width())));
}
开发者ID:eocanha,项目名称:webkit,代码行数:6,代码来源:RenderSVGForeignObject.cpp
示例2: roundf
void GLTouchScreen::analyze(float x, float y) {
//x = roundf(x * width / context->width);
//y = roundf(y * height / context->height);
if (clientRatio > viewRatio) { // Экран уже чем треубется
x = roundf(x * clientWidth / viewWidth);
y = roundf((((y / viewHeight) - 0.5f) * clientRatio / viewRatio + 0.5f) * clientHeight);
} else {
x = roundf((((x / viewWidth) - 0.5f) * viewRatio / clientRatio + 0.5f) * clientWidth);
y = roundf(y * clientHeight / viewHeight);
}
recordTrack(x, y, true);
if (touchTimeout != 0) {
touchTimeout = 0;
}
if (touchCancel) {
touchCancel = false;
return;
}
int32_t listlength = touchList.count();
Vec3* list = touchList.items();
if (listlength > 0) {
CString type;
GLfloat x1 = list[0].x;
GLfloat y1 = list[0].y;
GLfloat x2 = list[listlength - 1].x;
GLfloat y2 = list[listlength - 1].y;
if (listlength == 1) {
int32_t count = clickList.count();
if (count > 0) {
GLTouchObject** items = clickList.items();
for (int i = count - 1; i >= 0; i--) {
GLfloat ww = items[i]->w;
GLfloat hh = items[i]->h;
GLfloat xx = items[i]->x;
GLfloat yy = items[i]->y;
if ((x1 >= xx) && (x1 < (xx + ww)) &&
(y1 >= yy) && (y1 < (yy + hh))
) {
type = L"click ";
type += items[i]->name;
if (items[i]->onevent(type, NULL, NULL, NULL, items[i]->userData)) {
break;
}
}
}
}
if (type.m_length == 0)
type = L"none";
} else {
// Определение кругового движения по часовой стрелке или против
GLfloat cx, cy;
{
// Вычисляем центр окружности описывающей точки
GLfloat xmin, xmax, ymin, ymax;
xmin = xmax = x1;
ymin = ymax = y1;
for (int i = 0; i < listlength; i++) {
GLfloat xx = list[i].x;
GLfloat yy = list[i].y;
if (xx < xmin) xmin = xx;
if (xx > xmax) xmax = xx;
if (yy < ymin) ymin = yy;
if (yy > ymax) ymax = yy;
}
cx = (xmin + xmax) / 2.0f;
cy = (ymin + ymax) / 2.0f;
// Вычисляем средний радиус и определяем число смещений по кругу
GLfloat mr = 0; // Средний радиус
GLfloat cw = 0; // Число смещений по часовой стрелке
GLfloat bw = 0; // Число смещений против часовой стрелки
GLfloat ca = 0; // Угол смещения по часовой стрелке
GLfloat ba = 0; // Угол смещения против часовой стрелки
GLfloat lx = x2 - cx;
GLfloat ly = y2 - cy;
GLfloat la = atan2f(ly, lx); // Угол последней точки
for (int i = 0; i < listlength; i++) {
// Координаты относительно центра
GLfloat xx = list[i].x - cx;
GLfloat yy = list[i].y - cy;
// Растояние до точки
GLfloat r = floorf(sqrtf(xx * xx + yy * yy));
// Направление движения по часовой стрелке или против
GLfloat s = lx * yy - ly * xx;
GLfloat na = atan2f(yy, xx);
GLfloat a = (na - la) * 180.0f / (GLfloat)M_PI;
while (a < -180.0f) a += 360.0f;
while (a > 180.0f) a -= 360.0f;
if (i != 0) {
if (s > 0) { cw++; ca += a; }
else if (s < 0) { bw++; ba -= a; }
}
// Кешируем вычисления
list[i].z = r;
//.........这里部分代码省略.........
开发者ID:Jappsy,项目名称:jappsy,代码行数:101,代码来源:uGLTouchScreen.cpp
示例3: gl_raster_font_render_message
static void gl_raster_font_render_message(
gl_raster_t *font, const char *msg, GLfloat scale,
const GLfloat color[4], GLfloat pos_x, GLfloat pos_y,
unsigned text_align)
{
int x, y, delta_x, delta_y;
float inv_tex_size_x, inv_tex_size_y, inv_win_width, inv_win_height;
unsigned i, msg_len_full, msg_len;
GLfloat font_tex_coords[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_vertex[2 * 6 * MAX_MSG_LEN_CHUNK];
GLfloat font_color[4 * 6 * MAX_MSG_LEN_CHUNK];
struct gl_coords coords;
gl_t *gl = font ? font->gl : NULL;
if (!gl)
return;
msg_len_full = strlen(msg);
msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
x = roundf(pos_x * gl->vp.width);
y = roundf(pos_y * gl->vp.height);
delta_x = 0;
delta_y = 0;
switch (text_align)
{
case TEXT_ALIGN_RIGHT:
x -= get_message_width(font, msg);
break;
case TEXT_ALIGN_CENTER:
x -= get_message_width(font, msg) / 2.0;
break;
}
inv_tex_size_x = 1.0f / font->tex_width;
inv_tex_size_y = 1.0f / font->tex_height;
inv_win_width = 1.0f / font->gl->vp.width;
inv_win_height = 1.0f / font->gl->vp.height;
while (msg_len_full)
{
for (i = 0; i < msg_len; i++)
{
int off_x, off_y, tex_x, tex_y, width, height;
const struct font_glyph *glyph =
font->font_driver->get_glyph(font->font_data, (uint8_t)msg[i]);
if (!glyph) /* Do something smarter here ... */
glyph = font->font_driver->get_glyph(font->font_data, '?');
if (!glyph)
continue;
off_x = glyph->draw_offset_x;
off_y = glyph->draw_offset_y;
tex_x = glyph->atlas_offset_x;
tex_y = glyph->atlas_offset_y;
width = glyph->width;
height = glyph->height;
gl_raster_font_emit(0, 0, 1); /* Bottom-left */
gl_raster_font_emit(1, 1, 1); /* Bottom-right */
gl_raster_font_emit(2, 0, 0); /* Top-left */
gl_raster_font_emit(3, 1, 0); /* Top-right */
gl_raster_font_emit(4, 0, 0); /* Top-left */
gl_raster_font_emit(5, 1, 1); /* Bottom-right */
delta_x += glyph->advance_x;
delta_y -= glyph->advance_y;
}
coords.tex_coord = font_tex_coords;
coords.vertex = font_vertex;
coords.color = font_color;
coords.vertices = 6 * msg_len;
coords.lut_tex_coord = gl->coords.lut_tex_coord;
if (font->block)
gl_coord_array_add(&font->block->carr, &coords, coords.vertices);
else
gl_raster_font_draw_vertices(gl, &coords);
msg_len_full -= msg_len;
msg += msg_len;
msg_len = min(msg_len_full, MAX_MSG_LEN_CHUNK);
}
}
开发者ID:ProfessorKaos64,项目名称:RetroArch,代码行数:88,代码来源:gl_raster_font.c
示例4: fillThreeCompBuffer
//.........这里部分代码省略.........
srcRowByteOffset = 0;
dstByteOffset = 0;
while ( sy < srcHeight ) {
amty;
if ( dyrem == 0 ) {
for ( i = 0; i < dstWidth; i++ ) {
row->red[i] = row->green[i] = row->blue[i] = 0;
}
dyrem = srcHeight;
}
if ( syrem < dyrem ) {
amty = syrem;
} else {
amty = dyrem;
}
sx = 0;
dx = 0;
sxrem = 0;
dxrem = srcWidth;
r = 0, g = 0, b = 0;
while ( sx < srcWidth ) {
if ( sxrem == 0 ) {
sxrem = dstWidth;
srcColByteOffset = sx * srcComponents;
r = 0xff & srcBuffer[ srcRowByteOffset + srcColByteOffset++ ];
g = 0xff & srcBuffer[ srcRowByteOffset + srcColByteOffset++ ];
b = 0xff & srcBuffer[ srcRowByteOffset + srcColByteOffset ];
}
int amtx;
if ( sxrem < dxrem ) {
amtx = sxrem;
} else {
amtx = dxrem;
}
mult = ((float)amtx) * amty;
row->red[dx] += mult * r;
row->green[dx] += mult * g;
row->blue[dx] += mult * b;
if ( ( sxrem -= amtx ) == 0 ) {
sx++;
}
if ( ( dxrem -= amtx ) == 0 ) {
dx++;
dxrem = srcWidth;
}
}
if ( ( dyrem -= amty ) == 0 ) {
///////////////////////////////////////////////////////////////////
dstRowByteIndex = 0;
for ( i = 0; i < dstWidth; i++ ) {
mult = (float)srcPixels;
r_int = (int)roundf( row->red[i] / mult );
g_int = (int)roundf( row->green[i] / mult );
b_int = (int)roundf( row->blue[i] / mult );
if ( r_int < 0 ) {
r_int = 0;
} else if ( r_int > 255 ) {
r_int = 255;
}
if ( g_int < 0 ) {
g_int = 0;
} else if ( g_int > 255 ) {
g_int = 255;
}
if ( b_int < 0 ) {
b_int = 0;
} else if ( b_int > 255 ) {
b_int = 255;
}
row_data[dstRowByteIndex++] = (jbyte)r_int;
row_data[dstRowByteIndex++] = (jbyte)g_int;
row_data[dstRowByteIndex++] = (jbyte)b_int;
}
///////////////////////////////////////////////////////////////////
do {
for ( i = 0; i < dstRowByteLength; i++ ) {
dstBuffer[ dstByteOffset++ ] = row_data[i];
}
dy++;
} while ( ( ( syrem -= amty ) >= amty ) && ( amty == srcHeight ) );
} else {
syrem -= amty;
}
if ( syrem == 0 ) {
syrem = dstHeight;
sy++;
srcRowByteOffset += srcWidth * srcComponents;
}
}
///////////////////////////////////////////////////////////////////
free( row_data );
free( row->red );
free( row->green );
free( row->blue );
free( row );
}
开发者ID:Virtual-Light-Company,项目名称:ImageLoader,代码行数:101,代码来源:area_avg_scale_filter.c
示例5: direction
//---------------------------------------------------------------------------
//
// factors the total number of verices in alternating x, y, z, t directions
//
// given: constraints on the blocking entered as an array where
// 0 implies no constraint in that direction and some value n > 0 is a given
// number of blocks in a given direction
//
void Blocking::FactorDims(int *given) {
int rem = tot_b; // unfactored remaining portion of tot_b
int block_dim[DIY_MAX_DIM]; // current block size
int max; // longest remaining direction (0, 1, 2)
int i, j;
// init
for (i = 0; i < dim; i++) {
if (given[i] == 0) {
lat_size[i] = 1;
block_dim[i] = data_size[i];
}
else {
lat_size[i] = given[i];
if (rem % given[i])
#ifdef MAC
fprintf(stderr,"Unable to block the volume with given[%d] = %d "
"dimension. Please provide different 'given' constraints and "
"rerun.\n", i, given[i]);
#else
fprintf(stderr,"Unable to block the volume with given[%d] = %d "
"dimension. Please provide different 'given' constraints and "
"rerun.\n", i, given[i]);
#endif
assert(rem % given[i] == 0);
rem /= given[i];
}
}
// compute factorization of data dimensions into lattice dimensions
while (1) {
// find longest division direction
max = 0;
for(i = 1; i < dim; i++) {
if (given[i] == 0 && block_dim[i] > block_dim[max])
max = i;
}
// smallest factor remaining gets assigned to this direction
for (j = 2; j <= rem; j++) {
if (rem % j == 0) {
lat_size[max] *= j;
block_dim[max] /= j;
rem /= j;
break;
}
}
if (rem == 1)
break;
if (j > rem)
fprintf(stderr,"Unable to block the volume into %d blocks. "
"Please select a different number of blocks and rerun.\n", tot_b);
assert(j <= rem);
}
// sanity check
int prod_blocks = 1;
for (i = 0; i < dim; i++)
prod_blocks *= lat_size[i];
assert(prod_blocks == tot_b);
// block sizes
for(i = 0; i < dim; i++)
block_size[i] = (int)(roundf((float)data_size[i] / (float)lat_size[i]));
// debug
// fprintf(stderr, "block sizes = [ ");
// for (i = 0; i < dim; i++)
// fprintf(stderr, "%d ", block_size[i]);
// fprintf(stderr, "]\n");
}
开发者ID:ChengLiOSU,项目名称:OSUFlow,代码行数:87,代码来源:blocking.cpp
示例6: export_swf_create_layer_elements
gboolean export_swf_create_layer_elements(swf_frame_element *array_start, guint num_frames, layer *this_layer_data, guint layer_depth)
{
// Local variables
gfloat click_duration;
guint click_frames;
gfloat element_x_position_finish = 0;
gfloat element_x_position_increment = 0;
gfloat element_x_position_start = 0;
gfloat element_y_position_finish = 0;
gfloat element_y_position_increment = 0;
gfloat element_y_position_start = 0;
gfloat fade_frame;
gfloat finish_frame;
gint finish_frame_rounded;
guint frame_counter; // Holds the number of frames
GString *layer_name; // The text name for the layer
layer_mouse *mouse_data; // Points to the mouse object data inside the layer
guint loop_counter = 0; // Simple counter used in loops
gint num_displayed_frames;
guint opacity_count; // Used when calculating object opacity
gfloat opacity_step; // Used when calculating object opacity
guint play_click = MOUSE_NONE; // Should a click sound be played?
gfloat scaled_height_ratio; // Used to calculate the final size an object should be scaled to
gfloat scaled_width_ratio; // Used to calculate the final size an object should be scaled to
gfloat start_frame;
guint start_frame_rounded;
gfloat x_position; // Used in calculating layer object position
gfloat y_position; // Used in calculating layer object position
// Initialisation
layer_name = g_string_new(NULL);
g_string_printf(layer_name, "%s%d", "Object", layer_depth);
// Set some basic properties for the layer, across all of its frames
for (frame_counter = 0; frame_counter < num_frames; frame_counter++)
{
array_start[frame_counter].action_this = FALSE;
array_start[frame_counter].object_name = layer_name;
array_start[frame_counter].depth = layer_depth;
array_start[frame_counter].layer_info = this_layer_data;
array_start[frame_counter].is_moving = FALSE;
}
// Calculate the height and width scaling values needed for this swf output
scaled_height_ratio = (gfloat) get_output_height() / (gfloat) get_project_height();
scaled_width_ratio = (gfloat) get_output_width() / (gfloat) get_project_width();
// Calculate the scaled start and finish positions for each element
element_x_position_start = scaled_width_ratio * this_layer_data->x_offset_start;
element_x_position_finish = scaled_width_ratio * this_layer_data->x_offset_finish;
element_y_position_start = scaled_height_ratio * this_layer_data->y_offset_start;
element_y_position_finish = scaled_height_ratio * this_layer_data->y_offset_finish;
// If there is a fade in transition, fill in the relevant elements
start_frame = this_layer_data->start_time * get_frames_per_second();
if (TRANS_LAYER_NONE != this_layer_data->transition_in_type)
{
// Work out the starting and ending frames for the fade
finish_frame = start_frame + (this_layer_data->transition_in_duration * get_frames_per_second());
// Indicate on which frame the element should be displayed, at what display depth, and its starting co-ordinates
start_frame_rounded = roundf(start_frame);
finish_frame_rounded = roundf(finish_frame) == 0 ? 0 : ((roundf(finish_frame)>=num_frames) ? num_frames-1 : roundf(finish_frame));
array_start[start_frame_rounded].add = TRUE;
array_start[start_frame_rounded].x_position = element_x_position_start;
array_start[start_frame_rounded].y_position = element_y_position_start;
// Work out how much opacity to increment each frame by
opacity_step = 100 / ((this_layer_data->transition_in_duration * get_frames_per_second()));
// Loop through each frame of the fade in, setting the opacity values
opacity_count = 0;
for (frame_counter = start_frame_rounded; frame_counter <= finish_frame_rounded; frame_counter++)
{
array_start[frame_counter].action_this = TRUE;
array_start[frame_counter].opacity_change = TRUE;
array_start[frame_counter].opacity = opacity_count;
array_start[frame_counter].x_position = element_x_position_start;
array_start[frame_counter].y_position = element_y_position_start;
opacity_count += floorf(opacity_step);
}
// Ensure the layer is completely visible after the end of the fade in
array_start[frame_counter].action_this = TRUE;
array_start[frame_counter].opacity_change = TRUE;
array_start[frame_counter].opacity = 100;
} else
{
// Indicate on which frame the element should be displayed, at what display depth, and its starting co-ordinates
start_frame_rounded = roundf(start_frame);
array_start[start_frame_rounded].add = TRUE;
array_start[start_frame_rounded].x_position = element_x_position_start;
array_start[start_frame_rounded].y_position = element_y_position_start;
array_start[start_frame_rounded].action_this = TRUE;
array_start[start_frame_rounded].opacity = 100;
}
// If there is a fade out transition, fill in the relevant elements
if (TRANS_LAYER_NONE != this_layer_data->transition_out_type)
//.........这里部分代码省略.........
开发者ID:justinclift,项目名称:salasaga,代码行数:101,代码来源:export_swf_create_layer_elements.c
示例7: ScriptPlace
bool UniscribeController::shapeAndPlaceItem(const UChar* cp, unsigned i, const SimpleFontData* fontData, GlyphBuffer* glyphBuffer)
{
// Determine the string for this item.
const UChar* str = cp + m_items[i].iCharPos;
int len = m_items[i+1].iCharPos - m_items[i].iCharPos;
SCRIPT_ITEM item = m_items[i];
// Set up buffers to hold the results of shaping the item.
Vector<WORD> glyphs;
Vector<WORD> clusters;
Vector<SCRIPT_VISATTR> visualAttributes;
clusters.resize(len);
// Shape the item.
// The recommended size for the glyph buffer is 1.5 * the character length + 16 in the uniscribe docs.
// Apparently this is a good size to avoid having to make repeated calls to ScriptShape.
glyphs.resize(1.5 * len + 16);
visualAttributes.resize(glyphs.size());
if (!shape(str, len, item, fontData, glyphs, clusters, visualAttributes))
return true;
// We now have a collection of glyphs.
Vector<GOFFSET> offsets;
Vector<int> advances;
offsets.resize(glyphs.size());
advances.resize(glyphs.size());
int glyphCount = 0;
HRESULT placeResult = ScriptPlace(0, fontData->scriptCache(), glyphs.data(), glyphs.size(), visualAttributes.data(),
&item.a, advances.data(), offsets.data(), 0);
if (placeResult == E_PENDING) {
// The script cache isn't primed with enough info yet. We need to select our HFONT into
// a DC and pass the DC in to ScriptPlace.
HDC hdc = GetDC(0);
HFONT hfont = fontData->platformData().hfont();
HFONT oldFont = (HFONT)SelectObject(hdc, hfont);
placeResult = ScriptPlace(hdc, fontData->scriptCache(), glyphs.data(), glyphs.size(), visualAttributes.data(),
&item.a, advances.data(), offsets.data(), 0);
SelectObject(hdc, oldFont);
ReleaseDC(0, hdc);
}
if (FAILED(placeResult) || glyphs.isEmpty())
return true;
// Convert all chars that should be treated as spaces to use the space glyph.
// We also create a map that allows us to quickly go from space glyphs or rounding
// hack glyphs back to their corresponding characters.
Vector<int> spaceCharacters(glyphs.size());
spaceCharacters.fill(-1);
Vector<int> roundingHackCharacters(glyphs.size());
roundingHackCharacters.fill(-1);
Vector<int> roundingHackWordBoundaries(glyphs.size());
roundingHackWordBoundaries.fill(-1);
const float cLogicalScale = fontData->platformData().useGDI() ? 1.0f : 32.0f;
unsigned logicalSpaceWidth = fontData->spaceWidth() * cLogicalScale;
float roundedSpaceWidth = roundf(fontData->spaceWidth());
for (int k = 0; k < len; k++) {
UChar ch = *(str + k);
if (Font::treatAsSpace(ch)) {
// Substitute in the space glyph at the appropriate place in the glyphs
// array.
glyphs[clusters[k]] = fontData->spaceGlyph();
advances[clusters[k]] = logicalSpaceWidth;
spaceCharacters[clusters[k]] = m_currentCharacter + k + item.iCharPos;
}
if (Font::isRoundingHackCharacter(ch))
roundingHackCharacters[clusters[k]] = m_currentCharacter + k + item.iCharPos;
int boundary = k + m_currentCharacter + item.iCharPos;
if (boundary < m_run.length() &&
Font::isRoundingHackCharacter(*(str + k + 1)))
roundingHackWordBoundaries[clusters[k]] = boundary;
}
// Populate our glyph buffer with this information.
bool hasExtraSpacing = m_font.letterSpacing() || m_font.wordSpacing() || m_padding;
float leftEdge = m_runWidthSoFar;
for (unsigned k = 0; k < glyphs.size(); k++) {
Glyph glyph = glyphs[k];
float advance = advances[k] / cLogicalScale;
float offsetX = offsets[k].du / cLogicalScale;
float offsetY = offsets[k].dv / cLogicalScale;
// Match AppKit's rules for the integer vs. non-integer rendering modes.
float roundedAdvance = roundf(advance);
if (!m_font.isPrinterFont() && !fontData->isSystemFont()) {
advance = roundedAdvance;
offsetX = roundf(offsetX);
offsetY = roundf(offsetY);
}
advance += fontData->syntheticBoldOffset();
// We special case spaces in two ways when applying word rounding.
//.........这里部分代码省略.........
开发者ID:flwh,项目名称:Alcatel_OT_985_kernel,代码行数:101,代码来源:UniscribeController.cpp
示例8: acq_search
bool acq_search(gnss_signal_t sid, float cf_min, float cf_max,
float cf_bin_width, acq_result_t *acq_result)
{
/* Configuration */
u32 fft_len_log2 = FFT_LEN_LOG2_MAX;
u32 fft_len = 1 << fft_len_log2;
float fft_bin_width = NAP_ACQ_SAMPLE_RATE_Hz / fft_len;
float chips_per_sample = CHIP_RATE / NAP_ACQ_SAMPLE_RATE_Hz;
/* Generate, resample, and FFT code */
static fft_cplx_t code_fft[FFT_LEN_MAX];
code_resample(sid, chips_per_sample, code_fft, fft_len);
if (!fft(code_fft, code_fft, fft_len_log2,
FFT_DIR_FORWARD, FFT_SCALE_SCHED_CODE)) {
return false;
}
/* FFT samples */
u32 sample_count;
static fft_cplx_t sample_fft[FFT_LEN_MAX];
if(!fft_samples(FFT_SAMPLES_INPUT, sample_fft, fft_len_log2,
FFT_DIR_FORWARD, FFT_SCALE_SCHED_SAMPLES, &sample_count)) {
return false;
}
/* Search for results */
float best_mag_sq = 0.0f;
float best_mag_sq_sum = 0.0f;
float best_doppler = 0.0f;
u32 best_sample_offset = 0;
/* Loop over Doppler bins */
s32 doppler_bin_min = (s32)floorf(cf_min / cf_bin_width);
s32 doppler_bin_max = (s32)floorf(cf_max / cf_bin_width);
for (s32 doppler_bin = doppler_bin_min; doppler_bin <= doppler_bin_max;
doppler_bin++) {
s32 sample_offset = (s32)roundf(doppler_bin * cf_bin_width / fft_bin_width);
/* Actual computed Doppler */
float doppler = sample_offset * fft_bin_width;
/* Multiply sample FFT by shifted conjugate code FFT */
static fft_cplx_t result_fft[FFT_LEN_MAX];
for (u32 i=0; i<fft_len; i++) {
const fft_cplx_t *a = &code_fft[i];
const fft_cplx_t *b = &sample_fft[(i + sample_offset) & (fft_len - 1)];
fft_cplx_t *r = &result_fft[i];
s32 a_re = (s32)a->re;
s32 a_im = (s32)a->im;
s32 b_re = (s32)b->re;
s32 b_im = (s32)b->im;
r->re = ((a_re * b_re) + (a_im * b_im)) / RESULT_DIV;
r->im = ((a_re * -b_im) + (a_im * b_re)) / RESULT_DIV;
}
/* Inverse FFT */
if (!fft(result_fft, result_fft, fft_len_log2,
FFT_DIR_BACKWARD, FFT_SCALE_SCHED_INV)) {
return false;
}
/* Peak search */
float mag_sq_sum = 0.0f;
bool match = false;
for (u32 i=0; i<fft_len; i++) {
const fft_cplx_t *r = &result_fft[i];
float re = (float)r->re;
float im = (float)r->im;
float mag_sq = re*re + im*im;
mag_sq_sum += mag_sq;
if (mag_sq > best_mag_sq) {
best_mag_sq = mag_sq;
best_doppler = doppler;
best_sample_offset = i;
match = true;
}
}
if (match) {
best_mag_sq_sum = mag_sq_sum;
}
}
/* Account for non-integer number of codes and circular convolution:
* If correlation peak is in the first half of the buffer, most samples
* have NOT wrapped, so assume a positive shift.
* If correlation peak is in the second half of the buffer, most samples
* HAVE wrapped, so assume a negative shift. */
s32 corrected_sample_offset = (best_sample_offset < fft_len/2) ?
(s32)best_sample_offset :
(s32)best_sample_offset - (s32)fft_len;
/* Compute code phase */
float cp = chips_per_sample * corrected_sample_offset;
/* Modulus code length */
cp -= CODE_LENGTH * floorf(cp / CODE_LENGTH);
//.........这里部分代码省略.........
开发者ID:dt-exafore,项目名称:piksi_firmware,代码行数:101,代码来源:acq.c
示例9: computeViewportAttributes
//.........这里部分代码省略.........
#if OS(ANDROID)
result.devicePixelRatioForDeviceDimensions = isAutoDPI ? (deviceDPI / 160.0f) : result.devicePixelRatio;
#endif
switch (int(args.width)) {
case ViewportArguments::ValueDesktopWidth:
args.width = desktopWidth;
break;
case ViewportArguments::ValueDeviceWidth:
args.width = deviceWidth;
break;
case ViewportArguments::ValueDeviceHeight:
args.width = deviceHeight;
break;
}
switch (int(args.height)) {
case ViewportArguments::ValueDesktopWidth:
args.height = desktopWidth;
break;
case ViewportArguments::ValueDeviceWidth:
args.height = deviceWidth;
break;
case ViewportArguments::ValueDeviceHeight:
args.height = deviceHeight;
break;
}
// Clamp values to range defined by spec and resolve minimum-scale and maximum-scale values
if (args.width != ViewportArguments::ValueAuto)
args.width = min(float(10000), max(args.width, float(1)));
if (args.height != ViewportArguments::ValueAuto)
args.height = min(float(10000), max(args.height, float(1)));
if (args.initialScale != ViewportArguments::ValueAuto)
args.initialScale = min(float(10), max(args.initialScale, float(0.1)));
if (args.minimumScale != ViewportArguments::ValueAuto)
args.minimumScale = min(float(10), max(args.minimumScale, float(0.1)));
if (args.maximumScale != ViewportArguments::ValueAuto)
args.maximumScale = min(float(10), max(args.maximumScale, float(0.1)));
// Resolve minimum-scale and maximum-scale values according to spec.
if (args.minimumScale == ViewportArguments::ValueAuto)
result.minimumScale = float(0.25);
else
result.minimumScale = args.minimumScale;
if (args.maximumScale == ViewportArguments::ValueAuto) {
result.maximumScale = float(5.0);
result.minimumScale = min(float(5.0), result.minimumScale);
} else
result.maximumScale = args.maximumScale;
result.maximumScale = max(result.minimumScale, result.maximumScale);
// Resolve initial-scale value.
result.initialScale = args.initialScale;
if (result.initialScale == ViewportArguments::ValueAuto) {
result.initialScale = availableWidth / desktopWidth;
if (args.width != ViewportArguments::ValueAuto)
result.initialScale = availableWidth / args.width;
if (args.height != ViewportArguments::ValueAuto) {
// if 'auto', the initial-scale will be negative here and thus ignored.
result.initialScale = max<float>(result.initialScale, availableHeight / args.height);
}
}
// Constrain initial-scale value to minimum-scale/maximum-scale range.
result.initialScale = min(result.maximumScale, max(result.minimumScale, result.initialScale));
// Resolve width value.
float width;
if (args.width != ViewportArguments::ValueAuto)
width = args.width;
else {
if (args.initialScale == ViewportArguments::ValueAuto)
width = desktopWidth;
else if (args.height != ViewportArguments::ValueAuto)
width = args.height * (availableWidth / availableHeight);
else
width = availableWidth / result.initialScale;
}
// Resolve height value.
float height;
if (args.height != ViewportArguments::ValueAuto)
height = args.height;
else
height = width * availableHeight / availableWidth;
// Extend width and height to fill the visual viewport for the resolved initial-scale.
width = max<float>(width, availableWidth / result.initialScale);
height = max<float>(height, availableHeight / result.initialScale);
result.layoutSize.setWidth(static_cast<int>(roundf(width)));
result.layoutSize.setHeight(static_cast<int>(roundf(height)));
result.userScalable = args.userScalable;
return result;
}
开发者ID:paul99,项目名称:third_party,代码行数:101,代码来源:ViewportArguments.cpp
示例10: wiiu_font_render_line
static void wiiu_font_render_line(
video_frame_info_t *video_info,
wiiu_font_t* font, const char* msg, unsigned msg_len,
float scale, const unsigned int color, float pos_x,
float pos_y, unsigned text_align)
{
unsigned i;
wiiu_video_t* wiiu = (wiiu_video_t*)video_info->userdata;
unsigned width = video_info->width;
unsigned height = video_info->height;
int x = roundf(pos_x * width);
int y = roundf((1.0 - pos_y) * height);
if( !wiiu ||
wiiu->vertex_cache.current + (msg_len * 4) > wiiu->vertex_cache.size)
return;
switch (text_align)
{
case TEXT_ALIGN_RIGHT:
x -= wiiu_font_get_message_width(font, msg, msg_len, scale);
break;
case TEXT_ALIGN_CENTER:
x -= wiiu_font_get_message_width(font, msg, msg_len, scale) / 2;
break;
}
sprite_vertex_t* v = wiiu->vertex_cache.v + wiiu->vertex_cache.current;
for (i = 0; i < msg_len; i++)
{
const char* msg_tmp = &msg[i];
unsigned code = utf8_walk(&msg_tmp);
unsigned skip = msg_tmp - &msg[i];
if (skip > 1)
i += skip - 1;
const struct font_glyph* glyph =
font->font_driver->get_glyph(font->font_data, code);
if (!glyph) /* Do something smarter here ... */
glyph = font->font_driver->get_glyph(font->font_data, '?');
if (!glyph)
continue;
v->pos.x = x + glyph->draw_offset_x * scale;
v->pos.y = y + glyph->draw_offset_y * scale;
v->pos.width = glyph->width * scale;
v->pos.height = glyph->height * scale;
v->coord.u = glyph->atlas_offset_x;
v->coord.v = glyph->atlas_offset_y;
v->coord.width = glyph->width;
v->coord.height = glyph->height;
v->color = color;
v++;
x += glyph->advance_x * scale;
y += glyph->advance_y * scale;
}
int count = v - wiiu->vertex_cache.v - wiiu->vertex_cache.current;
if (!count)
return;
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_ATTRIBUTE_BUFFER, wiiu->vertex_cache.v + wiiu->vertex_cache.current, count * sizeof(wiiu->vertex_cache.v));
if(font->atlas->dirty)
{
for (i = 0; (i < font->atlas->height) && (i < font->texture.surface.height); i++)
memcpy(font->texture.surface.image + (i * font->texture.surface.pitch),
font->atlas->buffer + (i * font->atlas->width), font->atlas->width);
GX2Invalidate(GX2_INVALIDATE_MODE_CPU_TEXTURE, font->texture.surface.image,
font->texture.surface.imageSize);
font->atlas->dirty = false;
}
GX2SetPixelTexture(&font->texture, sprite_shader.ps.samplerVars[0].location);
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, font->ubo_tex);
GX2DrawEx(GX2_PRIMITIVE_MODE_POINTS, count, wiiu->vertex_cache.current, 1);
GX2SetVertexUniformBlock(sprite_shader.vs.uniformBlocks[1].offset, sprite_shader.vs.uniformBlocks[1].size, wiiu->ubo_tex);
wiiu->vertex_cache.current = v - wiiu->vertex_cache.v;
}
开发者ID:netux79,项目名称:RetroArch,代码行数:95,代码来源:wiiu_font.c
示例11: wlanframesync_execute_seekplcp
// frame detection
void wlanframesync_execute_seekplcp(wlanframesync _q)
{
_q->timer++;
// TODO : only check every 100 - 150 (decimates/reduced complexity)
if (_q->timer < 64)
return;
// reset timer
_q->timer = 0;
// read contents of input buffer
float complex * rc;
windowcf_read(_q->input_buffer, &rc);
// estimate gain
// TODO : use gain from result of FFT
unsigned int i;
float g = 0.0f;
for (i=16; i<80; i+=4) {
// compute |rc[i]|^2 efficiently
g += crealf(rc[i ])*crealf(rc[i ]) + cimagf(rc[i ])*cimagf(rc[i ]);
g += crealf(rc[i+1])*crealf(rc[i+1]) + cimagf(rc[i+1])*cimagf(rc[i+1]);
g += crealf(rc[i+2])*crealf(rc[i+2]) + cimagf(rc[i+2])*cimagf(rc[i+2]);
g += crealf(rc[i+3])*crealf(rc[i+3]) + cimagf(rc[i+3])*cimagf(rc[i+3]);
}
g = 64.0f / (g + 1e-12f);
// save gain (permits dynamic invocation of get_rssi() method)
_q->g0 = g;
// estimate S0 gain
wlanframesync_estimate_gain_S0(_q, &rc[16], _q->G0a);
// compute S0 metrics
float complex s_hat;
wlanframesync_S0_metrics(_q, _q->G0a, &s_hat);
s_hat *= g;
float tau_hat = cargf(s_hat) * (float)(16.0f) / (2*M_PI);
#if DEBUG_WLANFRAMESYNC_PRINT
printf(" - gain=%12.3f, rssi=%8.2f dB, s_hat=%12.4f <%12.8f>, tau_hat=%8.3f\n",
sqrt(g),
-10*log10(g),
cabsf(s_hat), cargf(s_hat),
tau_hat);
#endif
//
if (cabsf(s_hat) > WLANFRAMESYNC_S0A_ABS_THRESH) {
int dt = (int)roundf(tau_hat);
// set timer appropriately...
_q->timer = (16 + dt) % 16;
//_q->timer += 32; // add delay to help ensure good S0 estimate (multiple of 16)
_q->state = WLANFRAMESYNC_STATE_RXSHORT0;
#if DEBUG_WLANFRAMESYNC_PRINT
printf("********** frame detected! ************\n");
printf(" s_hat : %12.8f <%12.8f>\n", cabsf(s_hat), cargf(s_hat));
printf(" tau_hat : %12.8f\n", tau_hat);
printf(" dt : %12d\n", dt);
printf(" timer : %12u\n", _q->timer);
#endif
}
}
开发者ID:pk-mds,项目名称:liquid-wlan,代码行数:68,代码来源:wlanframesync.c
示例12: roundf
int Entity::getRoundedY() const
{
return roundf( y );
}
开发者ID:Outfl3sh,项目名称:maturitni-projekt,代码行数:4,代码来源:entity.cpp
示例13: return
//Returns steps from units (mm) for a particular drive
long LookAhead::EndPointToMachine(int8_t drive, float coord)
{
return (long)roundf(coord*reprap.GetPlatform()->DriveStepsPerUnit(drive));
}
开发者ID:RepRapMorgan,项目名称:RepRapFirmware,代码行数:5,代码来源:Move.cpp
示例14: vita2d_gfx_update_viewport
static void vita2d_gfx_update_viewport(vita_video_t* vita)
{
int x = 0;
int y = 0;
float device_aspect = ((float)PSP_FB_WIDTH) / PSP_FB_HEIGHT;
float width = PSP_FB_WIDTH;
float height = PSP_FB_HEIGHT;
settings_t *settings = config_get_ptr();
if (settings->video.scale_integer)
{
video_viewport_get_scaled_integer(&vita->vp, PSP_FB_WIDTH,
PSP_FB_HEIGHT, video_driver_get_aspect_ratio(), vita->keep_aspect);
width = vita->vp.width;
height = vita->vp.height;
}
else if (vita->keep_aspect)
{
float desired_aspect = video_driver_get_aspect_ratio();
if (vita->rotation == ORIENTATION_VERTICAL ||
vita->rotation == ORIENTATION_FLIPPED_ROTATED){
device_aspect = 1.0 / device_aspect;
width = PSP_FB_HEIGHT;
height = PSP_FB_WIDTH;
}
#if defined(HAVE_MENU)
if (settings->video.aspect_ratio_idx == ASPECT_RATIO_CUSTOM)
{
struct video_viewport *custom = video_viewport_get_custom();
if (custom)
{
x = custom->x;
y = custom->y;
width = custom->width;
height = custom->height;
}
}
else
#endif
{
float delta;
if ((fabsf(device_aspect - desired_aspect) < 0.0001f))
{
/* If the aspect ratios of screen and desired aspect
* ratio are sufficiently equal (floating point stuff),
* assume they are actually equal.
*/
}
else if (device_aspect > desired_aspect)
{
delta = (desired_aspect / device_aspect - 1.0f)
/ 2.0f + 0.5f;
x = (int)roundf(width * (0.5f - delta));
width = (unsigned)roundf(2.0f * width * delta);
}
else
{
delta = (device_aspect / desired_aspect - 1.0f)
/ 2.0f + 0.5f;
y = (int)roundf(height * (0.5f - delta));
height = (unsigned)roundf(2.0f * height * delta);
}
if (vita->rotation == ORIENTATION_VERTICAL ||
vita->rotation == ORIENTATION_FLIPPED_ROTATED){
x = (PSP_FB_WIDTH - width) * 0.5f;
y = (PSP_FB_HEIGHT - height) * 0.5f;
}
}
vita->vp.x = x;
vita->vp.y = y;
vita->vp.width = width;
vita->vp.height = height;
}
else
{
vita->vp.x = vita->vp.y = 0;
vita->vp.width = width;
vita->vp.height = height;
}
vita->vp.width += vita->vp.width&0x1;
vita->vp.height += vita->vp.height&0x1;
vita->should_resize = false;
}
开发者ID:AlexFolland,项目名称:RetroArch,代码行数:90,代码来源:vita2d_gfx.c
示例15: _raw_bits
Fixed::Fixed(const float f) : _raw_bits(roundf(f * (1 << _n_frac_bits)))
{
std::cout << "Float constructor called" << std::endl;
}
开发者ID:z0mbie42,项目名称:42,代码行数:4,代码来源:Fixed.cpp
示例16: main
int
main ()
{
float S[8][16], val;
int i,k, count = 0;
int vali;
printf("/* sbc_coeffs.h - Automatically generated by cosdata.c. */\n\n");
vali = SI_MULTI;
printf("#define SIMULTI\t%d\n\n", vali);
printf("static const int32_t sbc_coeffs8[] = {\n ");
for (k = 0;k < AC(sbc8_coeffs);k++) {
if (count % 8 == 0 && count != 0)
printf("\n ");
val = sbc8_coeffs[k] * COEFFS_MULTI;
vali = roundf(val);
printf("%d, ",vali);
count++;
}
printf("\n};\n");
count = 0;
printf("static const int32_t sbc_coeffs4[] = {\n ");
for (k = 0;k < AC(sbc4_coeffs);k++) {
if (count % 8 == 0 && count != 0)
printf("\n ");
val = sbc4_coeffs[k] * COEFFS_MULTI;
vali = roundf(val);
printf("%d, ",vali);
count++;
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdata8[8][16] = {\n ");
for (i = 0; i < 8; i++) {
for (k = 0;k < 16;k++) {
S[i][k] = cosf((i+0.5)*(k-4)*(M_PI_4/2));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = roundf(val);
printf("%d, ",vali);
if (k == 15)
printf("},");
count++;
}
}
printf("\n};\n");
count = 0;
printf("static const int32_t cosdata4[4][8] = {\n ");
for (i = 0; i < 4; i++) {
for (k = 0;k < 8;k++) {
S[i][k] = cosf((i+0.5)*(k-2)*(M_PI_4));
if (count % 8 == 0 && count != 0)
printf("\n ");
if (k == 0)
printf("{ ");
val = S[i][k] * SI_MULTI;
vali = roundf(val);
printf("%d, ",vali);
if (k == 7)
printf("},");
count++;
}
}
printf("\n};\n");
return 0;
}
开发者ID:erikarn,项目名称:virtual_oss,代码行数:80,代码来源:cosdata.c
示例17: OnDisplayChanged
float CMouseControl::MovePointerRel (float dx, float dy, int* dxRes, int* dyRes)
{
OnDisplayChanged ();
// Apply factors
dx*= m_fDx;
dy*= m_fDy;
// Low-pass filter
dx= dx * (1.0f - m_actualMotionWeight) + m_dxant * m_actualMotionWeight;
dy= dy * (1.0f - m_actualMotionWeight) + m_dyant * m_actualMotionWeight;
m_dxant= dx; m_dyant= dy;
// Acceleration
float distance= (float) ::sqrt (dx * dx + dy * dy);
unsigned int iAccelArray= (unsigned int) (distance + 0.5f);
if (iAccelArray>= ACCEL_ARRAY_SIZE) iAccelArray= ACCEL_ARRAY_SIZE - 1;
dx*= m_accelArray[iAccelArray];
dy*= m_accelArray[iAccelArray];
// Apply delta threshold
if (-m_minDeltaThreshold < dx && dx < m_minDeltaThreshold) dx= 0.0f;
if (-m_minDeltaThreshold < dy && dy < m_minDeltaThreshold) dy= 0.0f;
int idx= (int) roundf(dx);
int idy= (int) roundf(dy);
int mouseX, mouseY
|
请发表评论