/// <summary> /// Changes this transform from local to global space by iteratively progressing to parent objects transforms. /// </summary> /// <param name="t"></param> /// <param name="sceneAccess"></param> /// <returns></returns> public static MTransform LocalToGlobal(this MTransform t, MSceneAccess.Iface sceneAccess) { MTransform newT = t; if (t.Parent != null) { MSceneObject o = sceneAccess.GetSceneObjectByID(t.Parent); if (o != null) { newT = t.Multiply(o.Transform); if (o.Transform.Parent != null) { newT.Parent = o.Transform.Parent; newT = newT.LocalToGlobal(sceneAccess); } } } return(newT); }
public override MBoolResponse AssignInstruction(MInstruction instruction, MSimulationState simulationState) { //Assign the instruction this.instruction = instruction; MBoolResponse response = new MBoolResponse(true); if (instruction.Constraints.Count > 0 && instruction.Constraints[0].GeometryConstraint != null) { MSceneObject parent = this.SceneAccess.GetSceneObjectByID(instruction.Constraints[0].GeometryConstraint.ParentObjectID); if (instruction.Constraints[0].GeometryConstraint.ParentToConstraint != null) { MTransform ptc = instruction.Constraints[0].GeometryConstraint.ParentToConstraint; String gtp = ptc.Parent; if (gtp != null && this.SceneAccess.GetSceneObjectByID(gtp) != null) { // transform parent takes precedent. this.targetTransform = ptc.LocalToGlobal(this.SceneAccess); } else if (parent != null) { // parent to constraint has not valid parent, thus the geometry constraint parent is this.targetTransform = ptc.Multiply(parent.Transform.LocalToGlobal(this.SceneAccess)); } else { this.targetTransform = ptc; } } else { MVector3 pos = new MVector3(0, 0, 0); if (instruction.Constraints[0].GeometryConstraint.TranslationConstraint != null) { MTranslationConstraint trlCstr = instruction.Constraints[0].GeometryConstraint.TranslationConstraint; if (parent != null) { pos = parent.Transform.Position.Add(trlCstr.GetVector3()); } else { pos = trlCstr.GetVector3(); } } MQuaternion rot = new MQuaternion(0, 0, 0, 1); if (instruction.Constraints[0].GeometryConstraint.RotationConstraint != null) { MRotationConstraint rtCstr = instruction.Constraints[0].GeometryConstraint.RotationConstraint; if (parent != null) { rot = rtCstr.GetQuaternion().Multiply(parent.Transform.Rotation); } else { rot = rtCstr.GetQuaternion(); } } this.targetTransform = new MTransform("", pos, rot); } } else { response = new MBoolResponse(false) { LogData = new List <string>() { "Required target constraint (MGeometryConstraint) not defined" } }; } //Extract the velocity if defined if (instruction.Properties.ContainsKey("Velocity")) { Console.WriteLine("vel: " + instruction.Properties["Velocity"]); float.TryParse(instruction.Properties["Velocity"], System.Globalization.NumberStyles.Float, System.Globalization.CultureInfo.InvariantCulture, out velocity); } else { velocity = -1.0f; } /* * //Get the target id * if (instruction.Properties.ContainsKey("TargetID")) * this.targetTransform = this.SceneAccess.GetTransformByID(instruction.Properties["TargetID"]); * //Error id not available * else * { * return new MBoolResponse(false) * { * }; * }*/ //Return true/success return(response); }