[Scummvm-git-logs] scummvm master -> 1606d6688d665eccf7b2535cb42b84d684e98076

criezy criezy at scummvm.org
Sun May 20 12:21:12 CEST 2018


This automated email contains information about 3 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
abb8ae0936 COMMON: Template deg2rad and rad2deg in Common/math
d52937cc7e SCI: Update rad2deg usage
1606d6688d WINTERMUTE: Update deg2rad usage


Commit: abb8ae09361d6a9e19383c21d65e085fa41c0d1e
    https://github.com/scummvm/scummvm/commit/abb8ae09361d6a9e19383c21d65e085fa41c0d1e
Author: David Fioramonti (dafioram at gmail.com)
Date: 2018-05-20T11:21:06+01:00

Commit Message:
COMMON: Template deg2rad and rad2deg in Common/math

The input and output type can be different.

Currently, rad2deg is only being used by sci (float to int)
and deg2rad in wintermute.

Changed paths:
    common/math.h


diff --git a/common/math.h b/common/math.h
index ddb5c67..a8e0768 100644
--- a/common/math.h
+++ b/common/math.h
@@ -107,12 +107,46 @@ inline int intLog2(uint32 v) {
 }
 #endif
 
-inline float rad2deg(float rad) {
-	return rad * 180.0f / (float)M_PI;
+// Convert radians to degrees
+// Input and Output type can be different
+// Upconvert everything to floats
+template <class inputT, class outputT> 
+inline outputT rad2deg(inputT rad) {
+	return (outputT)( (float)rad * (float)57.2957795130823); // 180.0/M_PI = 57.2957795130823
 }
 
-inline float deg2rad(float deg) {
-	return deg * (float)M_PI / 180.0f;
+// Handle the case differently when the input type is double
+template <class outputT> 
+inline outputT rad2deg(double rad) {
+	return (outputT)( rad * 57.2957795130823);
+}
+
+// Convert radians to degrees
+// Input and Output type are the same
+template <class T> 
+inline T rad2deg(T rad) {
+	return rad2deg<T,T>(rad);
+}
+
+// Convert degrees to radians
+// Input and Output type can be different
+// Upconvert everything to floats
+template <class inputT, class outputT> 
+inline outputT deg2rad(inputT deg) {
+	return (outputT)( (float)deg * (float)0.0174532925199433); // M_PI/180.0 = 0.0174532925199433
+}
+
+// Handle the case differently when the input type is double
+template <class outputT> 
+inline outputT deg2rad(double deg) {
+	return (outputT)( deg * 0.0174532925199433);
+}
+
+// Convert degrees to radians
+// Input and Output type are the same
+template <class T> 
+inline T deg2rad(T deg) {
+	return deg2rad<T,T>(deg);
 }
 
 } // End of namespace Common


Commit: d52937cc7e0647b1b003c84e8e8b5f508ac00a9d
    https://github.com/scummvm/scummvm/commit/d52937cc7e0647b1b003c84e8e8b5f508ac00a9d
Author: David Fioramonti (dafioram at gmail.com)
Date: 2018-05-20T11:21:06+01:00

Commit Message:
SCI: Update rad2deg usage

Changed paths:
    engines/sci/engine/kpathing.cpp


diff --git a/engines/sci/engine/kpathing.cpp b/engines/sci/engine/kpathing.cpp
index 937b1cf..eb4d5d3 100644
--- a/engines/sci/engine/kpathing.cpp
+++ b/engines/sci/engine/kpathing.cpp
@@ -1919,7 +1919,7 @@ static int intersectDir(const Vertex *v1, const Vertex *v2) {
 // Direction of edge in degrees from pos. x-axis, between -180 and 180
 static int edgeDir(const Vertex *v) {
 	Common::Point p = v->_next->v - v->v;
-	int deg = (int)Common::rad2deg((float)atan2((double)p.y, (double)p.x));
+	int deg = Common::rad2deg<float,int>((float)atan2((double)p.y, (double)p.x));
 	if (deg < -180) deg += 360;
 	if (deg > 180) deg -= 360;
 	return deg;


Commit: 1606d6688d665eccf7b2535cb42b84d684e98076
    https://github.com/scummvm/scummvm/commit/1606d6688d665eccf7b2535cb42b84d684e98076
Author: David Fioramonti (dafioram at gmail.com)
Date: 2018-05-20T11:21:06+01:00

Commit Message:
WINTERMUTE: Update deg2rad usage

Changed paths:
    engines/wintermute/base/particles/part_emitter.cpp


diff --git a/engines/wintermute/base/particles/part_emitter.cpp b/engines/wintermute/base/particles/part_emitter.cpp
index c64a099..1c102d1 100644
--- a/engines/wintermute/base/particles/part_emitter.cpp
+++ b/engines/wintermute/base/particles/part_emitter.cpp
@@ -214,7 +214,8 @@ bool PartEmitter::initParticle(PartParticle *particle, uint32 currentTime, uint3
 	Vector2 vecVel(0, velocity);
 
 	Matrix4 matRot;
-	matRot.rotationZ(Common::deg2rad(BaseUtils::normalizeAngle(angle - 180)));
+	float radZrot = Common::deg2rad<float>(BaseUtils::normalizeAngle(angle - 180.0));
+	matRot.rotationZ(radZrot);
 	matRot.transformVector2(vecVel);
 
 	if (_alphaTimeBased) {
@@ -433,7 +434,8 @@ bool PartEmitter::addForce(const Common::String &name, PartForce::TForceType typ
 
 	force->_direction = Vector2(0, strength);
 	Matrix4 matRot;
-	matRot.rotationZ(Common::deg2rad(BaseUtils::normalizeAngle(angle - 180)));
+	float radZrot = Common::deg2rad<float>(BaseUtils::normalizeAngle(angle - 180.0));
+	matRot.rotationZ(radZrot);
 	matRot.transformVector2(force->_direction);
 
 	return STATUS_OK;





More information about the Scummvm-git-logs mailing list