UnityMol  0.9.6-875
UnityMol viewer / In developement
MouseOverMoleculeIMDSimulation.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using System.Collections;
3 
4 public class MouseOverMoleculeIMDSimulation : MonoBehaviour {
5  public static bool stopCamera = false;
6  private GameObject arrowParent;
7  private int atomId;
8 
9  public void setAtomId(int atomId) { this.atomId = atomId; }
10 
11  private Camera mainCamera = null;
12  // Use this for initialization
13 
14 
15  // Does something as a response
16  // to the user clicking on the object
17  void OnMouseDrag () {
18  if(mainCamera == null)
19  mainCamera = Camera.main;
20  if (arrowParent == null)
21  {
22  arrowParent = new GameObject("Arrow");
23 
24  GameObject arrow;
25  arrow = GameObject.CreatePrimitive(PrimitiveType.Cube);
26  arrow.transform.parent = arrowParent.transform;
27  arrow.transform.localScale = new Vector3(0.4f, 3.5f, 0.4f);
28  arrow.transform.Translate(arrow.transform.up * 2.0f);
29  arrow.GetComponent<Renderer>().enabled = true;
30 
31  arrowParent.transform.position = transform.position;
32  arrowParent.transform.parent = transform;
33  }
34 
36  BallUpdate script = gameObject.GetComponent<BallUpdate>();
37 
38  if(Input.GetMouseButton(0)){
39  maxCamera.cameraStop = true;
40  stopCamera = true;
41 
42  Vector3 p = Input.mousePosition;
43  p.z = mainCamera.WorldToScreenPoint(transform.position).z;
44 
45  Vector3 worldCoords = mainCamera.ScreenToWorldPoint(p);
46  Vector3 force = worldCoords - transform.position;
47  manager.send_forces(1, new int[] {this.atomId}, new float[] {force.x, force.y, force.z});
48 
49  float distance = Vector3.Distance(worldCoords, transform.position);
50  float arrowZScale = distance / 8.0f;
51  float arrowScale = distance / 12.0f;
52  arrowParent.transform.up = force;
53  arrowParent.transform.localScale = new Vector3(arrowScale, arrowZScale, arrowScale);
54  }
55  }
56 
57  void OnMouseUp() {
58  BallUpdate script = gameObject.GetComponent<BallUpdate>();
59 
61  manager.send_forces(1, new int[] {this.atomId}, new float[] {0.0f, 0.0f, 0.0f});
62 
63  maxCamera.cameraStop = false;
64  stopCamera = false;
65 
66  if (arrowParent != null)
67  {
68  GameObject.DestroyImmediate(arrowParent);
69  arrowParent = null;
70  }
71  }
72 }
static ArtemisManager getArtemisManager()
Definition: UnityMolMain.cs:29
static bool cameraStop
Definition: maxCamera.cs:88
void send_forces(int nb_forces, int[] indices, float[] coordinates)