x


Looking for ideas of how to control specific values from C#

We have two types of objects we add dynamically.

They can be rotated differently.

A) can only rotate 90 degrees, so that gives 4 directions {0,90,180,270}

B) can be rotated in 5 degress, so we have {0,5,10,15,20,25,30 ... 355} (you get the idea I think)

Problem is that we make the user rotate the object and we also need to let the user switch from type A to B and back. When switching back to A, we need to make sure that the rotation matches the rule and if it doesnt, then go for the best/nearest angle.

Does this make any sense to you and you have some ideas, please post them. I am stirring at this and cant come up with a nice solution. Only ugly hacks.

more ▼

asked Aug 16 '11 at 08:47 PM

BerggreenDK gravatar image

BerggreenDK
2.4k 54 62 75

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Mathf.Round is your friend

To round to nearest 1, Mathf.Round(value)

To round to nearest 5, Mathf.Round(value/5.0) * 5.0;

To round to nearest 90, Mathf.Round(value/90.0) * 90.0;

more ▼

answered Aug 16 '11 at 08:56 PM

DaveA gravatar image

DaveA
26.5k 151 171 256

oh my.. so pure and simple! I was thinking in terms of Modulus etc. THANKS A LOT!

Aug 16 '11 at 10:22 PM BerggreenDK
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x4161
x2167
x182
x56

asked: Aug 16 '11 at 08:47 PM

Seen: 650 times

Last Updated: Aug 16 '11 at 10:22 PM