public uint Add(Vector3 p, Vector3 r, Vector3 s) { Matrix4x4 mat4x4 = new Matrix4x4(); Matrix4x4Helper.SetTRS(ref mat4x4, p, r, s); foreach (var kv in m_MatPropertyBlock_Float) { kv.Value.Add(0f); } foreach (var kv in m_MatPropertyBlock_Vec4) { kv.Value.Add(Vector4.one); } return(m_Matrix4x4s.Add(mat4x4)); }
/// <summary> /// Creates the virtual marker. /// </summary> /// <param name="segment">Segment.</param> /// <param name="availableMarkers">Available markers.</param> /// <param name="unavailableMarker">Unavailable marker.</param> private void createVirtualMarker(Joint segment, List <string> availableMarkers, string unavailableMarker) { if (DEBUG.enabled) { UnityEngine.Debug.Log("Create virtual marker " + unavailableMarker + " for segment " + segment); } //UnityEngine.Debug.Log("availableMarkers[0] " + availableMarkers[0] + " availableMarkers[1] " + availableMarkers[1]); //UnityEngine.Debug.Log("unavailableMarker " + unavailableMarker); var trackingMarkers = this.segments[segment]; Vector3 tcs, vAxis, xAxis, yAxis, zAxis, locPos, vPos; // Create world to local matrix tcs = (availableMarkers.Count > 2) ? trackingMarkers[availableMarkers[2]] : trackingMarkers[ORIGIN]; xAxis = (tcs - trackingMarkers[availableMarkers[0]]).Normalized(); vAxis = (trackingMarkers[availableMarkers[0]] - trackingMarkers[availableMarkers[1]]).Normalized(); yAxis = Vector3.Cross(xAxis, vAxis); zAxis = Vector3.Cross(yAxis, xAxis); var worldToLocal = Matrix4x4Helper.GetMatrix(tcs.Convert(), zAxis.Convert(), yAxis.Convert(), xAxis.Convert()).inverse; locPos = worldToLocal.MultiplyPoint3x4(trackingMarkers[unavailableMarker].Convert()).Convert(); //UnityEngine.Debug.Log("locPos " + locPos); // Create local to world matrix tcs = (availableMarkers.Count > 2) ? this.markers[availableMarkers[2]] : this.skeleton.Find(segment).Pos; xAxis = (tcs - this.markers[availableMarkers[0]]).Normalized(); vAxis = (this.markers[availableMarkers[0]] - this.markers[availableMarkers[1]]).Normalized(); yAxis = Vector3.Cross(xAxis, vAxis); zAxis = Vector3.Cross(yAxis, xAxis); var localToWorld = Matrix4x4Helper.GetMatrix(tcs.Convert(), zAxis.Convert(), yAxis.Convert(), xAxis.Convert()); vPos = localToWorld.MultiplyPoint3x4(locPos.Convert()).Convert(); // Set new marker position this.markers[unavailableMarker] = vPos; }
private void ConfigureCamera() { this.nearClipPlane = Mathf.Max(this.nearClipPlane, MinimumNearClipPlane); this.viewportPosition.z = Mathf.Max(this.viewportPosition.z, MinimumNearClipPlane); this.aspectWidth = Mathf.Max(this.aspectWidth, MinimumAspectSize); this.aspectHeight = Mathf.Max(this.aspectHeight, MinimumAspectSize); this.cameraComponent.orthographic = false; this.cameraComponent.ResetAspect(); this.cameraComponent.ResetProjectionMatrix(); this.cameraComponent.ResetWorldToCameraMatrix(); var z = Mathf.Max(this.viewportPosition.z, this.nearClipPlane); if (this.useFixedAspectRatio) { this.cameraComponent.aspect = this.aspectWidth / this.aspectHeight; if (this.useAspectAsViewportSize) { var leftCorner = -0.5f * this.aspectWidth; var rightCorner = 0.5f * this.aspectWidth; var upperCorner = 0.5f * this.aspectHeight; var lowerCorner = -0.5f * this.aspectHeight; this.localFrustumCorners[LowerLeftCornerIndex].x = leftCorner; this.localFrustumCorners[LowerLeftCornerIndex].y = lowerCorner; this.localFrustumCorners[LowerLeftCornerIndex].z = z; this.localFrustumCorners[LowerRightCornerIndex].x = rightCorner; this.localFrustumCorners[LowerRightCornerIndex].y = lowerCorner; this.localFrustumCorners[LowerRightCornerIndex].z = z; this.localFrustumCorners[UpperLeftCornerIndex].x = leftCorner; this.localFrustumCorners[UpperLeftCornerIndex].y = upperCorner; this.localFrustumCorners[UpperLeftCornerIndex].z = z; this.localFrustumCorners[UpperRightCornerIndex].x = rightCorner; this.localFrustumCorners[UpperRightCornerIndex].y = upperCorner; this.localFrustumCorners[UpperRightCornerIndex].z = z; } else { this.cameraComponent.CalculateFrustumCorners( new Rect(0, 0, 1, 1), z, Camera.MonoOrStereoscopicEye.Mono, this.localFrustumCorners); } } else { this.cameraComponent.CalculateFrustumCorners( new Rect(0, 0, 1, 1), z, Camera.MonoOrStereoscopicEye.Mono, this.localFrustumCorners); } this.viewportSize.x = Vector3.Distance(this.localFrustumCorners[LowerLeftCornerIndex], this.localFrustumCorners[LowerRightCornerIndex]); this.viewportSize.y = Vector3.Distance(this.localFrustumCorners[LowerLeftCornerIndex], this.localFrustumCorners[UpperLeftCornerIndex]); var viewportQuaternion = Quaternion.Euler(this.viewportRotation); for (var i = 0; i < this.localFrustumCorners.Length; i++) { this.localFrustumCorners[i].x += this.viewportPosition.x; this.localFrustumCorners[i].y += this.viewportPosition.y; this.localFrustumCorners[i] = viewportQuaternion * this.localFrustumCorners[i]; } var lowerLeftCorner = this.LowerLeftCorner; var lowerRightCorner = this.LowerRightCorner; var upperLeftCorner = this.UpperLeftCorner; var worldEyePosition = this.WorldPointOfView; var screenRightAxis = lowerRightCorner - lowerLeftCorner; var screenUpAxis = upperLeftCorner - lowerLeftCorner; var lowerLeftDirection = lowerLeftCorner - worldEyePosition; var lowerRightDirection = lowerRightCorner - worldEyePosition; var upperLeftDirection = upperLeftCorner - worldEyePosition; if (Vector3.Dot(-Vector3.Cross(lowerLeftDirection, upperLeftDirection), lowerRightDirection) < 0.0) { screenRightAxis = -screenRightAxis; lowerLeftCorner = lowerRightCorner; lowerRightCorner = lowerLeftCorner + screenRightAxis; upperLeftCorner = lowerLeftCorner + screenUpAxis; lowerLeftDirection = lowerLeftCorner - worldEyePosition; lowerRightDirection = lowerRightCorner - worldEyePosition; upperLeftDirection = upperLeftCorner - worldEyePosition; } screenRightAxis.Normalize(); screenUpAxis.Normalize(); var normal = -Vector3.Cross(screenRightAxis, screenUpAxis).normalized; var distanceFromEyeToScreen = Mathf.Max(MinimumNearClipPlane, -Vector3.Dot(lowerLeftDirection, normal)); this.cameraComponent.nearClipPlane = this.setNearClipPlane ? distanceFromEyeToScreen : this.nearClipPlane; var left = Vector3.Dot(screenRightAxis, lowerLeftDirection) * this.cameraComponent.nearClipPlane / distanceFromEyeToScreen; var right = Vector3.Dot(screenRightAxis, lowerRightDirection) * this.cameraComponent.nearClipPlane / distanceFromEyeToScreen; var bottom = Vector3.Dot(screenUpAxis, lowerLeftDirection) * this.cameraComponent.nearClipPlane / distanceFromEyeToScreen; var top = Vector3.Dot(screenUpAxis, upperLeftDirection) * this.cameraComponent.nearClipPlane / distanceFromEyeToScreen; this.cameraComponent.projectionMatrix = Matrix4x4Helper.Perspective(left, right, bottom, top, this.cameraComponent.nearClipPlane, this.cameraComponent.farClipPlane); this.cameraComponent.worldToCameraMatrix = Matrix4x4Helper.Rotation(screenRightAxis, screenUpAxis, normal) * Matrix4x4Helper.Translation(worldEyePosition); if (this.useFixedAspectRatio && this.useAspectAsViewportSize) { this.cameraComponent.fieldOfView = Mathf.Atan(1f / this.cameraComponent.projectionMatrix[1, 1]) * 2f * Mathf.Rad2Deg; } }
public void SetScaleAndResetRot(uint id, Vector3 scale) { Matrix4x4Helper.SetMatrixScaleAndResetRot(ref m_Array[m_IdtoIndex[id]], scale); }
public void SetRotAndResetScale(uint id, Vector3 rot) { Matrix4x4Helper.SetMatrixRotationAndResetScale(ref m_Array[m_IdtoIndex[id]], rot); }
public void SetRotAndScale(uint id, Vector3 rot, Vector3 scale) { Matrix4x4Helper.SetRS(ref m_Array[m_IdtoIndex[id]], rot, scale); }
public void SetPos(uint id, Vector3 pos) { Matrix4x4Helper.SetMatrixPosition(ref m_Array[m_IdtoIndex[id]], pos); }