Skip to content

Commit

Permalink
Merge pull request #567 from allenai/revert-565-fixDirectionalPush
Browse files Browse the repository at this point in the history
Revert "Fix pushAngle in DirectionalPush"
  • Loading branch information
mattdeitke authored Jan 11, 2021
2 parents 885c3f9 + ee8a8dd commit 51f30d5
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 62 deletions.
40 changes: 25 additions & 15 deletions unity/Assets/Scripts/DebugInputField.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,22 +2200,25 @@ public void Execute(string command)

case "dirpush":
{
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = "DirectionalPush";
ServerAction action = new ServerAction();
action.action = "DirectionalPush";

if (splitcommand.Length > 1 && splitcommand.Length < 3) {
action["objectId"] = splitcommand[1];
action["moveMagnitude"] = 10;
} else if (splitcommand.Length > 2) {
action["objectId"] = splitcommand[1];
action["moveMagnitude"] = float.Parse(splitcommand[2]);
} else {
action["moveMagnitude"] = 159f;
if (splitcommand.Length > 1 && splitcommand.Length < 3)
{
action.objectId = splitcommand[1];
action.moveMagnitude = 10f;//4000f;
}

action["pushAngle"] = 279f;
action["x"] = 0.5f;
action["y"] = 0.5f;
else if(splitcommand.Length > 2)
{
action.objectId = splitcommand[1];
action.moveMagnitude = float.Parse(splitcommand[2]);
}

action.pushAngle = 279f;
action.moveMagnitude = 159f;
action.x = 0.5f;
action.y = 0.5f;
PhysicsController.ProcessControlCommand(action);
break;
}
Expand All @@ -2224,13 +2227,20 @@ public void Execute(string command)
{
Dictionary<string, object> action = new Dictionary<string, object>();
action["action"] = "ToggleObjectOn";
if (splitcommand.Length > 1) {
if (splitcommand.Length > 1)
{
action["objectId"] = splitcommand[1];
} else {
}

else
{
//action.objectId = Agent.GetComponent<PhysicsRemoteFPSAgentController>().ObjectIdOfClosestToggleObject();
action["x"] = 0.5f;
action["y"] = 0.5f;
}

PhysicsController.ProcessControlCommand(action);

break;
}

Expand Down
91 changes: 44 additions & 47 deletions unity/Assets/Scripts/PhysicsRemoteFPSAgentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1886,65 +1886,54 @@ public void PullObject(ServerAction action) {
ApplyForceObject(action);
}

public void DirectionalPush(
string objectId = null,
float? x = null,
float? y = null,
float? moveMagnitude = null,
float? pushAngle = null,
bool forceAction = false
) {
if (ItemInHand != null && objectId == ItemInHand.GetComponent<SimObjPhysics>().objectID) {
//pass in a magnitude and an angle offset to push an object relative to agent forward
public void DirectionalPush(ServerAction action)
{
if (ItemInHand != null && action.objectId == ItemInHand.GetComponent<SimObjPhysics>().objectID) {
errorMessage = "Please use Throw for an item in the Agent's Hand";
Debug.Log(errorMessage);
actionFinished(false);
return;
}

if (pushAngle == null) {
errorMessage = "pushAngle must be specified";
Debug.Log(errorMessage);
actionFinished(false);
return;
}

if (moveMagnitude == null) {
errorMessage = "moveMagnitude must be specified";
//the direction vecctor to push the target object defined by action.PushAngle
//degrees clockwise from the agent's forward, the PushAngle must be less than 360
if(action.pushAngle <= 0 || action.pushAngle >= 360)
{
errorMessage = "please give a PushAngle between 0 and 360.";
Debug.Log(errorMessage);
actionFinished(false);
return;
}

// the direction vector to push the target object defined by pushAngle
// degrees clockwise from the agent's forward, the PushAngle must be less than 360
pushAngle = Mathf.Abs((float) pushAngle % 360);

SimObjPhysics target = null;

if(objectId == null) {
if (x == null || y == null) {
errorMessage = "Must specify either (x and y) or objectId";
Debug.Log(errorMessage);
actionFinished(false);
return;
}
if(!ScreenToWorldTarget((float) x, (float) y, ref target, !forceAction)) {
// error message is set insice ScreenToWorldTarget
if (action.forceAction) {
action.forceVisible = true;
}

if(action.objectId == null)
{
if(!ScreenToWorldTarget(action.x, action.y, ref target, !action.forceAction))
{
//error message is set insice ScreenToWorldTarget
actionFinished(false);
return;
}
}

// an objectId was given, so find that target in the scene if it exists
else {
if (!physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(objectId)) {
//an objectId was given, so find that target in the scene if it exists
else
{
if (!physicsSceneManager.ObjectIdToSimObjPhysics.ContainsKey(action.objectId)) {
errorMessage = "Object ID appears to be invalid.";
actionFinished(false);
return;
}

// if object is in the scene and visible, assign it to 'target'
foreach (SimObjPhysics sop in VisibleSimObjs(objectId, forceVisible: forceAction)) {
//if object is in the scene and visible, assign it to 'target'
foreach (SimObjPhysics sop in VisibleSimObjs(action))
{
target = sop;
}
}
Expand All @@ -1964,38 +1953,46 @@ public void DirectionalPush(
return;
}

//print(target.name);

if (!target.GetComponent<SimObjPhysics>()) {
errorMessage = "Target must be SimObjPhysics!";
Debug.Log(errorMessage);
actionFinished(false);
return;
}

bool canBePushed = (
target.PrimaryProperty == SimObjPrimaryProperty.CanPickup ||
target.PrimaryProperty == SimObjPrimaryProperty.Moveable);
bool canbepushed = false;

if (target.PrimaryProperty == SimObjPrimaryProperty.CanPickup ||
target.PrimaryProperty == SimObjPrimaryProperty.Moveable)
canbepushed = true;

if (!canBePushed) {
if (!canbepushed) {
errorMessage = "Target Primary Property type incompatible with push/pull";
actionFinished(false);
return;
}

if (!forceAction && target.isInteractable == false) {
if (!action.forceAction && target.isInteractable == false) {
errorMessage = "Target is not interactable and is probably occluded by something!";
actionFinished(false);
return;
}

// find the Direction to push the object based on PushAngle
//find the Direction to push the object basec on action.PushAngle
Vector3 agentForward = transform.forward;
float pushAngleInRadians = ((float) pushAngle) * Mathf.PI / -180; //using -180 so positive PushAngle values go clockwise
float pushAngleInRadians = action.pushAngle * Mathf.PI/-180; //using -180 so positive PushAngle values go clockwise

Vector3 direction = new Vector3((agentForward.x * Mathf.Cos(pushAngleInRadians) - agentForward.z * Mathf.Sin(pushAngleInRadians)), 0,
agentForward.x * Mathf.Sin(pushAngleInRadians) + agentForward.z * Mathf.Cos(pushAngleInRadians));

ServerAction pushAction = new ServerAction();
pushAction.x = agentForward.x * Mathf.Cos(pushAngleInRadians) - agentForward.z * Mathf.Sin(pushAngleInRadians);
pushAction.y = 0;
pushAction.z = agentForward.x * Mathf.Sin(pushAngleInRadians) + agentForward.z * Mathf.Cos(pushAngleInRadians);
pushAction.moveMagnitude = (float) moveMagnitude;
pushAction.x = direction.x;
pushAction.y = direction.y;
pushAction.z = direction.z;

pushAction.moveMagnitude = action.moveMagnitude;

target.GetComponent<Rigidbody>().isKinematic = false;
sopApplyForce(pushAction, target);
Expand Down

0 comments on commit 51f30d5

Please sign in to comment.