12-05-2015 01:24 AM
I am trying to build a star simulation VI, which will create a main star at the position of the curson, and with a mouse down event, it will create another star at the position of mouse clicking on the graph. However, the curson is only movable if I hit run and drag the cursor immediately; otherwise when I try to drag it my mouse cursor will freeze as a cross shape.
I think the data flow is fine and I even put on a wait VI. Any suggestions?
Solved! Go to Solution.
12-05-2015 02:04 AM
You have an event strucure that is outside the loop and thus can run only once. When the event (mouse down) occurs the second time, the front panel locks (the event is configured to lock the front panel until the event completes, but the event cannot complete because it is not reachable via dataflow)
Get rid of the event structure.
12-05-2015 02:28 AM - edited 12-05-2015 02:42 AM
Here's a quick draft that should give you some ideas. You probably want to improve the user intereaction though. (e.g. grabbing the cursor is also a mouse down event of course)
(note that using complex arrays significantly simplifies the code)
12-05-2015 08:30 PM
At first I put the event structure and for loop inside the wire loop and everything worked fine. Then I dragged them out because I only want the event structure to be executed once -- so the position of the star 1 can be only set once. Is there any pattern that can do this? So far I only know producer/consumer structure.
12-05-2015 08:32 PM
Thank you! I learned so much from your code. I never thought of simplifying my code before and I can't believe it could be done like this.
My heart said a thousand times " Bravo!"
12-05-2015 09:23 PM
12-06-2015 12:43 PM - edited 12-06-2015 12:44 PM
From your original code, it seems you wanted to have more than two stars. In this case you should make the code scalable so you don't need to change much if the number of stars needs to be increased in the future. Here's a quick draft showing how to do that.
At the moment, the various stars are placed with a combination of ctrl and shift when clicking, but you could easily just use a numeric control that selects the stars to be placed at the click location. You should probably add more properties to the stars cluster so each has a mass, size, and color, position, etc.
Also note that we no longer need a timeout case. The graph is only updated when something has changed. You could use it later to e.g. simulate orbits.