public void ConvertTo() { VectorConverter r = new VectorConverter(); Vector rect = new Vector(1, 2); object o = r.ConvertTo(rect, typeof(string)); Assert.AreEqual(typeof(string), o.GetType()); Assert.AreEqual("1,2", (string)o); }
// <SnippetVectorConverterExample_csharp> private Vector vectorConverterExample() { VectorConverter vConverter = new VectorConverter(); Vector vectorResult = new Vector(); string string1 = "10,20"; vectorResult = (Vector)vConverter.ConvertFromString(string1); // vectorResult is equal to (10, 20) return(vectorResult); }
public NetWorkingTransform(SyncObjectModel syncObjectModel) { VectorConverter g = new VectorConverter(true, true, true); this.syncObjectModel = syncObjectModel; CreatorAuthority = syncObjectModel.UserName; ModelAuthority = syncObjectModel.ModelId; PrefabName = syncObjectModel.PrefabName; this.newPosition = JsonConvert.DeserializeObject <Vector3>(syncObjectModel.ModelPosition, g); this.newRotation = JsonConvert.DeserializeObject <Vector3>(syncObjectModel.ModelRotation, g); }
public void ConvertFrom() { VectorConverter r = new VectorConverter(); object or = r.ConvertFrom("3, 4"); Assert.AreEqual(typeof(Vector), or.GetType()); Assert.AreEqual(new Vector(3, 4), or); or = r.ConvertFrom("-1, -4"); Assert.AreEqual(typeof(Vector), or.GetType()); Assert.AreEqual(new Vector(-1, -4), or); }
public override void Awake() { if (rigidbody == null) { CheckDropAxis(); connectedBody = Physics.AddBody(); connectedBody.Position = VectorConverter.Convert(transform.position, to2dMode); connectedBody.Rotation = MathHelper.ToRadians(VectorConverter.Angle(transform.rotation.eulerAngles, to2dMode)); connectedBody.UserData = this; connectedBody.BodyType = BodyType.Static; AddCollider(connectedBody, 1); } }
protected override void DoAddCollider(Body body, float mass) { Microsoft.Xna.Framework.Vector2 scale = VectorConverter.Convert(transform.lossyScale, to2dMode); for (int i = 0; i < vertices.Count; i++) { Vertices v = vertices[i]; for (int j = 0; j < v.Count; j++) { v[j] = v[j] * scale; } } connectedBody = body; Physics.AddMesh(body, isTrigger, vertices, mass); }
static void Main(string[] args) { var vc = new VectorConverter(); vc.GhostscriptDir = @"C:\Program Files (x86)\gs\gs9.14\"; vc.ConvertEpsToPdf(@"..\..\..\Example\graphics.eps", @"..\..\..\Example\graphics.pdf"); vc.Pdf2SvgDir = @"C:\pdf2svg-0.2.2\"; vc.ConvertPdfToSvg(@"..\..\..\Example\graphics.pdf", @"..\..\..\Example\graphics-from-pdf.svg"); vc.ConvertEpsToSvg(@"..\..\..\Example\graphics.eps", @"..\..\..\Example\graphics-from-eps.svg"); vc.InkscapeDir = @"C:\Program Files (x86)\Inkscape\"; vc.ConvertSvgToPdf(@"..\..\..\Example\graphics-from-eps.svg", @"..\..\..\Example\graphics-from-svg.pdf"); vc.ConvertSvgToEps(@"..\..\..\Example\graphics-from-eps.svg", @"..\..\..\Example\graphics-from-svg.eps"); }
static void Main(string[] args) { var vc = new VectorConverter(); vc.GhostscriptDir = @"C:\Program Files (x86)\gs\gs9.14\"; vc.ConvertEpsToPdf(@"..\..\..\Example\graphics.eps", @"..\..\..\Example\graphics.pdf"); vc.Pdf2SvgDir = @"C:\pdf2svg-0.2.2\"; vc.ConvertPdfToSvg(@"..\..\..\Example\graphics.pdf", @"..\..\..\Example\graphics-from-pdf.svg"); vc.ConvertEpsToSvg(@"..\..\..\Example\graphics.eps", @"..\..\..\Example\graphics-from-eps.svg"); vc.InkscapeDir = @"C:\Program Files (x86)\Inkscape\"; vc.ConvertSvgToPdf(@"..\..\..\Example\graphics-from-eps.svg", @"..\..\..\Example\graphics-from-svg.pdf"); vc.ConvertSvgToEps(@"..\..\..\Example\graphics-from-eps.svg", @"..\..\..\Example\graphics-from-svg.eps"); }
/// <summary> /// Rotates the model /// </summary> /// <param name="rotation">The amount to rotate</param> /// <returns>Indicates whether the rotation was successful</returns> public bool Rotate(Vector3D rotation) { // Calculate absolute rotation Vector3D newRotation = _rotation + rotation; Engine.MD2System.Class_SetPointer(this.Name); try { R3DVector3D vector = VectorConverter.GetR3DVector3DFromVector3D(newRotation); Engine.MD2System.Model_SetRotation(ref vector); } catch (Exception e) { throw new ModelException("Could not set rotation '" + newRotation.X + "' '" + newRotation.Y + "' '" + newRotation.Z + "' for model '" + this.Name + "'", e); } _rotation = newRotation; // TODO: Implement success return(true); }
public void Test_CovertString() { var seed = "ate"; var input = "aate"; var converter = new VectorConverter(seed); var actual = converter.CovertString(input); var expectedBytes = new byte[Vector <byte> .Count]; expectedBytes[0] = 2; expectedBytes[1] = 1; expectedBytes[2] = 1; var expected = new Vector <byte>(expectedBytes); Assert.IsTrue(expected == actual); }
public void Test_GetStringValue() { var seed = "ate"; var inputBytes = new byte[Vector <byte> .Count]; inputBytes[0] = 2; inputBytes[1] = 1; inputBytes[2] = 1; var input = new Vector <byte>(inputBytes); var converter = new VectorConverter(seed); var actual = converter.GetStringValue(input); var expected = "aaet"; Assert.AreEqual(expected, actual); }
/// <summary> /// Создание чужой модели /// </summary> /// <param name="inModel"></param> public void CreateModelOther(SyncObjectModel inModel) { if (UserManager.CurrentUser.connectionId == inModel.UserModel.connectionId) { ObjectsStateManager.Instance.myModelsDictionartLocal.TryGetValue(inModel.ModelId, out var transform); if (transform != null) { ObjectsStateManager.Instance.myModelsDictionary.Enqueue(transform); } else { Debug.Log("Object you want to instantiate does not exist in current scene"); } return; } /* * Проверяем, есть ли данная модель на сцене * Если есть, не создаем повторную и выходим из тела метода */ if (ObjectsStateManager.Instance.modelsLoadedFromServerDictionary.ContainsKey(inModel.ModelId)) { return; } VectorConverter g = new VectorConverter(true, true, true); var position = JsonConvert.DeserializeObject <Vector3>(inModel.ModelPosition, g); g = new VectorConverter(true, true, true); var rotation = JsonConvert.DeserializeObject <Vector3>(inModel.ModelRotation, g); /* * Модель может создаваться только в основном потоке, * Поэтому диспатчим ее и засовываем в основной поток. */ UnityMainThreadDispatcher.Instance().Enqueue(delegate { var otherModelPrefab = Instantiate(Resources.Load(inModel.PrefabName), position, new Quaternion(rotation.x, rotation.y, rotation.z, 1)) as GameObject; var netWorkingTransform = otherModelPrefab.GetComponent <NetWorkingTransform>(); netWorkingTransform.SyncObjectModel = inModel; ObjectsStateManager.Instance.modelsLoadedFromServerDictionary.TryAdd(inModel.ModelId, netWorkingTransform); }); }
/// <summary> /// Moves the camera /// </summary> /// <param name="movement">The amount to move the camera</param> /// <returns>Indicates whether the Move was successful</returns> public bool Move(Vector3D movement) { Vector3D newPosition = _position + movement; try { initialisePointer(); R3DVector3D r = VectorConverter.GetR3DVector3DFromVector3D(newPosition); Engine.Cameras.Camera_SetPosition(ref r); } catch (Exception e) { throw new RenderingException("Could not set position '" + newPosition.X + "' '" + newPosition.Y + "' '" + newPosition.Z + "' for camera.", e); } _position = newPosition; // TODO: Implement success correctly - may not be needed for a camera return(true); }
/// <summary> /// Rotates the camera /// </summary> /// <param name="rotation">The amount to rotate the camera</param> /// <returns>Indicates whether the rotation was successful</returns> public bool Rotate(Vector3D rotation) { Vector3D newRotation = _rotation + rotation; try { initialisePointer(); R3DVector3D r = VectorConverter.GetR3DVector3DFromVector3D(newRotation); Engine.Cameras.Camera_SetRotation(ref r); } catch (Exception e) { throw new RenderingException("Could not set rotation '" + newRotation.X + "' '" + newRotation.Y + "' '" + newRotation.Z + "' for camera.", e); } _rotation = newRotation; // TODO: Implement success if needed return(true); }
/// <summary> /// Moves the model /// </summary> /// <param name="movement">The amount to move (relative)</param> /// <returns>Indicates whether the move was successful</returns> public bool Move(Vector3D movement) { // Calculate new absolute vector: Vector3D newPosition = _position + movement; Engine.MeshBuilder.Class_SetPointer(this.Name); try { R3DVector3D vector = VectorConverter.GetR3DVector3DFromVector3D(newPosition); Engine.MeshBuilder.Mesh_SetPosition(ref vector); } catch (Exception e) { throw new ModelException("Could not set position '" + newPosition.X + "' '" + newPosition.Y + "' '" + newPosition.Z + "' for model '" + this.Name + "'", e); } _position = newPosition; // TODO: Implement success return(true); }
public void AddForce(Vector3 elasticityForce, ForceMode mode) { Vector2 ef = VectorConverter.Convert(elasticityForce, body.UserData.to2dMode); switch (mode) { case ForceMode.Force: body.ApplyForce(ef, VectorConverter.Convert(gameObject.transform.position, body.UserData.to2dMode)); break; case ForceMode.Acceleration: throw new NotImplementedException(); case ForceMode.Impulse: body.ApplyLinearImpulse(ef, VectorConverter.Convert(gameObject.transform.position, body.UserData.to2dMode)); break; case ForceMode.VelocityChange: throw new NotImplementedException(); } }
protected override void DoAddCollider(Body body, float mass) { connectedBody = body; Vector2 cen = VectorConverter.Convert(center * transform.lossyScale, to2dMode); if (direction == 0 || height <= radius * 2) { float rad = radius * transform.lossyScale.z; Physics.AddCircle(body, isTrigger, rad, cen, mass); } else { if (direction == 1) { Vector2 sz = new Vector2(height - radius * 2, radius * 2); sz *= (Vector2)gameObject.transform.lossyScale; Physics.AddBox(body, isTrigger, sz.x, sz.y, cen, mass); sz /= 2; float rad = sz.y; sz.y = 0; Physics.AddCircle(body, isTrigger, rad, cen + sz, mass); Physics.AddCircle(body, isTrigger, rad, cen - sz, mass); } else { Vector2 sz = new Vector2(radius * 2, height - radius * 2); sz *= (Vector2)gameObject.transform.lossyScale; Physics.AddBox(body, isTrigger, sz.x, sz.y, cen, mass); sz /= 2; float rad = sz.x; sz.x = 0; Physics.AddCircle(body, isTrigger, rad, cen + sz, mass); Physics.AddCircle(body, isTrigger, rad, cen - sz, mass); } } }
public void CreateModel(Vector3 position, Vector3 rotation, string prefabName) { var g = new VectorConverter(false, true, false); var myModelPrefab = Instantiate(Resources.Load(prefabName), position, new Quaternion(rotation.x, rotation.y, rotation.z, 1)) as GameObject; if (UserManager.CurrentUser.RoomModelId == null || myModelPrefab == null) { return; } var netWorkingTransform = myModelPrefab.GetComponent <NetWorkingTransform>(); var syncObjModel = netWorkingTransform.GetModelInfo(); syncObjModel.PrefabName = prefabName; syncObjModel.ModelPosition = JsonConvert.SerializeObject(position, g); syncObjModel.ModelRotation = JsonConvert.SerializeObject(rotation, g); syncObjModel.ModelId = Guid.NewGuid().ToString(); netWorkingTransform.SyncObjectModel = syncObjModel; Debug.Log($"Model id {syncObjModel.ModelId}"); SinalRClientHelper._gameHubProxy.Invoke("CreateModel", syncObjModel); /* * Добавляем созданную модель в локальное хранилище обьектов */ ObjectsStateManager.Instance.myModelsDictionartLocal.TryAdd(syncObjModel.ModelId, netWorkingTransform); if (netWorkingTransform is IMovingNetworkObject movingNetwork) { movingNetwork.Initialize(); } }
// This method performs the Point operations public void PerformOperation(object sender, RoutedEventArgs e) { RadioButton li = (sender as RadioButton); // Strings used to display the results String syntaxString, resultType, operationString; // The local variables point1, point2, vector2, etc are defined in each // case block for readability reasons. Each variable is contained within // the scope of each case statement. switch (li.Name) { //begin switch case "rb1": { // Converts a String to a Point using a PointConverter // Returns a Point. PointConverter pConverter = new PointConverter(); Point pointResult = new Point(); string string1 = "10,20"; pointResult = (Point)pConverter.ConvertFromString(string1); // pointResult is equal to (10, 20) // Displaying Results syntaxString = "pointResult = (Point)pConverter1.ConvertFromString(string1);"; resultType = "Point"; operationString = "Converting a String to a Point"; ShowResults(pointResult.ToString(), syntaxString, resultType, operationString); break; } case "rb2": { // Converts a String to a Vector using a VectorConverter // Returns a Vector. VectorConverter vConverter = new VectorConverter(); Vector vectorResult = new Vector(); string string1 = "10,20"; vectorResult = (Vector)vConverter.ConvertFromString(string1); // vectorResult is equal to (10, 20) // Displaying Results syntaxString = "vectorResult = (Vector)vConverter.ConvertFromString(string1);"; resultType = "Vector"; operationString = "Converting a String into a Vector"; ShowResults(vectorResult.ToString(), syntaxString, resultType, operationString); break; } case "rb3": { // Converts a String to a Matrix using a MatrixConverter // Returns a Matrix. MatrixConverter mConverter = new MatrixConverter(); Matrix matrixResult = new Matrix(); string string2 = "10,20,30,40,50,60"; matrixResult = (Matrix)mConverter.ConvertFromString(string2); // matrixResult is equal to (10, 20, 30, 40, 50, 60) // Displaying Results syntaxString = "matrixResult = (Vector)mConverter.ConvertFromString(string2);"; resultType = "Matrix"; operationString = "Converting a String into a Matrix"; ShowResults(matrixResult.ToString(), syntaxString, resultType, operationString); break; } case "rb4": { // Converts a String to a Point3D using a Point3DConverter // Returns a Point3D. Point3DConverter p3DConverter = new Point3DConverter(); Point3D point3DResult = new Point3D(); string string3 = "10,20,30"; point3DResult = (Point3D)p3DConverter.ConvertFromString(string3); // point3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "point3DResult = (Point3D)p3DConverter.ConvertFromString(string3);"; resultType = "Point3D"; operationString = "Converting a String into a Point3D"; ShowResults(point3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb5": { // Converts a String to a Vector3D using a Vector3DConverter // Returns a Vector3D. Vector3DConverter v3DConverter = new Vector3DConverter(); Vector3D vector3DResult = new Vector3D(); string string3 = "10,20,30"; vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3); // vector3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "vector3DResult = (Vector3D)v3DConverter.ConvertFromString(string3);"; resultType = "Vector3D"; operationString = "Converting a String into a Vector3D"; ShowResults(vector3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb6": { // Converts a String to a Size3D using a Size3DConverter // Returns a Size3D. Size3DConverter s3DConverter = new Size3DConverter(); Size3D size3DResult = new Size3D(); string string3 = "10,20,30"; size3DResult = (Size3D)s3DConverter.ConvertFromString(string3); // size3DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "size3DResult = (Size3D)v3DConverter.ConvertFromString(string3);"; resultType = "Size3D"; operationString = "Converting a String into a Size3D"; ShowResults(size3DResult.ToString(), syntaxString, resultType, operationString); break; } case "rb7": { // Converts a String to a Point4D using a Point4DConverter // Returns a Point4D. Point4DConverter p4DConverter = new Point4DConverter(); Point4D point4DResult = new Point4D(); string string4 = "10,20,30,40"; point4DResult = (Point4D)p4DConverter.ConvertFromString(string4); // point4DResult is equal to (10, 20, 30) // Displaying Results syntaxString = "point4DResult = (Point4D)v3DConverter.ConvertFromString(string3);"; resultType = "Point4D"; operationString = "Converting a String into a Point4D"; ShowResults(point4DResult.ToString(), syntaxString, resultType, operationString); break; } default: break; } //end switch }
public void ConvertFrom_size() { VectorConverter r = new VectorConverter(); r.ConvertFrom(new Vector(10, 20)); }
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { return(VectorConverter.ConvertFrom(reader.Value)); }
public Vector3 GetPointVelocity(Vector3 worldPoint) { return(body.GetLinearVelocityFromWorldPoint(VectorConverter.Convert(worldPoint, collider.to2dMode))); }