c++ Variable being overwritten during each loop iteration -


I'm developing simulation software for which some aspects of its functionality require some predefined behavior of an entity The behavior on which I am currently working is establishing a unit in the simulation environment to go to a 'spiral' about the determined point by the user.

There are several current options of user behavior by selecting special options from the GUI, the way I intend to implement this new behavior for the unit is as follows:

< Ul>
  • Obtain the origin of the circle from the existing location of the unit (the point specified by the user who will be spiraling around the unit) / Li>
  • Check the current distance of the unit from spiral origin:
  • If it is more than a certain distance from the original, then move directly to the original, unless it is a definite There is no distance, then start the spiral.
  • If it is less than the distance from the original, stay away from the original place, until it is not from that distance, then start the spiral.
  • Each time the unit meets a circuit of the spiral, the value displayed in the GUI, which represents the number of circuits, should be updated.
  • I have started writing a loop to implement this behavior, and I intend that with each repetition of the loop, by checking the angle of the unit from the original, the number of the entire circuit To increase, every time the angle is equal, as was the connection to the spiral behavior, I will know that another circuit has been completed. But, since I am getting an angle between the unit and the origin at the beginning of the loop, this value will be updated with every move of the loop - this will mean that the unit will not be able to reach the original again from that angle, Because the angle will keep changing.

    What would I want to know, if there is a way to set the value of a variable before running a loop, and after that the value of another loop is repetitive? Can I specify that value in a global variable, and make it 'absolute' value, so that even if I try to change its value again I will not be able to?

    EDIT

    The obvious suggestion is to set that variable variable value outside of the loop, but I can not do this due to the nature of existing behaviors That has been implemented, and then what happens when the user selects one of the behaviors.

    It almost feels like you should do the first loop of the loop to set this one time variable Exit the loop , and then repeat inside the n-1 . If the loop body is complex, then put it in a function. Also keep in mind that if you use the floating point value of your angles, then it is likely that they are never the same after the first repetition.

      int loop_body (params) Return first_iteration_value; } Int initial_value = loop_body (parameter); For (init; condition; incr) {loop_body (params); }  

    Comments

    Popular posts from this blog

    apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

    c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

    c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -