bool decodeBoundingSphere3f(v8::Handle<v8::Value> toDecodeCenterVec, v8::Handle<v8::Value> toDecodeRadius, BoundingSphere3f& toDecodeTo, String& errMsg) { bool isVec3 = Vec3ValValidate(toDecodeCenterVec); if (! isVec3) { errMsg += "Error decoding bounding sphere. Position argument passed in for center of sphere is not a vec3."; return false; } Vector3f centerPos = Vec3ValExtractF(toDecodeCenterVec); bool isNumber = NumericValidate(toDecodeRadius); if (! isNumber) { errMsg += "Error decoding bounding sphere. Radius argument passed in is not a number. "; return false; } double rad = NumericExtract(toDecodeRadius); toDecodeTo = BoundingSphere3f(centerPos, rad); return true; }
void ObjectFactory::generateRandomObjects(const BoundingBox3f& region, const Duration& duration, double forceRadius, int forceNumRandomObjects) { Time start(Time::null()); Time end = start + duration; Vector3f region_extents = region.extents(); uint32 nobjects = GetOptionValue<uint32>(OBJECT_NUM_RANDOM); if (forceNumRandomObjects) nobjects=forceNumRandomObjects; if (nobjects == 0) return; bool simple = GetOptionValue<bool>(OBJECT_SIMPLE); bool only_2d = GetOptionValue<bool>(OBJECT_2D); std::string motion_path_type = GetOptionValue<String>(OBJECT_STATIC); float driftX = GetOptionValue<float>(OBJECT_DRIFT_X); float driftY = GetOptionValue<float>(OBJECT_DRIFT_Y); float driftZ = GetOptionValue<float>(OBJECT_DRIFT_Z); float percent_queriers = GetOptionValue<float>(OBJECT_QUERY_FRAC); Vector3f driftVecDir(driftX,driftY,driftZ); for(uint32 i = 0; i < nobjects; i++) { UUID id = randomUUID(); ObjectInputs* inputs = new ObjectInputs; Vector3f startpos = region.min() + Vector3f(randFloat()*region_extents.x, randFloat()*region_extents.y, (only_2d ? 0.5 : randFloat())*region_extents.z); double radval = forceRadius; if (!radval) radval=10; float bounds_radius = (simple ? radval : (randFloat()*2*radval)); //SILOG(oh,error,"Creating "<<id.toString()<<" radius "<<bounds_radius); inputs->localID = mLocalIDSource++; if (motion_path_type == "static")//static inputs->motion = new StaticMotionPath(start, startpos); else if (motion_path_type == "drift") //drift { // inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, zfactor); // FIXME inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, 0.5, driftVecDir); // FIXME } else //random inputs->motion = new RandomMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, (only_2d ? 0.0 : 1.0)); // FIXME inputs->bounds = BoundingSphere3f( Vector3f(0, 0, 0), bounds_radius ); inputs->registerQuery = (randFloat() <= percent_queriers); inputs->queryAngle = SolidAngle(SolidAngle::Max / 900.f); // FIXME how to set this? variability by objects? inputs->connectAt = Duration::seconds(0.f); inputs->startTimer = Network::IOTimer::create(mContext->ioService); mObjectIDs.insert(id); mInputs[id] = inputs; } }
JSPresenceStruct::JSPresenceStruct(EmersonScript* parent,PresStructRestoreParams& psrp,Vector3f center, HostedObject::PresenceToken presToken,JSContextStruct* jscont) : JSPositionListener(parent,NULL), JSSuspendable(), isConnected(false), hasConnectedCallback(false), mPresenceToken(presToken), mContext(NULL) { mLocation = *psrp.mTmv3f; mOrientation = *psrp.mTmq; mMesh = *psrp.mMesh; mBounds = BoundingSphere3f( center ,* psrp.mScale); mSuspendedVelocity = *psrp.mSuspendedVelocity; mSuspendedOrientationVelocity = *psrp.mSuspendedOrientationVelocity; if (psrp.mConnCallback != NULL) { hasConnectedCallback = true; mOnConnectedCallback = v8::Persistent<v8::Function>::New(*psrp.mConnCallback); } if (*psrp.mIsSuspended) suspend(); if (*psrp.mIsCleared) clear(); mContID = *psrp.mContID; if (mContID != jscont->getContextID()) parent->registerFixupSuspendable(this,mContID); else mContext = jscont; if (psrp.mOnProxRemovedEventHandler != NULL) mOnProxRemovedEventHandler = v8::Persistent<v8::Function>::New(*psrp.mOnProxRemovedEventHandler); if (psrp.mOnProxAddedEventHandler != NULL) mOnProxAddedEventHandler = v8::Persistent<v8::Function>::New(*psrp.mOnProxAddedEventHandler); //if we were not connected before, then we will not request the space to go //through the rest of its connection procedure, which means that we should //save the sporef inside psrp if (! *psrp.mIsConnected ) JSPositionListener::setListenTo( psrp.mSporef ,NULL); }
void PintoManagerLocationServiceCache::addAggregate(ServerID sid) { Lock lck(mMutex); assert(mServers.find(sid) == mServers.end()); SpaceServerData old_data = mServers[sid]; // Dummy info, we'll get updates soon. mServers[sid].location = TimedMotionVector3f(Time::null(), MotionVector3f()); mServers[sid].region = BoundingSphere3f(); mServers[sid].maxSize = 0; mServers[sid].aggregate = true; mServers[sid].tracking = 0; mServers[sid].removable = false; // Removal only by removeAggregate }
void CBRLocationServiceCache::processBoundsUpdated(const UUID& uuid, bool agg, const BoundingSphere3f& newval) { Lock lck(mMutex); ObjectDataMap::iterator it = mObjects.find(uuid); if (it == mObjects.end()) return; it->second.bounds = newval; BoundingSphere3f old_region = it->second.region; it->second.region = BoundingSphere3f(newval.center(), 0.f); float32 old_maxSize = it->second.maxSize; it->second.maxSize = newval.radius(); if (!agg) { for(ListenerSet::iterator listen_it = mListeners.begin(); listen_it != mListeners.end(); listen_it++) { (*listen_it)->locationRegionUpdated(uuid, old_region, it->second.region); (*listen_it)->locationMaxSizeUpdated(uuid, old_maxSize, it->second.maxSize); } } }
void CBRLocationServiceCache::objectAdded(const UUID& uuid, bool islocal, bool agg, const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, const BoundingSphere3f& bounds, const String& mesh, const String& phy, const String& zernike) { ObjectData data; data.location = loc; data.orientation = orient; data.bounds = bounds; data.region = BoundingSphere3f(bounds.center(), 0.f); data.maxSize = bounds.radius(); data.mesh = mesh; data.physics = phy; data.zernike = zernike; data.isLocal = islocal; data.exists = true; data.tracking = 0; data.isAggregate = agg; mStrand->post( std::tr1::bind( &CBRLocationServiceCache::processObjectAdded, this, uuid, data ), "CBRLocationServiceCache::processObjectAdded" ); }
void CBRLocationServiceCache::processObjectAdded(const UUID& uuid, bool islocal, bool agg, const TimedMotionVector3f& loc, const TimedMotionQuaternion& orient, const BoundingSphere3f& bounds, const String& mesh, const String& phy) { Lock lck(mMutex); if (mObjects.find(uuid) != mObjects.end()) return; ObjectData data; data.location = loc; data.orientation = orient; data.bounds = bounds; data.region = BoundingSphere3f(bounds.center(), 0.f); data.maxSize = bounds.radius(); data.mesh = mesh; data.physics = phy; data.isLocal = islocal; data.exists = true; data.tracking = 0; data.isAggregate = agg; mObjects[uuid] = data; if (!agg) for(ListenerSet::iterator it = mListeners.begin(); it != mListeners.end(); it++) (*it)->locationConnected(uuid, islocal, loc, data.region, data.maxSize); }
/// Get the bounding sphere containing all objects BoundingSphere3f fullBounds() const { return BoundingSphere3f(centerOffset, fullRadius()); }
/// Get the bounding sphere containing the centers of all objects BoundingSphere3f centerBounds() const { return BoundingSphere3f(centerOffset, centerBoundsRadius); }
void ObjectFactory::generateStaticTraceObjects(const BoundingBox3f& region, const Duration& duration) { Time start(Time::null()); uint32 nobjects = GetOptionValue<uint32>(OBJECT_SL_NUM); if (nobjects == 0) return; String pack_filename = GetOptionValue<String>(OBJECT_SL_FILE); assert(!pack_filename.empty()); String pack_dir = GetOptionValue<String>(OBJECT_PACK_DIR); pack_filename = pack_dir + pack_filename; Vector3f sim_center = GetOptionValue<Vector3f>(OBJECT_SL_CENTER); // First, load in all the objects. FILE* pack_file = fopen(pack_filename.c_str(), "rb"); if (pack_file == NULL) { SILOG(objectfactory,error,"Couldn't open object pack file, not generating any objects."); assert(false); return; } TraceObjectMap trace_objects; // parse each line: uuid x y z t rad SLEntry ent; char uuid[256]; while( !feof(pack_file) && fscanf(pack_file, "%s %f %f %f %d %f", uuid, &ent.pos.x, &ent.pos.y, &ent.pos.z, &ent.t, &ent.rad) ) { ent.uuid = UUID(std::string(uuid), UUID::HumanReadable()); //SILOG(oh,error,"Preating "<<ent.uuid.toString()<<" radius "<<ent.rad); TraceObjectMap::iterator obj_it = trace_objects.find(ent.uuid); if (obj_it == trace_objects.end()) { trace_objects[ent.uuid] = ObjectUpdateList(); obj_it = trace_objects.find(ent.uuid); } obj_it->second[ent.t] = ent; } fclose(pack_file); // Now get a version sorted by distance from typedef std::set<ObjectUpdateList, SortObjectUpdateListByDist> ObjectsByDistanceList; ObjectsByDistanceList objs_by_dist = ObjectsByDistanceList( SortObjectUpdateListByDist(sim_center) ); for(TraceObjectMap::iterator obj_it = trace_objects.begin(); obj_it != trace_objects.end(); obj_it++) objs_by_dist.insert(obj_it->second); // Finally, for the number of objects requested, insert the data ObjectsByDistanceList::iterator obj_it = objs_by_dist.begin(); for(uint32 i = 0; i < nobjects; i++, obj_it++) { ObjectInputs* inputs = new ObjectInputs; SLEntry first = (obj_it->begin())->second; inputs->localID = mLocalIDSource++; inputs->motion = new StaticMotionPath(Time::microseconds(first.t*1000), first.pos); inputs->bounds = BoundingSphere3f( Vector3f(0, 0, 0), first.rad ); inputs->registerQuery = false; inputs->queryAngle = SolidAngle::Max; inputs->connectAt = Duration::seconds(0.f); inputs->startTimer = Network::IOTimer::create(mContext->ioService); mObjectIDs.insert(first.uuid); mInputs[first.uuid] = inputs; } }
/** Object packs are our own custom format for simple, fixed, object tests. The file format is * a simple binary dump of each objects information: * * struct ObjectInformation { * uint64 object_id; * double x; * double y; * double z; * double radius; * }; * * This gives the minimal information for a static object and allows you to seek directly to any * object in the file, making it easy to split the file across multiple object hosts. */ void ObjectFactory::generatePackObjects(const BoundingBox3f& region, const Duration& duration) { bool dump_pack = GetOptionValue<bool>(OBJECT_PACK_DUMP); if (dump_pack) return; // If we're dumping objects, don't load // from a pack Time start(Time::null()); uint32 nobjects = GetOptionValue<uint32>(OBJECT_PACK_NUM); if (nobjects == 0) return; String pack_filename = GetOptionValue<String>(OBJECT_PACK); assert(!pack_filename.empty()); String pack_dir = GetOptionValue<String>(OBJECT_PACK_DIR); pack_filename = pack_dir + pack_filename; FILE* pack_file = fopen(pack_filename.c_str(), "rb"); if (pack_file == NULL) { SILOG(objectfactory,error,"Couldn't open object pack file, not generating any objects."); assert(false); return; } // First offset ourselves into the file uint32 pack_offset = GetOptionValue<uint32>(OBJECT_PACK_OFFSET); uint32 obj_pack_size = 8 + // objid 8 + // radius 8 + // x 8 + // y 8 + // z 0; int seek_success = fseek( pack_file, obj_pack_size * pack_offset, SEEK_SET ); if (seek_success != 0) { SILOG(objectfactory,error,"Couldn't seek to appropriate offset in object pack file."); fclose(pack_file); return; } for(uint32 i = 0; i < nobjects; i++) { ObjectInputs* inputs = new ObjectInputs; uint64 pack_objid = 0; double x = 0, y = 0, z = 0, rad = 0; fread( &pack_objid, sizeof(uint64), 1, pack_file ); fread( &x, sizeof(double), 1, pack_file ); fread( &y, sizeof(double), 1, pack_file ); fread( &z, sizeof(double), 1, pack_file ); fread( &rad, sizeof(double), 1, pack_file ); UUID id = pack2UUID(pack_objid); Vector3f startpos((float)x, (float)y, (float)z); float bounds_radius = (float)rad; //SILOG(oh,error,"Preating "<<id.toString()<<" radius "<<bounds_radius); inputs->localID = mLocalIDSource++; inputs->motion = new StaticMotionPath(start, startpos); inputs->bounds = BoundingSphere3f( Vector3f(0, 0, 0), bounds_radius ); inputs->registerQuery = false; inputs->queryAngle = SolidAngle::Max; inputs->connectAt = Duration::seconds(0.f); inputs->startTimer = Network::IOTimer::create(mContext->ioService); mObjectIDs.insert(id); mInputs[id] = inputs; } fclose(pack_file); }