# Unity conversion between radians and degrees

## Recommended Posts

Hello, Community! I just had an idea on how to make radian/degree conversion easier in my engine. What if I encapsulated each in a class that automatically makes the conversion. However, in a previous post, the concept of making a class based off of intrisic was doomed to failure. ex:
class Radian
{

public:
Radian ( const Degree& d );
const Radian& operator = ( const Real& f ) { mRad = f; return *this; }
const Radian& operator = ( const Degree& d );

Real GetDegrees() const; // see bottom of this file
Real GetAngleUnits() const;

Radian operator + ( const Degree& d ) const;
Radian& operator += ( const Degree& d );
Radian operator - ( const Degree& d ) const;
Radian& operator -= ( const Degree& d );
Radian operator * ( Real f ) const { return Radian ( mRad * f ); }
Radian& operator *= ( Real f ) { mRad *= f; return *this; }
Radian operator / ( Real f ) const { return Radian ( mRad / f ); }
Radian& operator /= ( Real f ) { mRad /= f; return *this; }

};


Where 'Real' can be typedef'd to float or double; PS. This is from the OGRE engine [smile] I'm just curious to see if it sounds like a good idea, exorcist_bob

##### Share on other sites
Why not just make the interface to all your engine's methods take radians, rather than an arbitrary combination of different angular units? Then you don't need a separate class at all.

##### Share on other sites
The reason for it is for extensibilities sake, so that if someone else builds a module that returns degrees, I can easily convert it over.

##### Share on other sites
You don't need full blown classes for that. Just have a rad_2_deg() and deg_2_rad() function and you're set.

##### Share on other sites
Quote:
 Original post by exorcist_bobThe reason for it is for extensibilities sake, so that if someone else builds a module that returns degrees, I can easily convert it over.

YAGNI ?

What's wrong with:
namespace {  const float pi = 3.14159f;    inline float degToRad(float rad)  {    return rad * 180.0f / pi;  }  inline float radToDeg(float deg)  {    return deg * pi / 180.0f;  }}

or even:

I see. Thanks!

##### Share on other sites
Quote:
 Original post by exorcist_bobThe reason for it is for extensibilities sake, so that if someone else builds a module that returns degrees, I can easily convert it over.

As the engine's interface designer, you get to specify what is reasonable and what is not. My opinion is that if you already support radians, you need not support degrees, and vice versa. That is, it is not unreasonable to declare "my interface shall only take radians, and your modules must comply accordingly".

## Create an account

Register a new account

• ## Partner Spotlight

• ### Forum Statistics

• Total Topics
627637
• Total Posts
2978335
• ### Similar Content

• Hi guys, check out our new game about sticks. Feedback welcome!

Stickman Dismount 2 Annihilation is a sequel to the legendary game of survival, where to make incredible tricks, driving different transport and getting into different crash! The game is made in the best traditions of simulator games with ragdoll physics elements. Make incredible jumps and tricks and destroy the enemy! Your task is make the finish alive or dead!

Website: http://strifexxx.wixsite.com/cyberpony
VK: https://vk.com/club122273704

• New indie game development studio Knife Entertainment expects to release their debut project My Little Story: Reborn.

Reborn is the first-person horror containing the spirit of the occultism and mystery. We decided to give players something, which they miss so much in games of this genre: you don't have to hide in dark corners trying to escape from some invulnerable monster. It will be vice versa. We gave players everything to make even the most savage and malicious enemy tremble with fear. You'll face the cruel world full of danger, to expose dark secrets and to fight with ancient evil.

Our principal credo is our great attention to various details. That's why there are a lot of easter eggs in the form of references and visual quoting of such cult films, games and art works, as The Evil Dead, True Detective, Silent Hill, etc. The release is scheduled for the end of this year.

• Have you ever dreamed of fighting with dinosaurs? If so, then this game is for you. Hold out against the bloodthirsty prehistoric lizards for as long as possible. Seize more weapons, including a shot gun, sword and other stuff. Good luck!

• COMPANY AND THE PROJECT

We are an indie game studio consisted of professional and friendly people. Additionally, we are a team of skilled artists and dedicated indie enthusiasts. Our current project is INT, developed on Unity Engine 5 for platforms Windows, Linux, and Mac.
INT is a 3D Sci-fi RPG with a strong emphasis on story, role playing, and innovative RPG features such as randomized companions. The focus is on the journey through a war-torn world with fast-paced combat against hordes of enemies. The player must accomplish quests like a traditional RPG, complete objectives, and meet lively crew members who will aid in the player's survival. Throughout the game you can side and complete missions through criminal cartels, and the two major combatants, the UCE and ACP, of the Interstellar Civil War.
Please note that all of our current positions are remote work. You will not be required to travel.
INT Official website
Steam Greenlight
IndieDB page
Also follow social media platforms for the latest news regarding our projects.

TALENTS NEEDED

Animation Rigger
Community Manager

REVENUE - SHARE

This is the perfect opportunity to get into the game development industry. Being an Indie team we do not have the creative restrictions often imposed by publishers or other third parties. We are extremely conscientious of our work and continuously uphold a high level of quality throughout our project.
We are unable to offer wages or per-item payments at this time. However revenue-sharing from crowd-funding is offered to team members who contribute 15-20 hours per week to company projects, as well as maintain constant communication and adhere to deadlines. Currently the crowd-funding campaign is scheduled for the year 2018. Your understanding is dearly appreciated.

Thank you for your time! We look forward to hearing from you!

John Shen
Starboard Games LLC
• By Misantes
Hey everyone
I've hit a milestone for a side-project of mine I've been working on for some time. It's been a frustrating labor of love, but reached my version 1.0 mark recently
The asset can be used to create procedural music configurations that are editable in real time in a game. You're able to edit dozens of variables like the scale, mode, tempo, instruments, effects and dozens of other settings to react and adapt to gameplay or other events (or just use it as an easy tool to custom make music for your game).
It's available on the unity asset store here: https://www.assetstore.unity3d.com/#!/content/99791
A demo is available on my github page: https://stickandbindlegames.github.io