RemoteInformation deserializeDataSourceData( const ::zeq::Event& event ) { if( event.getType() != EVENT_DATASOURCE_DATA ) return RemoteInformation(); auto data = GetVolumeInformation( event.getData( )); RemoteInformation info; livre::VolumeInformation& vi = info.second; info.first.low() = data->eventLow(); info.first.high() = data->eventHigh(); vi.isBigEndian = data->isBigEndian(); vi.compCount = data->compCount(); vi.dataType = DataType( data->dataType( )); vi.overlap = _deserializeVector3< unsigned >( data->overlap( )); vi.maximumBlockSize = _deserializeVector3< unsigned >( data->maximumBlockSize( )); vi.minPos = _deserializeVector3< float >( data->minPos( )); vi.maxPos = _deserializeVector3< float >( data->maxPos( )); vi.voxels = _deserializeVector3< unsigned >( data->voxels( )); vi.worldSize = _deserializeVector3< float >( data->worldSize( )); vi.boundingBox.getMin() = _deserializeVector3< float >( data->boundingBoxMin( )); vi.boundingBox.getMax() = _deserializeVector3< float >( data->boundingBoxMax( )); vi.worldSpacePerVoxel = data->worldSpacePerVoxel(); const Vector3ui& blockSize = vi.maximumBlockSize - vi.overlap * 2; Vector3ui blocksSize = vi.voxels / blockSize; blocksSize = blocksSize / ( 1u << data->depth( )); vi.rootNode = RootNode( data->depth(), blocksSize ); return info; }
void DiWaterChunk::UpdateMaterial() { DiTerrain* tr = mParent->mTerrainMap; DiVec4 worldSize(tr->GetGridSize(),tr->GetTextureScale(),tr->GetWorldSize().x,tr->GetWorldSize().y); mMaterial->GetShaderParameter()->WriteFloat4("v_WorldSizes",worldSize); }
static LatLng unproject(const Point<double>& p, double scale, LatLng::WrapMode wrapMode = LatLng::Unwrapped) { auto p2 = p * util::DEGREES_MAX / worldSize(scale); return LatLng { util::DEGREES_MAX / M_PI * std::atan(std::exp((util::LONGITUDE_MAX - p2.y) * util::DEG2RAD)) - 90.0, p2.x - util::LONGITUDE_MAX, wrapMode }; }
void World::alignToWindowCenter(const Vec2 &windowSize) { Vec2 windowCenter = windowSize / 2; Vec2 worldSize(Config::World::WIDTH, Config::World::HEIGHT); Vec2 worldCenter = worldSize / 2; Vec2 worldCenterScr = worldPainter.worldToScreen(worldCenter); Vec2 offset = windowCenter - worldCenterScr; this->offset = offset; worldPainter.setOffset(this->offset); }
void MyMPIController::sendMessageToEach(QString message) { int command = 0; MPI_Bcast(&command,1,MPI_INT,0,MPI_COMM_WORLD); for(int i=1; i<worldSize(); i++) { QString newMessage = QString("Message to %1: %2").arg(i).arg(message); const char *msg = newMessage.toStdString().c_str(); int messageLength = newMessage.toStdString().size()+1; MPI_Send(&messageLength, 1, MPI_INT, i, 0, MPI_COMM_WORLD); MPI_Send((void*)msg, messageLength, MPI_CHAR, i, 0, MPI_COMM_WORLD); } }
void Daemon::setDefault( bool wait ) { connections().lockedClear(); _rope.reset(); if ( _state == State::Grouped || _state == State::Leaving ) _quit = true; _state = State::Free; if ( _childPid != NoChild ) { waitForChild( wait ); _childPid = NoChild; } rank( 0 ); worldSize( 0 ); }
void Daemon::startGrouping( InputMessage &message, Channel channel ) { NOTE(); OutputMessage response( MessageType::Control ); int parameter; message >> parameter; channel->receive( message ); if ( _state != State::Enslaved ) { response.tag( Code::Refuse ); channel->send( response ); return; } response.tag( Code::OK ); channel->send( response ); _state = State::FormingGroup; worldSize( parameter ); }
void Daemon::leave( Channel channel ) { NOTE(); OutputMessage response( MessageType::Control ); if ( _state != State::Leaving ) { response.tag( Code::Refuse ); channel->send( response ); return; } response.tag( Code::CutRope ); _rope->send( response ); // we do not care about the message, we just need to asure // the message was read before we respond to the master InputMessage acknowledgement; _rope->receiveHeader( acknowledgement ); response.tag( Code::OK ); channel->send( response ); worldSize( 0 ); _quit = true; }
QPointF Visualizer::worldCoordinate(QPointF deviceCoordinate) { QSizeF size = worldSize(); double pixel = pixelSize(); return QPointF(-0.5 * size.width() + deviceCoordinate.x() * pixel, 0.5 * size.height() - deviceCoordinate.y() * pixel); }
double Visualizer::pixelSize() // Return distance in WORLD coordinates of 1 pixel. { return worldSize().width() / (double)width(); }
void MapRenderer::draw(GameWorld* world, const MapInfo& mi) { renderer->pushDebugGroup("Map"); renderer->useProgram(rectProg); // World out the number of units per tile glm::vec2 worldSize(GAME_MAP_SIZE); const int mapBlockLine = 8; glm::vec2 tileSize = worldSize / (float)mapBlockLine; // Determine the scale to show the right number of world units on the screen float worldScale = mi.screenSize / mi.worldSize; auto proj = renderer->get2DProjection(); glm::mat4 view, model; renderer->setUniform(rectProg, "proj", proj); renderer->setUniform(rectProg, "model", glm::mat4()); renderer->setUniform(rectProg, "colour", glm::vec4(0.f, 0.f, 0.f, 1.f)); view = glm::translate(view, glm::vec3(mi.screenPosition, 0.f)); if (mi.clipToSize) { glBindVertexArray( circle.getVAOName() ); glBindTexture(GL_TEXTURE_2D, 0); glm::mat4 circleView = glm::scale(view, glm::vec3(mi.screenSize)); renderer->setUniform(rectProg, "view", circleView); glEnable(GL_STENCIL_TEST); glStencilFunc(GL_ALWAYS, 1, 0xFF); glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE); glStencilMask(0xFF); glColorMask(0x00, 0x00, 0x00, 0x00); glDrawArrays(GL_TRIANGLE_FAN, 0, 182); glColorMask(0xFF, 0xFF, 0xFF, 0xFF); glStencilFunc(GL_EQUAL, 1, 0xFF); } view = glm::scale(view, glm::vec3(worldScale)); view = glm::rotate(view, mi.rotation, glm::vec3(0.f, 0.f, 1.f)); view = glm::translate(view, glm::vec3(glm::vec2(-1.f, 1.f) * mi.worldCenter, 0.f)); renderer->setUniform(rectProg, "view", view); glBindVertexArray( rect.getVAOName() ); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, 0); // radar00 = -x, +y // incrementing in X, then Y int initX = -(mapBlockLine/2); int initY = -(mapBlockLine/2); for( int m = 0; m < MAP_BLOCK_SIZE; ++m ) { std::string num = (m < 10 ? "0" : ""); std::string name = "radar" + num + std::to_string(m); auto texture = world->data->textures[{name,""}]; glBindTexture(GL_TEXTURE_2D, texture->getName()); int mX = initX + (m % mapBlockLine); int mY = initY + (m / mapBlockLine); auto tc = glm::vec2(mX, mY) * tileSize + glm::vec2(tileSize/2.f); glm::mat4 tilemodel = model; tilemodel = glm::translate( tilemodel, glm::vec3( tc, 0.f ) ); tilemodel = glm::scale( tilemodel, glm::vec3( tileSize, 1.f ) ); renderer->setUniform(rectProg, "model", tilemodel); glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); } // From here on out we will work in screenspace renderer->setUniform(rectProg, "view", glm::mat4()); if (mi.clipToSize) { glDisable(GL_STENCIL_TEST); // We only need the outer ring if we're clipping. glBlendFuncSeparate(GL_DST_COLOR, GL_ZERO, GL_ONE, GL_ZERO); TextureData::Handle radarDisc = data->findTexture("radardisc"); glm::mat4 model; model = glm::translate(model, glm::vec3(mi.screenPosition, 0.0f)); model = glm::scale(model, glm::vec3(mi.screenSize*1.07)); renderer->setUniform(rectProg, "model", model); glBindTexture(GL_TEXTURE_2D, radarDisc->getName()); glDrawArrays( GL_TRIANGLE_STRIP, 0, 4 ); glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); } for(auto& blip : world->state->radarBlips) { glm::vec2 blippos( blip.second.coord ); if( blip.second.target > 0 ) { GameObject* object = world->getBlipTarget(blip.second); if( object ) { blippos = glm::vec2( object->getPosition() ); } } drawBlip(blippos, view, mi, blip.second.texture); } // Draw the player blip auto player = world->pedestrianPool.find(world->state->playerObject); if( player ) { glm::vec2 plyblip(player->getPosition()); float hdg = glm::roll(player->getRotation()); drawBlip(plyblip, view, mi, "radar_centre", mi.rotation - hdg); } drawBlip(mi.worldCenter + glm::vec2(0.f, mi.worldSize), view, mi, "radar_north", 0.f, 24.f); glBindVertexArray( 0 ); glBindTexture(GL_TEXTURE_2D, 0); glUseProgram(0); /// @TODO migrate to using the renderer renderer->invalidate(); renderer->popDebugGroup(); }
static Point<double> project(const LatLng& latLng, double scale) { return Point<double> { util::LONGITUDE_MAX + latLng.longitude, util::LONGITUDE_MAX - util::RAD2DEG * std::log(std::tan(M_PI / 4 + latLng.latitude * M_PI / util::DEGREES_MAX)) } * worldSize(scale) / util::DEGREES_MAX; }
static double getMetersPerPixelAtLatitude(double lat, double zoom) { const double constrainedZoom = util::clamp(zoom, util::MIN_ZOOM, util::MAX_ZOOM); const double constrainedScale = std::pow(2.0, constrainedZoom); const double constrainedLatitude = util::clamp(lat, -util::LATITUDE_MAX, util::LATITUDE_MAX); return std::cos(constrainedLatitude * util::DEG2RAD) * util::M2PI * util::EARTH_RADIUS_M / worldSize(constrainedScale); }
static Point<double> project(const LatLng& latLng, double scale) { return project_(latLng, worldSize(scale)); }
void KdTreeVsBroadphaseDemo::doLinearCasts() { const int numCasts = 100; hkObjectArray<hkpClosestCdPointCollector> worldCollectors(numCasts); hkObjectArray<hkpClosestCdPointCollector> treeCollectors(numCasts); hkArray<hkpLinearCastInput> lcInput (numCasts); hkArray<const hkpCollidable*> castCollidables(numCasts); for (int i=0; i < numCasts; i++) { //hkprintf("random seed = %d\n", m_rand.getCurrent()); castCollidables[i] = m_collidables[ m_rand.getRand32() % m_collidables.getSize() ]; hkVector4 start, end; start = hkGetRigidBody(castCollidables[i])->getPosition(); hkVector4 worldSize(m_worldSizeX, m_worldSizeY, m_worldSizeZ); m_rand.getRandomVector11(end); end.mul4(worldSize); // Flatten out the rays in one component - this triggers a special case in the raycasting code { end(i%3) = start(i%3); } lcInput[i].m_to = end; lcInput[i].m_maxExtraPenetration = HK_REAL_EPSILON; lcInput[i].m_startPointTolerance = HK_REAL_EPSILON; worldCollectors[i].reset(); treeCollectors[i].reset(); } { HK_ASSERT(0x3fe8daf1, m_world->m_kdTreeManager->isUpToDate()); HK_TIME_CODE_BLOCK("kdtreeLinearCast", HK_NULL); for (int i=0; i < numCasts; i++) { m_world->linearCast(castCollidables[i], lcInput[i], treeCollectors[i] ); } } { HK_TIME_CODE_BLOCK("worldLinearCast", HK_NULL); // // Mark the world's kd-tree as dirty, forcing raycasting to go through the old (slow) hkp3AxisSweep algorithm // You should NOT usually be doing this. // m_world->markKdTreeDirty(); for (int i=0; i < numCasts; i++) { m_world->linearCast(castCollidables[i], lcInput[i], worldCollectors[i] ); } } // Check that the results agree, and draw the results { for (int i=0; i<numCasts; i++) { HK_ASSERT(0x0, worldCollectors[i].hasHit() == treeCollectors[i].hasHit() ); if (worldCollectors[i].hasHit()) { hkReal tolerance = m_world->getCollisionInput()->m_config->m_iterativeLinearCastEarlyOutDistance; hkBool hitFractionsEqual = hkMath::equal(worldCollectors[i].getEarlyOutDistance(), treeCollectors[i].getEarlyOutDistance(), 2.0f*tolerance); hkBool hitCollidablesEqual = worldCollectors[i].getHit().m_rootCollidableB == treeCollectors[i].getHit().m_rootCollidableB ; HK_ASSERT(0x0, hitFractionsEqual || hitCollidablesEqual ); } hkVector4 start = hkGetRigidBody(castCollidables[i])->getPosition(); if (treeCollectors[i].hasHit()) { hkVector4 hitpoint; hitpoint.setInterpolate4(start, lcInput[i].m_to, treeCollectors[i].getEarlyOutDistance() ); HK_DISPLAY_STAR(hitpoint, .1f, hkColor::RED); HK_DISPLAY_ARROW(hitpoint, treeCollectors[i].getHit().m_contact.getNormal(), hkColor::CYAN); HK_DISPLAY_LINE(start, hitpoint, hkColor::BLUE); } else { HK_DISPLAY_LINE(start, lcInput[i].m_to, hkColor::WHITE); } } } }