void StandardLocationService::locationUpdate(UUID source, void* buffer, uint32 length) { Sirikata::Protocol::Loc::Container loc_container; bool parse_success = loc_container.ParseFromString( String((char*) buffer, length) ); if (!parse_success) { LOG_INVALID_MESSAGE_BUFFER(standardloc, error, ((char*)buffer), length); return; } if (loc_container.has_update_request()) { Sirikata::Protocol::Loc::LocationUpdateRequest request = loc_container.update_request(); TrackingType obj_type = type(source); if (obj_type == Local) { LocationMap::iterator loc_it = mLocations.find( source ); assert(loc_it != mLocations.end()); if (request.has_location()) { TimedMotionVector3f newloc( request.location().t(), MotionVector3f( request.location().position(), request.location().velocity() ) ); loc_it->second.location = newloc; notifyLocalLocationUpdated( source, loc_it->second.aggregate, newloc ); CONTEXT_SPACETRACE(serverLoc, mContext->id(), mContext->id(), source, newloc ); } if (request.has_bounds()) { BoundingSphere3f newbounds = request.bounds(); loc_it->second.bounds = newbounds; notifyLocalBoundsUpdated( source, loc_it->second.aggregate, newbounds ); } if (request.has_mesh()) { String newmesh = request.mesh(); loc_it->second.mesh = newmesh; notifyLocalMeshUpdated( source, loc_it->second.aggregate, newmesh ); } if (request.has_orientation()) { TimedMotionQuaternion neworient( request.orientation().t(), MotionQuaternion( request.orientation().position(), request.orientation().velocity() ) ); loc_it->second.orientation = neworient; notifyLocalOrientationUpdated( source, loc_it->second.aggregate, neworient ); } if (request.has_physics()) { String newphy = request.physics(); loc_it->second.physics = newphy; notifyLocalPhysicsUpdated( source, loc_it->second.aggregate, newphy ); } } else { // Warn about update to non-local object } } }
void SimpleCameraObjectScript::rotateAction(Vector3f about, float amount) { // Get the updated position Time now = context()->simTime(); Location loc = mSelfProxy->extrapolateLocation(now); const Quaternion &orient = loc.getOrientation(); TimedMotionQuaternion neworient(now, MotionQuaternion(loc.getOrientation(), Quaternion(about, amount))); mParent->requestOrientationUpdate(mID.space(), mID.object(), neworient); }
void SimpleCameraObjectScript::rotateAction(Vector3f about, float amount) { // Get the updated position Time now = context()->simTime(); Location loc = mSelfProxy->extrapolateLocation(now); const Quaternion &orient = loc.getOrientation(); TimedMotionQuaternion neworient(now, MotionQuaternion(loc.getOrientation(), Quaternion(about, amount))); mParent->requestOrientationUpdate(mID.space(), mID.object(), neworient); // And update our local Proxy's information, assuming the move will be successful mSelfProxy->setOrientation(neworient, 0, true); }
void SimpleCameraObjectScript::stableRotateAction(float dir, float amount) { // Get the updated position Time now = context()->simTime(); Location loc = mSelfProxy->extrapolateLocation(now); const Quaternion &orient = loc.getOrientation(); double p, r, y; quat2Euler(orient, p, r, y); Vector3f raxis; raxis.x = 0; raxis.y = std::cos(p*DEG2RAD); raxis.z = -std::sin(p*DEG2RAD); // Request updates from spcae TimedMotionQuaternion neworient(now, MotionQuaternion(loc.getOrientation(), Quaternion(raxis, dir*amount))); mParent->requestOrientationUpdate(mID.space(), mID.object(), neworient); }
void StandardLocationService::receiveMessage(Message* msg) { assert(msg->dest_port() == SERVER_PORT_LOCATION); Sirikata::Protocol::Loc::BulkLocationUpdate contents; bool parsed = parsePBJMessage(&contents, msg->payload()); if (parsed) { for(int32 idx = 0; idx < contents.update_size(); idx++) { Sirikata::Protocol::Loc::LocationUpdate update = contents.update(idx); // Its possible we'll get an out of date update. We only use this update // if (a) we have this object marked as a replica object and (b) we don't // have this object marked as a local object if (type(update.object()) != Replica) continue; LocationMap::iterator loc_it = mLocations.find( update.object() ); // We can safely make this assertion right now because space server // to space server loc and prox are on the same reliable channel. If // this goes away then a) we can't make this assertion and b) we // need an OrphanLocUpdateManager to save updates where this // condition is false so they can be applied once the prox update // arrives. assert(loc_it != mLocations.end()); if (update.has_location()) { TimedMotionVector3f newloc( update.location().t(), MotionVector3f( update.location().position(), update.location().velocity() ) ); loc_it->second.location = newloc; notifyReplicaLocationUpdated( update.object(), newloc ); CONTEXT_SPACETRACE(serverLoc, msg->source_server(), mContext->id(), update.object(), newloc ); } if (update.has_orientation()) { TimedMotionQuaternion neworient( update.orientation().t(), MotionQuaternion( update.orientation().position(), update.orientation().velocity() ) ); loc_it->second.orientation = neworient; notifyReplicaOrientationUpdated( update.object(), neworient ); } if (update.has_bounds()) { BoundingSphere3f newbounds = update.bounds(); loc_it->second.bounds = newbounds; notifyReplicaBoundsUpdated( update.object(), newbounds ); } if (update.has_mesh()) { String newmesh = update.mesh(); loc_it->second.mesh = newmesh; notifyReplicaMeshUpdated( update.object(), newmesh ); } if (update.has_physics()) { String newphy = update.physics(); loc_it->second.physics = newphy; notifyReplicaPhysicsUpdated( update.object(), newphy ); } } } delete msg; }