2005-02-27 09:00:13 +00:00
|
|
|
//This file is part of Photon (http://photon.sourceforge.net)
|
|
|
|
//Copyright (C) 2004-2005 James Turk
|
|
|
|
//
|
|
|
|
// Author:
|
|
|
|
// James Turk (jpt2433@rit.edu)
|
|
|
|
//
|
|
|
|
// Version:
|
2005-03-03 09:25:19 +00:00
|
|
|
// $Id: math.hpp,v 1.4 2005/03/03 09:25:19 cozman Exp $
|
2005-02-27 09:00:13 +00:00
|
|
|
|
|
|
|
#ifndef PHOTON_MATH_MATH_HPP
|
|
|
|
#define PHOTON_MATH_MATH_HPP
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
|
|
|
|
#include "types.hpp"
|
|
|
|
|
|
|
|
namespace photon
|
|
|
|
{
|
|
|
|
namespace math
|
|
|
|
{
|
|
|
|
|
|
|
|
class Vector2;
|
|
|
|
|
2005-03-01 07:51:23 +00:00
|
|
|
// Title: Math Utilities
|
|
|
|
|
2005-03-02 10:55:54 +00:00
|
|
|
// Group: Constants
|
2005-03-03 09:25:19 +00:00
|
|
|
|
|
|
|
// Constant: PI
|
|
|
|
// Defined constant for pi: 3.1415926535897932384626433832795
|
|
|
|
const scalar PI=3.1415926535897932384626433832795;
|
2005-03-02 10:55:54 +00:00
|
|
|
|
2005-03-01 07:51:23 +00:00
|
|
|
// Group: Generic
|
|
|
|
|
2005-02-27 09:00:13 +00:00
|
|
|
// Function: clamp
|
|
|
|
// Clamp a value between two boundaries.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// val - value to clamp
|
|
|
|
// low - lower boundary
|
|
|
|
// high - upper boundary
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// low if val < low, high if val > high, val otherwise
|
|
|
|
template<typename T, typename C>
|
|
|
|
T clamp(T val, C low, C high);
|
|
|
|
|
|
|
|
// Function: scalarCompare
|
|
|
|
// Check for equality, using an epsilon.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// val1 - First value to compare.
|
|
|
|
// val2 - Second value to compare.
|
|
|
|
// epsilon - Epsilon value, defaults to 0.0001.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// true if |val1-val2| < epsilon
|
|
|
|
bool scalarCompare(scalar val1, scalar val2, scalar epsilon=0.000001);
|
|
|
|
|
|
|
|
// Function: distance
|
|
|
|
// Determine distance between two points.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// v1 - First point.
|
|
|
|
// v2 - Second point.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Scalar distance between the two points.
|
2005-03-03 09:25:19 +00:00
|
|
|
scalar distance(const Vector2& v1, const Vector2& v2);
|
2005-02-27 09:00:13 +00:00
|
|
|
|
2005-03-01 07:51:23 +00:00
|
|
|
// Group: Degrees/Radians
|
|
|
|
|
2005-02-27 09:00:13 +00:00
|
|
|
// Function: degToRad
|
|
|
|
// Convert degrees to radians.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// degrees - Degree value to convert to radians.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Radian equivalent of 'degrees'.
|
2005-03-03 09:25:19 +00:00
|
|
|
//
|
|
|
|
// See Also:
|
|
|
|
// <radToDeg>
|
2005-02-27 09:00:13 +00:00
|
|
|
scalar degToRad(scalar degrees);
|
|
|
|
|
|
|
|
// Function: radToDeg
|
|
|
|
// Convert radians to degrees.
|
|
|
|
//
|
|
|
|
// Parameters:
|
|
|
|
// radians - Radian value to convert to degrees.
|
|
|
|
//
|
|
|
|
// Returns:
|
|
|
|
// Degree equivalent of 'radians'
|
2005-03-03 09:25:19 +00:00
|
|
|
//
|
|
|
|
// See Also:
|
|
|
|
// <degToRad>
|
2005-02-27 09:00:13 +00:00
|
|
|
scalar radToDeg(scalar radians);
|
|
|
|
|
2005-03-03 09:25:19 +00:00
|
|
|
// clamp template implementation
|
2005-02-27 09:00:13 +00:00
|
|
|
|
|
|
|
template<typename T, typename C>
|
|
|
|
T clamp(T val, C low, C high)
|
|
|
|
{
|
|
|
|
if(val < low)
|
|
|
|
return low;
|
|
|
|
else if(val > high)
|
|
|
|
return high;
|
|
|
|
else
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif //PHOTON_MATH_MATH_HPP
|