public async Task ShowRotations() { var rotations = await _rotationsApi.Get <List <Model.Rotation> >(null); rotations.RemoveAll(r => !r.Available); var currentDate = DateTime.Now.Date; rotations.RemoveAll(r => !((currentDate > r.From) && (currentDate < r.To))); rotations.RemoveAll(r => (r.ForBirthday) && (currentDate.Date != APIService.User.BirthDate.Date)); rotations = (from item in rotations orderby item.ForBirthday descending select item).ToList(); Rotations.Clear(); foreach (var rotation in rotations) { var movie = await _moviesApi.GetById <Model.Movie>(rotation.MovieId); var show = await _showsApi.GetById <Model.Show>(rotation.ShowId); var newItem = new Model.ObservableLists.RotationItem() { Birthday = rotation.ForBirthday, From = rotation.From.Date.ToString("dd. MMMM yy"), To = rotation.To.ToString("dd. MMMM yy"), Description = rotation.Description, MovieImage = movie.ImageLink, ShowImage = show.ImageLink, RotationId = rotation.RotationId }; Rotations.Add(newItem); } }
public void AddRotation(String[] Parameters) { Affectation Affectation = new Affectation("R", GroupDepth, Parameters, CurrentLoop); Rotations.Add(Affectation); Content += Affectation.getEquivalentLine(); }
public void AddTransform(Matrix transform, float rotation, Color tint, bool rebuild) { LocalTransforms.Add(transform * Matrix.Invert(GlobalTransform)); Rotations.Add(rotation); Tints.Add(tint); if (rebuild) { RebuildPrimitive(); } }
/// <summary> /// Create a rotation /// </summary> /// <param name="name">Name</param> /// <param name="description">Description</param> /// <returns>Rotation</returns> public Rotation CreateRotation(string name, string description) { Rotation rotation = new Rotation(name, description); if (Rotations.Contains(rotation)) { string msg = String.Format(WorkSchedule.GetMessage("rotation.already.exists"), name); throw new Exception(msg); } Rotations.Add(rotation); rotation.WorkSchedule = this; return(rotation); }
public void Deserialize(Stream stream) { using (var r = stream.ToBinaryReader(true)) { Unk = r.ReadInt32(); int count = r.ReadInt32(); for (int j = 0; j < count; j++) { Rotations.Add(new Quaternion(r.ReadSingle(), r.ReadSingle(), r.ReadSingle(), r.ReadSingle())); } count = r.ReadInt32(); for (int j = 0; j < count; j++) { Positions.Add(new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle())); } } }
private void LoadDotVision(Picture picture) { string fileName = picture.Directorio + @"\.vision"; Rotations.Clear(); const Int32 BufferSize = 128; using (var fileStream = File.OpenRead(fileName)) using (var streamReader = new StreamReader(fileStream, System.Text.Encoding.UTF8, true, BufferSize)) { string line; while ((line = streamReader.ReadLine()) != null) { string[] valores = line.Split('|'); double angulo = 0; double.TryParse(valores[1], out angulo); Rotations.Add(new Rotation(valores[0], angulo)); } } }
private void AddRotationControl(RotationInfo ri) { var DockPanel = new DockPanel() { Tag = ri }; var Label = new Label() { MinWidth = 30 }; Label.Content = ri.Axis; var ctm = new ContextMenu(); var rm = new MenuItem(); rm.Header = "Remove"; rm.Tag = DockPanel; rm.Click += RotationSlider_Remove; ctm.Items.Add(rm); DockPanel.ContextMenu = ctm; DockPanel.SetDock(Label, Dock.Left); var Slider = new Slider() { Maximum = 100, TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight, TickFrequency = 5, Focusable = false, IsSnapToTickEnabled = true, Tag = ri }; Slider.ValueChanged += RotationSlider_ValueChanged; DockPanel.Children.Add(Label); DockPanel.Children.Add(Slider); Rotations.Add(ri); RotationsList.Children.Add(DockPanel); }
public void HandleModEnable() { Main.Mod.Debug(MethodBase.GetCurrentMethod()); foreach (KeyValuePair <string, string> kvp in CloneGuids) { Main.Mod.Debug(Positions.ContainsKey(kvp.Value)); if (Positions.ContainsKey(kvp.Value)) { NewVendors[kvp.Value].Posistion = Positions[kvp.Value]; } else { Positions.Add(CloneGuids["bokken"], bokkenPos); } if (Rotations.ContainsKey(kvp.Value)) { NewVendors[kvp.Value].Rotation = Quaternion.LookRotation(Rotations[kvp.Value]); } else { Rotations.Add(CloneGuids["bokken"], bokkenRot); } } }
// CalculateBoneRotations is called for calculating the bone rotations(global/local) in the method of joint angle mapping public void CalculateBoneRotations() { // calculate the Bone Global Rotations for (int i = 0; i < 15; i++) { Rotations.Add(Quaternion.identity); // initialize the Rotations } // check whether using absolute coordinate rotation and pick the different methods(aligning coordinates/relatively rotating) to calculate the bone rotations if (UseAbsoluteCoordinate) { // calculate the bone global rotations using the method of aligning bone coordinates(make sure that the coordinate system will be the same(fixed to the bones) for every frame based on the human joint keypoints) Rotations[0] = CalculateGlobalRotation(Positions[6] - Positions[2], Positions[7] - Positions[6]); // Rotations[1] = CalculateGlobalRotation(Positions[2] - Positions[1], Positions[1] - Positions[0]); // rightThigh Rotations[2] = CalculateGlobalRotation(Positions[1] - Positions[0], Positions[1] - Positions[2]); // rightCalf Rotations[3] = CalculateGlobalRotation(Positions[6] - Positions[3], Positions[6] - Positions[7]); // Rotations[4] = CalculateGlobalRotation(Positions[3] - Positions[4], Positions[4] - Positions[5]); // leftThigh Rotations[5] = CalculateGlobalRotation(Positions[4] - Positions[5], Positions[4] - Positions[3]); // leftCalf Rotations[6] = CalculateGlobalRotation(Positions[6] - Positions[7], Positions[3] - Positions[2]); // Rotations[7] = CalculateGlobalRotation(Positions[7] - Positions[8], Positions[6] - Positions[7]); // Rotations[8] = CalculateGlobalRotation(Positions[8] - Positions[9], Positions[7] - Positions[8]); // Rotations[9] = CalculateGlobalRotation(Positions[8] - Positions[12], Positions[8] - Positions[7]); // rightClavicle Rotations[10] = CalculateGlobalRotation(Positions[12] - Positions[11], Positions[11] - Positions[10]); // rightUpperArm Rotations[11] = CalculateGlobalRotation(Positions[11] - Positions[10], Positions[11] - Positions[12]); // rightForearm Rotations[12] = CalculateGlobalRotation(Positions[8] - Positions[13], Positions[7] - Positions[8]); // Rotations[13] = CalculateGlobalRotation(Positions[13] - Positions[14], Positions[14] - Positions[15]); // leftUpperArm Rotations[14] = CalculateGlobalRotation(Positions[14] - Positions[15], Positions[14] - Positions[13]); // leftForearm } else { // define the initial reference coordinate rotations var rotLeftForward = Quaternion.LookRotation(Vector3.left, Vector3.forward); var rotLeftBack = Quaternion.LookRotation(Vector3.left, Vector3.back); var rotLeftDown = Quaternion.LookRotation(Vector3.left, Vector3.down); var rotLeftUp = Quaternion.LookRotation(Vector3.left, Vector3.up); // TODO: calculate the bone global rotations using the method of relatively rotating Rotations[0] = CalculateGlobalRotation(Positions[2] - Positions[6], Positions[7] - Positions[6], rotLeftDown); // rightHipBone Rotations[1] = CalculateGlobalRotation(Positions[1] - Positions[2], Positions[0] - Positions[1], rotLeftForward); // rightThigh Rotations[2] = CalculateGlobalRotation(Positions[0] - Positions[1], Positions[2] - Positions[1], rotLeftForward); // rightCalf Rotations[3] = CalculateGlobalRotation(Positions[3] - Positions[6], Positions[6] - Positions[7], rotLeftDown); // leftHipBone Rotations[4] = CalculateGlobalRotation(Positions[4] - Positions[3], Positions[5] - Positions[4], rotLeftForward); // leftThigh Rotations[5] = CalculateGlobalRotation(Positions[5] - Positions[4], Positions[3] - Positions[4], rotLeftForward); // leftCalf Rotations[6] = CalculateGlobalRotation(Positions[7] - Positions[6], Positions[3] - Positions[2], rotLeftDown); // waist Rotations[7] = CalculateGlobalRotation(Positions[8] - Positions[7], Positions[6] - Positions[7], rotLeftDown); // chest Rotations[8] = CalculateGlobalRotation(Positions[9] - Positions[8], Positions[13] - Positions[12], rotLeftDown); // neck Rotations[9] = CalculateGlobalRotation(Positions[12] - Positions[8], Positions[8] - Positions[7], rotLeftUp); // rightClavicle Rotations[10] = CalculateGlobalRotation(Positions[11] - Positions[12], Positions[10] - Positions[11], rotLeftBack); // rightUpperArm Rotations[11] = CalculateGlobalRotation(Positions[10] - Positions[11], Positions[12] - Positions[11], rotLeftBack); // rightForearm Rotations[12] = CalculateGlobalRotation(Positions[13] - Positions[8], Positions[7] - Positions[8], rotLeftUp); // leftClavicle Rotations[13] = CalculateGlobalRotation(Positions[14] - Positions[13], Positions[15] - Positions[14], rotLeftBack); // leftUpperArm Rotations[14] = CalculateGlobalRotation(Positions[15] - Positions[14], Positions[13] - Positions[14], rotLeftBack); // leftForearm } // calculate the Bone Local Rotations for (int j = 0; j < 15; j++) { LocalRotations.Add(Quaternion.identity); // initialize the LocalRotations } // check whether using local rotation of bones for driving avatar if (UseLocalRotation) { // calculate the bone local rotations using the method of relatively rotating LocalRotations[0] = CalculateLocalRotation(Rotations[6], Rotations[0]); // rightHipBone LocalRotations[1] = CalculateLocalRotation(Rotations[0], Rotations[1]); // rightThigh LocalRotations[2] = CalculateLocalRotation(Rotations[1], Rotations[2]); // rightCalf LocalRotations[3] = CalculateLocalRotation(Rotations[6], Rotations[3]); // leftHipBone LocalRotations[4] = CalculateLocalRotation(Rotations[3], Rotations[4]); // leftThigh LocalRotations[5] = CalculateLocalRotation(Rotations[4], Rotations[5]); // leftCalf LocalRotations[6] = Rotations[6]; // waist LocalRotations[7] = CalculateLocalRotation(Rotations[6], Rotations[7]); // chest LocalRotations[8] = CalculateLocalRotation(Rotations[7], Rotations[8]); // neck LocalRotations[9] = CalculateLocalRotation(Rotations[8], Rotations[9]); // rightClavicle LocalRotations[10] = CalculateLocalRotation(Rotations[9], Rotations[10]); // rightUpperArm LocalRotations[11] = CalculateLocalRotation(Rotations[10], Rotations[11]); // rightForearm LocalRotations[12] = CalculateLocalRotation(Rotations[8], Rotations[12]); // leftClavicle LocalRotations[13] = CalculateLocalRotation(Rotations[12], Rotations[13]); // leftUpperArm LocalRotations[14] = CalculateLocalRotation(Rotations[13], Rotations[14]); // leftForearm } }
// Update is called once per frame void Update() { if (!Finish) { if (GravelCount < NumOfGravel) { if (TimeAccumulated > DropTimeInterval) { string fileName = FileNames[rnd.Next() % FileNames.Length]; GameObject loadedObject = new OBJLoader().Load(fileName).transform.GetChild(0).gameObject; PickFileNames.Add(fileName); // add Rigidbody Rigidbody rb = loadedObject.AddComponent <Rigidbody>(); rb.useGravity = true; rb.isKinematic = false; // add MeshCollider MeshCollider mc = loadedObject.AddComponent <MeshCollider>(); mc.convex = true; // set parent loadedObject.transform.parent.parent = Stone; // set position float X = Convert.ToSingle(rnd.NextDouble() * Math.Abs(Xmax - Xmin) + Xmin); float Z = Convert.ToSingle(rnd.NextDouble() * Math.Abs(Zmax - Zmin) + Zmin); loadedObject.transform.position = new Vector3(X, Y, Z); // add position and rotation Positions.Add(Vector3.zero); Rotations.Add(Vector3.zero); GravelCount++; TimeAccumulated = 0; } } else if (TimeAccumulated > CheckTimeInterval) { if (TimeAccumulated > TimeOutThreshold) { Debug.Log("Time out! Just output results directly..."); Finish = true; } else { Debug.Log("Checking..."); Finish = true; for (int i = Positions.Count - 1; i >= 0; i--) { if (CompareVector(Positions[i], Stone.GetChild(i).GetChild(0).position) && CompareVector(Rotations[i], Stone.GetChild(i).GetChild(0).eulerAngles)) { Positions.RemoveAt(i); Rotations.RemoveAt(i); StopGravelsNum++; } else { Finish = false; var newPosition = Stone.GetChild(i).GetChild(0).position; Positions[i] = new Vector3(newPosition.x, newPosition.y, newPosition.z); var newRotation = Stone.GetChild(i).GetChild(0).eulerAngles; Rotations[i] = new Vector3(newRotation.x, newRotation.y, newRotation.z); } } } TimeAccumulated = 0; } TimeAccumulated += Time.deltaTime; } else { if (!FinishDisplayed) { WriteCSV("scene_" + SceneCount.ToString() + ".csv"); WriteXML("scene_" + SceneCount.ToString() + ".xml"); Debug.Log("Finish"); FinishDisplayed = true; SceneCount++; // reset if (SceneCount < NumOfScene) { Finish = false; Positions = new List <Vector3>(); Rotations = new List <Vector3>(); PickFileNames = new List <string>(); GravelCount = 0; TimeAccumulated = 0; FinishDisplayed = false; foreach (Transform child in Stone) { GameObject.Destroy(child.gameObject); } Debug.Log("Start Scene " + SceneCount.ToString()); } } } }
public void CalculateBoneRotations() { // calculate the Bone Global Rotations for (int i = 0; i < 15; i++) { Rotations.Add(Quaternion.identity); // initialize the Rotations } // define the initial reference coordinate rotations var rotLeftForward = Quaternion.LookRotation(Vector3.left, Vector3.forward); var rotLeftBack = Quaternion.LookRotation(Vector3.left, Vector3.back); var rotLeftDown = Quaternion.LookRotation(Vector3.left, Vector3.down); var rotLeftUp = Quaternion.LookRotation(Vector3.left, Vector3.up); // TODO: make sure that the coordinate system will be the same(fixed to the bones) for every frame based on the human joint keypoints Rotations[0] = CalculateGlobalRotation(Positions[2] - Positions[6], Positions[7] - Positions[6], rotLeftDown); Rotations[1] = CalculateGlobalRotation(Positions[1] - Positions[2], Positions[0] - Positions[1], rotLeftForward); Rotations[2] = CalculateGlobalRotation(Positions[0] - Positions[1], Positions[2] - Positions[1], rotLeftForward); Rotations[3] = CalculateGlobalRotation(Positions[3] - Positions[6], Positions[6] - Positions[7], rotLeftDown); Rotations[4] = CalculateGlobalRotation(Positions[4] - Positions[3], Positions[5] - Positions[4], rotLeftForward); Rotations[5] = CalculateGlobalRotation(Positions[5] - Positions[4], Positions[3] - Positions[4], rotLeftForward); Rotations[6] = CalculateGlobalRotation(Positions[7] - Positions[6], Positions[3] - Positions[2], rotLeftDown); Rotations[7] = CalculateGlobalRotation(Positions[8] - Positions[7], Positions[6] - Positions[7], rotLeftDown); Rotations[8] = CalculateGlobalRotation(Positions[9] - Positions[8], Positions[13] - Positions[12], rotLeftDown); Rotations[9] = CalculateGlobalRotation(Positions[12] - Positions[8], Positions[8] - Positions[7], rotLeftUp); Rotations[10] = CalculateGlobalRotation(Positions[11] - Positions[12], Positions[10] - Positions[11], rotLeftBack); Rotations[11] = CalculateGlobalRotation(Positions[10] - Positions[11], Positions[12] - Positions[11], rotLeftBack); Rotations[12] = CalculateGlobalRotation(Positions[13] - Positions[8], Positions[7] - Positions[8], rotLeftUp); Rotations[13] = CalculateGlobalRotation(Positions[14] - Positions[13], Positions[15] - Positions[14], rotLeftBack); Rotations[14] = CalculateGlobalRotation(Positions[15] - Positions[14], Positions[13] - Positions[14], rotLeftBack); // Rotations[0] = CalculateGlobalRotation(Positions[2]-Positions[6], Positions[7]-Positions[6]); // Rotations[1] = CalculateGlobalRotation(Positions[1]-Positions[2], Positions[0]-Positions[1]); // Rotations[2] = CalculateGlobalRotation(Positions[0]-Positions[1], Positions[2]-Positions[1]); // Rotations[3] = CalculateGlobalRotation(Positions[3]-Positions[6], Positions[6]-Positions[7]); // Rotations[4] = CalculateGlobalRotation(Positions[4]-Positions[3], Positions[5]-Positions[4]); // Rotations[5] = CalculateGlobalRotation(Positions[5]-Positions[4], Positions[3]-Positions[4]); // Rotations[6] = CalculateGlobalRotation(Positions[7]-Positions[6], Positions[3]-Positions[2]); // Rotations[7] = CalculateGlobalRotation(Positions[8]-Positions[7], Positions[6]-Positions[7]); // Rotations[8] = CalculateGlobalRotation(Positions[9]-Positions[8], Positions[13]-Positions[12]); // Rotations[9] = CalculateGlobalRotation(Positions[12]-Positions[8], Positions[8]-Positions[7]); // Rotations[10] = CalculateGlobalRotation(Positions[11]-Positions[12], Positions[10]-Positions[11]); // Rotations[11] = CalculateGlobalRotation(Positions[10]-Positions[11], Positions[12]-Positions[11]); // Rotations[12] = CalculateGlobalRotation(Positions[13]-Positions[8], Positions[7]-Positions[8]); // Rotations[13] = CalculateGlobalRotation(Positions[14]-Positions[13], Positions[15]-Positions[14]); // Rotations[14] = CalculateGlobalRotation(Positions[15]-Positions[14], Positions[13]-Positions[14]); // calculate the Bone Local Rotations LocalRotations = Rotations.ToList(); // initialize the LocalRotations // construct the reference coordinate rotations var invRightHipBine = Quaternion.Inverse(Rotations[0]); var invRightThigh = Quaternion.Inverse(Rotations[1]); var invLeftHipBone = Quaternion.Inverse(Rotations[3]); var invLeftThigh = Quaternion.Inverse(Rotations[4]); var invWaist = Quaternion.Inverse(Rotations[6]); var invCheset = Quaternion.Inverse(Rotations[7]); var invNeck = Quaternion.Inverse(Rotations[8]); var invRightClavicle = Quaternion.Inverse(Rotations[9]); var invRigthUpperArm = Quaternion.Inverse(Rotations[10]); var invLeftClavicle = Quaternion.Inverse(Rotations[12]); var invLeftUpperArm = Quaternion.Inverse(Rotations[13]); // calculate the bone local roataions of human LocalRotations[0] = invWaist * LocalRotations[0]; LocalRotations[1] = invRightHipBine * LocalRotations[1]; LocalRotations[2] = invRightThigh * LocalRotations[2]; LocalRotations[3] = invWaist * LocalRotations[3]; LocalRotations[4] = invLeftHipBone * LocalRotations[4]; LocalRotations[5] = invLeftThigh * LocalRotations[5]; // LocalRotations[6] = invWaist * LocalRotations[6]; LocalRotations[7] = invWaist * LocalRotations[7]; LocalRotations[8] = invCheset * LocalRotations[8]; LocalRotations[9] = invNeck * LocalRotations[9]; LocalRotations[10] = invRightClavicle * LocalRotations[10]; LocalRotations[11] = invRigthUpperArm * LocalRotations[11]; LocalRotations[12] = invNeck * LocalRotations[12]; LocalRotations[13] = invLeftClavicle * LocalRotations[13]; LocalRotations[14] = invLeftUpperArm * LocalRotations[14]; }
// CalculateBoneRotations is called for calculating the bone rotations(global/local) in the method of joint angle mapping public void CalculateBoneRotations() { // calculate the Bone Global Rotations for (int i = 0; i < 16; i++) { Rotations.Add(Quaternion.identity); // initialize the Rotations } // check whether using absolute coordinate rotation and pick the different methods(aligning coordinates/relatively rotating) to calculate the bone rotations if (UseAbsoluteCoordinate) { // calculate the bone global rotations using the method of aligning bone coordinates(make sure that the coordinate system will be the same(fixed to the bones) for every frame based on the human joint keypoints) Rotations[0] = CalculateGlobalRotation(Positions[6] - Positions[7], Positions[3] - Positions[2], 3); // rightHipBone(rotTypeFlag:3) Rotations[1] = CalculateGlobalRotation(Positions[2] - Positions[1], Positions[1] - Positions[0], 1); // rightThigh(rotTypeFlag:1) Rotations[2] = CalculateGlobalRotation(Positions[1] - Positions[0], Positions[1] - Positions[2], 1); // rightCalf(rotTypeFlag:1) Rotations[3] = CalculateGlobalRotation(Positions[6] - Positions[7], Positions[3] - Positions[2], 3); // leftHipBone(rotTypeFlag:3) Rotations[4] = CalculateGlobalRotation(Positions[3] - Positions[4], Positions[4] - Positions[5], 1); // leftThigh(rotTypeFlag:1) Rotations[5] = CalculateGlobalRotation(Positions[4] - Positions[5], Positions[4] - Positions[3], 1); // leftCalf(rotTypeFlag:1) Rotations[6] = CalculateGlobalRotation(Positions[6] - Positions[7], Positions[3] - Positions[2], 3); // waist(rotTypeFlag:3) Rotations[7] = CalculateGlobalRotation(Positions[7] - Positions[8], Positions[6] - Positions[7], 1); // chest(rotTypeFlag:1) Rotations[8] = CalculateGlobalRotation(Positions[8] - Positions[9], Positions[7] - Positions[8], 1) * new Quaternion(0.0f, 0.0f, 0.342f, 0.940f); // neck(rotTypeFlag:1)(correct the neck up for 40 degrees in z axis rotation direction) Rotations[9] = CalculateGlobalRotation(Positions[9] - Positions[10], Positions[8] - Positions[9], 1); // head(rotTypeFlag:1) Rotations[10] = CalculateGlobalRotation(Positions[8] - Positions[13], Vector3.Cross(Positions[8] - Positions[13], Positions[8] - Positions[7]), 2); // rightClavicle(rotTypeFlag:2) Rotations[11] = CalculateGlobalRotation(Positions[13] - Positions[12], Positions[12] - Positions[11], 1); // rightUpperArm(rotTypeFlag:1) Rotations[12] = CalculateGlobalRotation(Positions[12] - Positions[11], Positions[12] - Positions[13], 1); // rightForearm(rotTypeFlag:1) Rotations[13] = CalculateGlobalRotation(Positions[8] - Positions[14], Vector3.Cross(Positions[8] - Positions[14], Positions[7] - Positions[8]), 2); // leftClavicle(rotTypeFlag:2) Rotations[14] = CalculateGlobalRotation(Positions[14] - Positions[15], Positions[15] - Positions[16], 1); // leftUpperArm(rotTypeFlag:1) Rotations[15] = CalculateGlobalRotation(Positions[15] - Positions[16], Positions[15] - Positions[14], 1); // leftForearm(rotTypeFlag:1) } else { // define the initial reference coordinate rotations var rotLeftForward = Quaternion.LookRotation(Vector3.left, Vector3.forward); var rotLeftBack = Quaternion.LookRotation(Vector3.left, Vector3.back); var rotLeftDown = Quaternion.LookRotation(Vector3.left, Vector3.down); var rotLeftUp = Quaternion.LookRotation(Vector3.left, Vector3.up); // calculate the bone global rotations using the method of relatively rotating Rotations[0] = CalculateGlobalRotation(Positions[2] - Positions[6], Positions[7] - Positions[6], rotLeftDown); // rightHipBone Rotations[1] = CalculateGlobalRotation(Positions[1] - Positions[2], Positions[0] - Positions[1], rotLeftForward); // rightThigh Rotations[2] = CalculateGlobalRotation(Positions[0] - Positions[1], Positions[2] - Positions[1], rotLeftForward); // rightCalf Rotations[3] = CalculateGlobalRotation(Positions[3] - Positions[6], Positions[6] - Positions[7], rotLeftDown); // leftHipBone Rotations[4] = CalculateGlobalRotation(Positions[4] - Positions[3], Positions[5] - Positions[4], rotLeftForward); // leftThigh Rotations[5] = CalculateGlobalRotation(Positions[5] - Positions[4], Positions[3] - Positions[4], rotLeftForward); // leftCalf Rotations[6] = CalculateGlobalRotation(Positions[7] - Positions[6], Positions[3] - Positions[2], rotLeftDown); // waist Rotations[7] = CalculateGlobalRotation(Positions[8] - Positions[7], Positions[6] - Positions[7], rotLeftDown); // chest Rotations[8] = CalculateGlobalRotation(Positions[9] - Positions[8], Positions[13] - Positions[12], rotLeftDown); // neck Rotations[9] = CalculateGlobalRotation(Positions[10] - Positions[9], Positions[8] - Positions[9], rotLeftDown); // head Rotations[10] = CalculateGlobalRotation(Positions[13] - Positions[8], Positions[8] - Positions[7], rotLeftUp); // rightClavicle Rotations[11] = CalculateGlobalRotation(Positions[12] - Positions[13], Positions[11] - Positions[12], rotLeftBack); // rightUpperArm Rotations[12] = CalculateGlobalRotation(Positions[11] - Positions[12], Positions[13] - Positions[12], rotLeftBack); // rightForearm Rotations[13] = CalculateGlobalRotation(Positions[14] - Positions[8], Positions[7] - Positions[8], rotLeftUp); // leftClavicle Rotations[14] = CalculateGlobalRotation(Positions[15] - Positions[14], Positions[16] - Positions[15], rotLeftBack); // leftUpperArm Rotations[15] = CalculateGlobalRotation(Positions[16] - Positions[15], Positions[14] - Positions[15], rotLeftBack); // leftForearm } // calculate the Bone Local Rotations for (int j = 0; j < 16; j++) { LocalRotations.Add(Quaternion.identity); // initialize the LocalRotations } // check whether using local rotation of bones for driving avatar if (UseLocalRotation) { // calculate the bone local rotations using the method of relatively rotating LocalRotations[0] = CalculateLocalRotation(Rotations[6], Rotations[0]); // rightHipBone LocalRotations[1] = CalculateLocalRotation(Rotations[0], Rotations[1]); // rightThigh LocalRotations[2] = CalculateLocalRotation(Rotations[1], Rotations[2]); // rightCalf LocalRotations[3] = CalculateLocalRotation(Rotations[6], Rotations[3]); // leftHipBone LocalRotations[4] = CalculateLocalRotation(Rotations[3], Rotations[4]); // leftThigh LocalRotations[5] = CalculateLocalRotation(Rotations[4], Rotations[5]); // leftCalf // LocalRotations[6] = Rotations[6]; // waist LocalRotations[6] = CalculateLocalRotation(new Quaternion(-0.5f, 0.5f, 0.5f, 0.5f), Rotations[6]); // waist(relative rotation of pelvis to the world coordinate system) LocalRotations[7] = CalculateLocalRotation(Rotations[6], Rotations[7]); // chest LocalRotations[8] = CalculateLocalRotation(Rotations[7], Rotations[8]); // neck LocalRotations[9] = CalculateLocalRotation(Rotations[8], Rotations[9]); // head LocalRotations[10] = CalculateLocalRotation(Rotations[8], Rotations[10]); // rightClavicle LocalRotations[11] = CalculateLocalRotation(Rotations[10], Rotations[11]); // rightUpperArm LocalRotations[12] = CalculateLocalRotation(Rotations[11], Rotations[12]); // rightForearm LocalRotations[13] = CalculateLocalRotation(Rotations[8], Rotations[13]); // leftClavicle LocalRotations[14] = CalculateLocalRotation(Rotations[13], Rotations[14]); // leftUpperArm LocalRotations[15] = CalculateLocalRotation(Rotations[14], Rotations[15]); // leftForearm } }
public void CalculateBoneRotations() { // Global Rotations for (int i = 0; i < 15; i++) { Rotations.Add(Quaternion.identity); } // TODO: make sure that the coordinate system will be the same(fixed to the bones) for every frame based on the human joint keypoints Rotations[0] = CalculateGlobalRotation(Positions[2] - Positions[6], Positions[7] - Positions[6], HumanToAvatarTransformRotations[0]); Rotations[1] = CalculateGlobalRotation(Positions[1] - Positions[2], Positions[0] - Positions[1], HumanToAvatarTransformRotations[1]); Rotations[2] = CalculateGlobalRotation(Positions[0] - Positions[1], Positions[2] - Positions[1], HumanToAvatarTransformRotations[2]); Rotations[3] = CalculateGlobalRotation(Positions[3] - Positions[6], Positions[6] - Positions[7], HumanToAvatarTransformRotations[3]); Rotations[4] = CalculateGlobalRotation(Positions[4] - Positions[3], Positions[5] - Positions[4], HumanToAvatarTransformRotations[4]); Rotations[5] = CalculateGlobalRotation(Positions[5] - Positions[4], Positions[3] - Positions[4], HumanToAvatarTransformRotations[5]); Rotations[6] = CalculateGlobalRotation(Positions[7] - Positions[6], Positions[3] - Positions[2], HumanToAvatarTransformRotations[6]); Rotations[7] = CalculateGlobalRotation(Positions[8] - Positions[7], Positions[6] - Positions[7], HumanToAvatarTransformRotations[7]); Rotations[8] = CalculateGlobalRotation(Positions[9] - Positions[8], Positions[13] - Positions[12], HumanToAvatarTransformRotations[8]); Rotations[9] = CalculateGlobalRotation(Positions[12] - Positions[8], Positions[8] - Positions[7], HumanToAvatarTransformRotations[9]); Rotations[10] = CalculateGlobalRotation(Positions[11] - Positions[12], Positions[10] - Positions[11], HumanToAvatarTransformRotations[10]); Rotations[11] = CalculateGlobalRotation(Positions[10] - Positions[11], Positions[12] - Positions[11], HumanToAvatarTransformRotations[11]); Rotations[12] = CalculateGlobalRotation(Positions[13] - Positions[8], Positions[7] - Positions[8], HumanToAvatarTransformRotations[12]); Rotations[13] = CalculateGlobalRotation(Positions[14] - Positions[13], Positions[15] - Positions[14], HumanToAvatarTransformRotations[13]); Rotations[14] = CalculateGlobalRotation(Positions[15] - Positions[14], Positions[13] - Positions[14], HumanToAvatarTransformRotations[14]); // Local Rotations LocalRotations = Rotations.ToList(); // construct the reference coordinate rotations var invRightHipBine = Quaternion.Inverse(Rotations[0]); var invRightThigh = Quaternion.Inverse(Rotations[1]); var invLeftHipBone = Quaternion.Inverse(Rotations[3]); var invLeftThigh = Quaternion.Inverse(Rotations[4]); var invWaist = Quaternion.Inverse(Rotations[6]); var invCheset = Quaternion.Inverse(Rotations[7]); var invNeck = Quaternion.Inverse(Rotations[8]); var invRightClavicle = Quaternion.Inverse(Rotations[9]); var invRigthUpperArm = Quaternion.Inverse(Rotations[10]); var invLeftClavicle = Quaternion.Inverse(Rotations[12]); var invLeftUpperArm = Quaternion.Inverse(Rotations[13]); // calculate the bone local roataions of human // TODO: make sure the inv on the left or the right LocalRotations[0] = LocalRotations[0] * invWaist; LocalRotations[1] = LocalRotations[1] * invRightHipBine; LocalRotations[2] = LocalRotations[2] * invRightThigh; LocalRotations[3] = LocalRotations[3] * invWaist; LocalRotations[4] = LocalRotations[4] * invLeftHipBone; LocalRotations[5] = LocalRotations[5] * invLeftThigh; // LocalRotations[6] = LocalRotations[6] * invWaist; LocalRotations[7] = LocalRotations[7] * invWaist; LocalRotations[8] = LocalRotations[8] * invCheset; LocalRotations[9] = LocalRotations[9] * invNeck; LocalRotations[10] = LocalRotations[10] * invRightClavicle; LocalRotations[11] = LocalRotations[11] * invRigthUpperArm; LocalRotations[12] = LocalRotations[12] * invNeck; LocalRotations[13] = LocalRotations[13] * invLeftClavicle; LocalRotations[14] = LocalRotations[14] * invLeftUpperArm; // LocalRotations[0] = invWaist * LocalRotations[0]; // LocalRotations[1] = invRightHipBine * LocalRotations[1]; // LocalRotations[2] = invRightThigh * LocalRotations[2]; // LocalRotations[3] = invWaist * LocalRotations[3]; // LocalRotations[4] = invLeftHipBone * LocalRotations[4]; // LocalRotations[5] = invLeftThigh * LocalRotations[5]; // // LocalRotations[6] = invWaist * LocalRotations[6]; // LocalRotations[7] = invWaist * LocalRotations[7]; // LocalRotations[8] = invCheset * LocalRotations[8]; // LocalRotations[9] = invNeck * LocalRotations[9]; // LocalRotations[10] = invRightClavicle * LocalRotations[10]; // LocalRotations[11] = invRigthUpperArm * LocalRotations[11]; // LocalRotations[12] = invNeck * LocalRotations[12]; // LocalRotations[13] = invLeftClavicle * LocalRotations[13]; // LocalRotations[14] = invLeftUpperArm * LocalRotations[14]; }