int console_widget_t::loc_y(int mouse_y) { /* calculate location of the mouse in screen text coordinates */ int border_y = (fit_y - h()) / 2; int loc_y = (mouse_y-MENU_SIZE_PIXELS+border_y)/letter_y; /* clip mouse location to screen only */ loc_y = i_min(console->config.y, loc_y); loc_y = i_max(0, loc_y); return loc_y; }
int console_widget_t::loc_x(int mouse_x) { /* calculate location of the mouse in screen text coordinates */ int border_x = (fit_x-w()) / 2; int loc_x = (mouse_x+border_x)/letter_x; /* clip mouse location to screen only */ loc_x = i_min(console->config.x, loc_x); loc_x = i_max(0, loc_x); return loc_x; }
void console_widget_t::scroll_back_buffer(int delta) { if(!console) return; if(mouse_copy) mouse_clear(); /* limit scroll display to scroll buffer */ scroll_lines += delta; scroll_lines = i_max(scroll_lines, console->config.y-console->config.max_y); scroll_lines = i_min(scroll_lines, 0); damage_console(0, 0, console->config.x, console->config.y); }
inline ErrorCode SweptVertexData::get_params(const EntityHandle vhandle, int &i, int &j, int &k) const { if (TYPE_FROM_HANDLE(vhandle) != MBVERTEX) return MB_FAILURE; int hdiff = vhandle - start_handle(); k = hdiff / (dIJK[0]*dIJK[1]); j = (hdiff - (k*dIJK[0]*dIJK[1])) / dIJK[0]; i = hdiff % dIJK[0]; k += vertexParams[0].k(); j += vertexParams[0].j(); i += vertexParams[0].i(); return (vhandle >= start_handle() && i >= i_min() && i <= i_max() && j >= j_min() && j <= j_max() && k >= k_min() && k <= k_max()) ? MB_SUCCESS : MB_FAILURE; }
inline ErrorCode SweptElementData::get_params(const EntityHandle ehandle, int &i, int &j, int &k) const { if (TYPE_FROM_HANDLE(ehandle) != TYPE_FROM_HANDLE(start_handle())) return MB_FAILURE; int hdiff = ehandle - start_handle(); // use double ?: test below because on some platforms, both sides of the : are // evaluated, and if dIJKm1[1] is zero, that'll generate a divide-by-zero k = (dIJKm1[1] > 0 ? hdiff / (dIJKm1[1] > 0 ? dIJKm1[0]*dIJKm1[1] : 1) : 0); j = (hdiff - (k*dIJKm1[0]*dIJKm1[1])) / dIJKm1[0]; i = hdiff % dIJKm1[0]; k += elementParams[0].k(); j += elementParams[0].j(); i += elementParams[0].i(); return (ehandle >= start_handle() && ehandle < start_handle()+size() && i >= i_min() && i <= i_max() && j >= j_min() && j <= j_max() && k >= k_min() && k <= k_max()) ? MB_SUCCESS : MB_FAILURE; }
//! get max params for this vertex inline void SweptVertexData::max_params(int &i, int &j, int &k) const { i = i_max(); j = j_max(); k = k_max(); }
void Perlin3DViewerWidget::updatePerlinChunks() { while (!_ChunkGenerator.threadAvailable()) { // // first obtain the camera position const myGL::Vec3f& camera_pos = _FreeFly.getPosition(); #define D_CHUNK (float)(_ChunkGenerator.getChunkSize()) #define D_CHECK_NEG(l_value) \ ( ( (l_value) < 0 ) \ ? ( (l_value) / D_CHUNK - 1 ) \ : ( (l_value) / D_CHUNK ) ) // // then obtain the camera chunk position myGL::Vec3i i_pos( D_CHECK_NEG( camera_pos.x ), D_CHECK_NEG( camera_pos.y ), D_CHECK_NEG( camera_pos.z ) ); #undef D_CHUNK #undef D_CHECK_NEG // // get the range in chunk (min/max) int tmp_dec = Navigator_GlobalValue::pTest->_chunkRange; myGL::Vec3i i_min(i_pos.x - tmp_dec, i_pos.y - tmp_dec, i_pos.z - tmp_dec); myGL::Vec3i i_max(i_pos.x + tmp_dec, i_pos.y + tmp_dec, i_pos.z + tmp_dec); myGL::Vec3i i_inc; /// myGL::Vec3i i_inc_best_visible; float length_best_visible = std::numeric_limits<float>::max(); myGL::Vec3i i_inc_best_not_visible; float length_best_not_visible = std::numeric_limits<float>::max(); for (i_inc.z = i_min.z; i_inc.z <= i_max.z; ++i_inc.z) for (i_inc.y = i_min.y; i_inc.y <= i_max.y; ++i_inc.y) for (i_inc.x = i_min.x; i_inc.x <= i_max.x; ++i_inc.x) { /// /// check if this coord got a chunk bool no_need_to_go_further = false; for (Perlin3D_Chunk* element : _Perlin3D_Chunks) { const myGL::Vec3i& tmp_pos = element->getPosition(); /// same position if (i_inc == tmp_pos) { no_need_to_go_further = true; break; } } /// /// if yes => loop again if (no_need_to_go_further) continue; /// else => check if visible myGL::Vec3f tmp_pos1; tmp_pos1.x = (float)i_inc.x * (float)Navigator_GlobalValue::pTest->_chunkSize; tmp_pos1.y = (float)i_inc.y * (float)Navigator_GlobalValue::pTest->_chunkSize; tmp_pos1.z = (float)i_inc.z * (float)Navigator_GlobalValue::pTest->_chunkSize; bool is_visible = _Frustum.cubeInFrustum( tmp_pos1, (float)Navigator_GlobalValue::pTest->_chunkSize ); /// check his length /// reccord these data for the choice myGL::Vec3f tmp_pos2; tmp_pos2.x = (float)(i_inc.x - i_pos.x) * (float)Navigator_GlobalValue::pTest->_chunkSize; tmp_pos2.y = (float)(i_inc.y - i_pos.y) * (float)Navigator_GlobalValue::pTest->_chunkSize; tmp_pos2.z = (float)(i_inc.z - i_pos.z) * (float)Navigator_GlobalValue::pTest->_chunkSize; float tmp_lenght = sqrtf( tmp_pos2.x * tmp_pos2.x + tmp_pos2.y * tmp_pos2.y + tmp_pos2.z * tmp_pos2.z ); if (is_visible) { if (tmp_lenght < length_best_visible) { i_inc_best_visible = i_inc; length_best_visible = tmp_lenght; } } else { if (tmp_lenght < length_best_not_visible) { i_inc_best_not_visible = i_inc; length_best_not_visible = tmp_lenght; } } } if ( length_best_visible == std::numeric_limits<float>::max() && length_best_not_visible == std::numeric_limits<float>::max() ) // break; return; Perlin3D_Chunk* tmp_Chunk = NULL; t_Chunks::iterator itC = _Perlin3D_Chunks.begin(); // for (; itC != _Perlin3D_Chunks.end(); ++itC) for (; itC != _Perlin3D_Chunks.end(); ) { const myGL::Vec3i& tmp_pos = (*itC)->getPosition(); if ( !(*itC)->isDisabled() && ( tmp_pos.x < i_min.x || tmp_pos.x > i_max.x || tmp_pos.y < i_min.y || tmp_pos.y > i_max.y || tmp_pos.z < i_min.z || tmp_pos.z > i_max.z ) ) { delete *itC, *itC = NULL; itC = _Perlin3D_Chunks.erase(itC); // break; } else { ++itC; } } // if ( itC == _Perlin3D_Chunks.end() ) { tmp_Chunk = new Perlin3D_Chunk(); _Perlin3D_Chunks.push_back( tmp_Chunk ); } // else // { // tmp_Chunk = *itC; // tmp_Chunk->releaseBuffers(); // } if ( length_best_visible != std::numeric_limits<float>::max() ) _ChunkGenerator.generate( i_inc_best_visible, tmp_Chunk ); else _ChunkGenerator.generate( i_inc_best_not_visible, tmp_Chunk ); // if ( length_best_visible != std::numeric_limits<float>::max() ) // { // PerlinNoise _PerlinNoise; // { // int octaves = 1; // float freq = 1.0f; // float amp = 1.0f; // int seed = 0; // _PerlinNoise.Set( octaves, freq, amp, seed ); // } // MarchingCube _marchingCube; // _marchingCube._PerlinNoise = &_PerlinNoise; // _marchingCube.setChunkSize(20); // _marchingCube.prepare(i_inc_best_visible, tmp_Chunk); // _marchingCube.execute(); // } // else // { // // // _marchingCube._PerlinNoise = &p; // // _marchingCube.setChunkSize(chunk_size); // // _marchingCube.prepare(i_inc_best_not_visible, pPerlin3D_Chunk); // // _marchingCube.execute(); // } } }