示例#1
0
void LLAgentListener::requestTouch(LLSD const & event_data) const
{
	LLViewerObject *object = NULL;
	
	if (event_data.has("obj_uuid"))
	{
		object = gObjectList.findObject(event_data["obj_uuid"]);
	}
	else if (event_data.has("position"))
	{
		LLVector3 target_position = ll_vector3_from_sd(event_data["position"]);
		object = findObjectClosestTo(target_position);
	}

	S32 face = 0;
	if (event_data.has("face"))
	{
		face = event_data["face"].asInteger();
	}

    if (object && object->getPCode() == LL_PCODE_VOLUME)
    {
		// Fake enough pick info to get it to (hopefully) work
		LLPickInfo pick;
		pick.mObjectFace = face;

		/*
		These values are sent to the simulator, but face seems to be easiest to use

		pick.mUVCoords	 "UVCoord"
		pick.mSTCoords	"STCoord"	
		pick.mObjectFace	"FaceIndex"
		pick.mIntersection	"Position"
		pick.mNormal	"Normal"
		pick.mBinormal	"Binormal"
		*/

		// A touch is a sketchy message sequence ... send a grab, immediately
		// followed by un-grabbing, crossing fingers and hoping packets arrive in
		// the correct order
		send_ObjectGrab_message(object, pick, LLVector3::zero);
		send_ObjectDeGrab_message(object, pick);
    }
	else
	{
		llwarns << "LLAgent requestTouch could not find the touch target " 
			<< event_data["obj_uuid"].asUUID() << llendl;
	}
}
void LLToolGrab::startGrab()
{
	// Compute grab_offset in the OBJECT's root's coordinate frame
	// (sometimes root == object)
	LLViewerObject* objectp = mGrabPick.getObject();
	if (!objectp)
	{
		return;
	}

	LLViewerObject *root = (LLViewerObject *)objectp->getRoot();

	// drag from center
	LLVector3d grab_start_global = root->getPositionGlobal();

	// Where the grab starts, relative to the center of the root object of the set.
	// JC - This code looks wonky, but I believe it does the right thing.
	// Otherwise, when you grab a linked object set, it "pops" on the start
	// of the drag.
	LLVector3d grab_offsetd = root->getPositionGlobal() - objectp->getPositionGlobal();

	LLVector3 grab_offset;
	grab_offset.setVec(grab_offsetd);

	LLQuaternion rotation = root->getRotation();
	rotation.conjQuat();
	grab_offset = grab_offset * rotation;

	// This planar drag starts at the grab point
	mDragStartPointGlobal = grab_start_global;
	mDragStartFromCamera = grab_start_global - gAgentCamera.getCameraPositionGlobal();

	send_ObjectGrab_message(objectp, mGrabPick, grab_offset);

	mGrabOffsetFromCenterInitial = grab_offset;
	mGrabHiddenOffsetFromCamera = mDragStartFromCamera;

	mGrabTimer.reset();

	mLastUVCoords = mGrabPick.mUVCoords;
	mLastSTCoords = mGrabPick.mSTCoords;
	mLastFace = mGrabPick.mObjectFace;
	mLastIntersection = mGrabPick.mIntersection;
	mLastNormal = mGrabPick.mNormal;
	mLastBinormal = mGrabPick.mBinormal;
	mLastGrabPos = LLVector3(-1.f, -1.f, -1.f);
}