protected override void CameraDraw() { shiftingOriginMap = mapObject.GetComponent <VtsMapShiftingOrigin>(); conv = Math.Mul44x44(Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)), Math.Inverse44(draws.camera.view)); UpdateOpaqueDraws(); UpdateTransparentDraws(); }
private void UpdateParts() { double[] conv = Math.Mul44x44(Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)), Math.Inverse44(draws.camera.view)); Dictionary<VtsMesh, DrawTask> tasksByMesh = new Dictionary<VtsMesh, DrawTask>(); foreach (DrawTask t in draws.colliders) { VtsMesh k = t.mesh as VtsMesh; if (!tasksByMesh.ContainsKey(k)) tasksByMesh.Add(k, t); } HashSet<VtsMesh> partsToRemove = new HashSet<VtsMesh>(partsCache.Keys); foreach (KeyValuePair<VtsMesh, DrawTask> tbm in tasksByMesh) { if (!partsCache.ContainsKey(tbm.Key)) { GameObject o = Instantiate(colliderPrefab); partsCache.Add(tbm.Key, o); UnityEngine.Mesh msh = (tbm.Value.mesh as VtsMesh).Get(); o.GetComponent<MeshCollider>().sharedMesh = msh; VtsUtil.Matrix2Transform(o.transform, VtsUtil.V2U44(Math.Mul44x44(conv, System.Array.ConvertAll(tbm.Value.data.mv, System.Convert.ToDouble)))); } partsToRemove.Remove(tbm.Key); } foreach (VtsMesh m in partsToRemove) { Destroy(partsCache[m]); partsCache.Remove(m); } }
private void Update() { // draw current frame draws.Load(vmap, vcam); CameraDraw(); UpdateBackground(); // prepare for next frame vcam.SetViewportSize((uint)ucam.pixelWidth, (uint)ucam.pixelHeight); double[] Mu = Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)); if (controlTransformation == VtsDataControl.Vts) { double[] view = vcam.GetView(); VtsUtil.Matrix2Transform(camTrans, VtsUtil.V2U44(Math.Mul44x44(Math.Inverse44(Math.Mul44x44(view, Mu)), VtsUtil.U2V44(VtsUtil.InvertZ)))); } else { double[] view = Math.Mul44x44(VtsUtil.U2V44(ucam.worldToCameraMatrix), Mu); vcam.SetView(view); } if (controlNearFar == VtsDataControl.Vts) { double n, f; vcam.SuggestedNearFar(out n, out f); ucam.nearClipPlane = (float)n; ucam.farClipPlane = (float)f; } vcam.SetProj(ucam.fieldOfView, ucam.nearClipPlane, ucam.farClipPlane); // statistics Statistics = vcam.GetStatistics(); }
protected override void CameraDraw() { shiftingOriginMap = mapObject.GetComponent <VtsMapShiftingOrigin>(); conv = Math.Mul44x44(Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)), Math.Inverse44(draws.camera.view)); UpdateSurfacesCache(opaquePrefab, draws.opaque, opaquePartsCache); UpdateSurfacesCache(transparentPrefab, draws.transparent, transparentPartsCache); originHasShifted = false; }
private void CamOverrideView(ref double[] values) { double[] Mu = Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)); // view matrix switch (controlTransformation) { case VtsDataControl.Vts: VtsUtil.Matrix2Transform(camTrans, VtsUtil.V2U44(Math.Mul44x44(Math.Inverse44(Math.Mul44x44(values, Mu)), VtsUtil.U2V44(VtsUtil.InvertZ)))); break; case VtsDataControl.Unity: values = Math.Mul44x44(VtsUtil.U2V44(cam.worldToCameraMatrix), Mu); break; } }
private void CollOverrideCenter(ref double[] values) { values = VtsUtil.U2V3(probTrans.position); { // convert from unity world to (local) vts physical double[] point4 = new double[4] { values[0], values[1], values[2], 1 }; point4 = Math.Mul44x4(VtsUtil.U2V44(mapTrans.worldToLocalMatrix), point4); values[0] = point4[0]; values[1] = point4[1]; values[2] = point4[2]; } { // swap YZ double tmp = values[1]; values[1] = values[2]; values[2] = tmp; } }
public double[] VtsNavigationToUnity(double[] point) { Util.CheckArray(point, 3); point = map.Convert(point, Srs.Navigation, Srs.Physical); { // swap YZ double tmp = point[1]; point[1] = point[2]; point[2] = tmp; } { // convert from (local) vts physical to unity world double[] point4 = new double[4] { point[0], point[1], point[2], 1 }; point4 = Math.Mul44x4(VtsUtil.U2V44(transform.localToWorldMatrix), point4); point[0] = point4[0]; point[1] = point4[1]; point[2] = point4[2]; } return(point); }
public double[] UnityToVtsNavigation(double[] point) { Util.CheckArray(point, 3); { // convert from unity world to (local) vts physical double[] point4 = new double[4] { point[0], point[1], point[2], 1 }; point4 = Math.Mul44x4(VtsUtil.U2V44(transform.worldToLocalMatrix), point4); point[0] = point4[0]; point[1] = point4[1]; point[2] = point4[2]; } { // swap YZ double tmp = point[1]; point[1] = point[2]; point[2] = tmp; } point = map.Convert(point, Srs.Physical, Srs.Navigation); return(point); }
private void FixedUpdate() { // update current colliders draws.Load(vmap, vcam); UpdateParts(); // prepare for next frame vcam.SetViewportSize(1, 1); double[] Mu = Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)); double[] view = Math.Mul44x44(VtsUtil.U2V44(probTrans.localToWorldMatrix.inverse), Mu); vcam.SetView(view); // enforce fixed traversal mode { StringBuilder builder = new StringBuilder(); builder.Append("{ \"fixedTraversalDistance\":").Append(collidersDistance).Append(", \"fixedTraversalLod\":").Append(collidersLod).Append(", \"traverseModeSurfaces\":4, \"traverseModeGeodata\":0 }"); vcam.SetOptions(builder.ToString()); } // statistics Statistics = vcam.GetStatistics(); }
protected override void CameraUpdate() { double[] conv = Math.Mul44x44(Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)), Math.Inverse44(draws.camera.view)); Dictionary <VtsMesh, List <DrawTask> > tasksByMesh = new Dictionary <VtsMesh, List <DrawTask> >(); foreach (DrawTask t in draws.opaque) { VtsMesh k = t.mesh as VtsMesh; if (!tasksByMesh.ContainsKey(k)) { tasksByMesh.Add(k, new List <DrawTask>()); } tasksByMesh[k].Add(t); } HashSet <VtsMesh> partsToRemove = new HashSet <VtsMesh>(partsCache.Keys); foreach (KeyValuePair <VtsMesh, List <DrawTask> > tbm in tasksByMesh) { if (!partsCache.ContainsKey(tbm.Key)) { partsCache.Add(tbm.Key, new List <GameObject>(tbm.Value.Count)); } UpdateParts(tbm.Value, partsCache[tbm.Key], conv); partsToRemove.Remove(tbm.Key); } foreach (VtsMesh m in partsToRemove) { foreach (GameObject o in partsCache[m]) { Destroy(o); } partsCache.Remove(m); } }
protected override void CameraDraw() { conv = Math.Mul44x44(Math.Mul44x44(VtsUtil.U2V44(mapTrans.localToWorldMatrix), VtsUtil.U2V44(VtsUtil.SwapYZ)), Math.Inverse44(draws.camera.view)); UpdateOpaqueDraws(); UpdateTransparentDraws(); }