Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Ignacio 1 · Mar 30, 2011 at 02:11 PM · rotationquaternionslerp

Selecting the rotation direction for Quaternion.Slerp

Hi! I'm making a spacecraft simulator and I'm working on adding support for mechanical gauges. In order to simplify the code, I'd call an update function where I specify the gauge and the current reading, in whatever units the gauge displays the information (e.g., feet, feet/sec, g's, etc).

In order to do that, I do the following operations in the startup phase:

  • Rotate the needle to the minimum scale value and store its rotation in a quaternion.
  • Rotate the needle to the maximum scale value and store its rotation in a quaternion.

Then, during the simulation, the UpdateNeedle function converts the needle's current reading to an interpolated value between 0 and 1 and calls the Quaternion.Slerp method in order to rotate it to the appropriate position. The function works fine for instruments whose scale doesn't span more than 180 (see the "Oxygen" gauge) but I'm having problems for bigger scales (see the "Altitude" gauge).

alt text alt text

More specifically, the "Altitude" gauge interpolates in the yellow area between the blue and red squares, which is clearly not what I want. How can I make the rotation using the other part of the scale?

Thanks in advance for your help!

--Nacho

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Jesse Anders · Mar 30, 2011 at 03:48 PM

For something like this, my inclination would be simply to use angles.

Say the gauge sweeps out an angle of about 340 degrees (as in your image). At 0, the angle of the needle is, say, 250. Given a parametric value t, the angle of the needle is then:

250 - t * 340

Or, more generally:

initial_angle - t * sweep_angle

Assuming a standard 2-d Cartesian coordinate system.

The result may of course go into the negatives (or, more generally, go outside of the range [0, 360)), but that shouldn't be a problem in most cases, and if you need the angle in the range [0, 360), you can always wrap it.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Ignacio 1 · Mar 30, 2011 at 07:10 PM 0
Share

Thanks for your reply! What you suggest is a very good solution. $$anonymous$$y solution involving slerps seemed to be very clean (at least from my point of view, hehe), but it's clearly not going to work. I'll try what you suggest.

Your answer

Hint: You can notify a user about this post by typing @username

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

Answers Answers and Comments

No one has followed this question yet.

Related Questions

Use Lerp to rotate object 2 Answers

Follow and Rotate an object 1 Answer

Rotating Rigidbodies 2 Answers

Rigidbody2d Collision Breaks Quaternion.Slerp 2 Answers

Quaternion.Euler and Quaternion.Slerp problem when using *= Add!! 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges