[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Pingus-CVS] r3636 - trunk/pingus/src/math
From: |
grumbel at BerliOS |
Subject: |
[Pingus-CVS] r3636 - trunk/pingus/src/math |
Date: |
Thu, 3 Jul 2008 02:14:19 +0200 |
Author: grumbel
Date: 2008-07-03 02:14:18 +0200 (Thu, 03 Jul 2008)
New Revision: 3636
Removed:
trunk/pingus/src/math/matrix.cpp
trunk/pingus/src/math/matrix.hpp
trunk/pingus/src/math/quaternion.cpp
trunk/pingus/src/math/quaternion.hpp
Log:
Removed unused math stuff
Deleted: trunk/pingus/src/math/matrix.cpp
===================================================================
--- trunk/pingus/src/math/matrix.cpp 2008-07-02 23:37:43 UTC (rev 3635)
+++ trunk/pingus/src/math/matrix.cpp 2008-07-03 00:14:18 UTC (rev 3636)
@@ -1,188 +0,0 @@
-/*
-** ClanLib SDK
-** Copyright (c) 1997-2005 The ClanLib Team
-**
-** This software is provided 'as-is', without any express or implied
-** warranty. In no event will the authors be held liable for any damages
-** arising from the use of this software.
-**
-** Permission is granted to anyone to use this software for any purpose,
-** including commercial applications, and to alter it and redistribute it
-** freely, subject to the following restrictions:
-**
-** 1. The origin of this software must not be misrepresented; you must not
-** claim that you wrote the original software. If you use this software
-** in a product, an acknowledgment in the product documentation would be
-** appreciated but is not required.
-** 2. Altered source versions must be plainly marked as such, and must not be
-** misrepresented as being the original software.
-** 3. This notice may not be removed or altered from any source distribution.
-**
-** Note: Some of the libraries ClanLib may link to may have additional
-** requirements or restrictions.
-**
-** File Author(s):
-**
-** Magnus Norddahl
-** (if your name is missing here, please add it)
-*/
-
-#include <string.h>
-#include <iostream>
-#include <math.h>
-#include "matrix.hpp"
-
-/////////////////////////////////////////////////////////////////////////////
-// Matrix construction:
-
-Matrix::Matrix()
-{
- memset(matrix, 0, sizeof(float[16]));
-}
-
-Matrix
-Matrix::identity()
-{
- Matrix matrix;
-
- matrix.matrix[0] = 1.0;
- matrix.matrix[5] = 1.0;
- matrix.matrix[10] = 1.0;
- matrix.matrix[15] = 1.0;
-
- return matrix;
-}
-
-Matrix::Matrix(const Matrix ©)
-{
- for (int i=0; i<16; i++)
- matrix[i] = copy.matrix[i];
-}
-
-Matrix::Matrix(const float *init_matrix)
-{
- for (int i=0; i<16; i++)
- matrix[i] = init_matrix[i];
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// Matrix attributes:
-
-float Matrix::get_origin_x() const
-{
- return matrix[12];
-}
-
-float Matrix::get_origin_y() const
-{
- return matrix[13];
-}
-
-float Matrix::get_origin_z() const
-{
- return matrix[14];
-}
-
-/////////////////////////////////////////////////////////////////////////////
-// Matrix operations:
-
-bool Matrix::operator==(const Matrix &other) const
-{
- for (int i=0; i<16; i++)
- if (matrix[i] != other.matrix[i]) return false;
- return true;
-}
-
-bool Matrix::operator!=(const Matrix &other) const
-{
- for (int i=0; i<16; i++)
- if (matrix[i] != other.matrix[i]) return true;
- return false;
-}
-
-Matrix &Matrix::operator =(const Matrix ©)
-{
- for (int i=0; i<16; i++)
- matrix[i] = copy.matrix[i];
- return *this;
-}
-
-Matrix Matrix::multiply(const Matrix &mult) const
-{
- Matrix result;
- for (int x=0; x<4; x++)
- {
- for (int y=0; y<4; y++)
- {
- result.matrix[x+y*4] =
- matrix[x]*mult.matrix[y*4] +
- matrix[x+4]*mult.matrix[y*4+1] +
- matrix[x+8]*mult.matrix[y*4+2] +
- matrix[x+12]*mult.matrix[y*4+3];
- }
- }
- return result;
-}
-
-Matrix
-Matrix::scale(float x, float y, float z)
-{
- Matrix matrix = Matrix::identity();
- matrix[0] = x;
- matrix[5] = y;
- matrix[10] = z;
- return multiply(matrix);
-}
-
-Matrix
-Matrix::translate(float x, float y, float z)
-{
- Matrix matrix = Matrix::identity();
- matrix[12] = x;
- matrix[13] = y;
- matrix[14] = z;
- return multiply(matrix);
-}
-
-Matrix
-Matrix::rotate(float angle, float x, float y, float z)
-{
- float len2 = x*x+y*y+z*z;
- if (len2 != 1.0)
- {
- float len = sqrt(len2);
- x /= len;
- y /= len;
- z /= len;
- }
-
- float c = cos(angle*3.14159265f/180);
- float s = sin(angle*3.14159265f/180);
-
- Matrix matrix = Matrix::identity();
- matrix[0] = x*x*(1-c)+c;
- matrix[1] = y*x*(1-c)+z*s;
- matrix[2] = x*z*(1-c)-y*s;
-
- matrix[4] = x*y*(1-c)-z*s;
- matrix[5] = y*y*(1-c)+c;
- matrix[6] = y*z*(1-c)+x*s;
-
- matrix[8] = x*z*(1-c)+y*s;
- matrix[9] = y*z*(1-c)-x*s;
- matrix[10] = z*z*(1-c)+c;
-
- return multiply(matrix);
-}
-
-std::ostream& operator<<(std::ostream& s, const Matrix& m)
-{
- s << "[" << m[ 0] << ", " << m[ 4] << ", " << m[ 8] << ", " << m[12] << "\n";
- s << " " << m[ 1] << ", " << m[ 5] << ", " << m[ 9] << ", " << m[13] << "\n";
- s << " " << m[ 2] << ", " << m[ 6] << ", " << m[10] << ", " << m[14] << "\n";
- s << " " << m[ 3] << ", " << m[ 7] << ", " << m[11] << ", " << m[15] <<
"]\n";
-
- return s;
-}
-
-/* EOF */
Deleted: trunk/pingus/src/math/matrix.hpp
===================================================================
--- trunk/pingus/src/math/matrix.hpp 2008-07-02 23:37:43 UTC (rev 3635)
+++ trunk/pingus/src/math/matrix.hpp 2008-07-03 00:14:18 UTC (rev 3636)
@@ -1,102 +0,0 @@
-/*
-** ClanLib SDK
-** Copyright (c) 1997-2005 The ClanLib Team
-**
-** This software is provided 'as-is', without any express or implied
-** warranty. In no event will the authors be held liable for any damages
-** arising from the use of this software.
-**
-** Permission is granted to anyone to use this software for any purpose,
-** including commercial applications, and to alter it and redistribute it
-** freely, subject to the following restrictions:
-**
-** 1. The origin of this software must not be misrepresented; you must not
-** claim that you wrote the original software. If you use this software
-** in a product, an acknowledgment in the product documentation would be
-** appreciated but is not required.
-** 2. Altered source versions must be plainly marked as such, and must not be
-** misrepresented as being the original software.
-** 3. This notice may not be removed or altered from any source distribution.
-**
-** Note: Some of the libraries ClanLib may link to may have additional
-** requirements or restrictions.
-**
-** File Author(s):
-**
-** Magnus Norddahl
-** (if your name is missing here, please add it)
-*/
-
-#ifndef HEADER_MATH_MATRIX_HPP
-#define HEADER_MATH_MATRIX_HPP
-
-#include <iosfwd>
-
-//: 4x4 Matrix.
-class Matrix
-{
-//! Construction:
-public:
- //: Constructs a 4x4 matrix.
- Matrix();
-
- Matrix(const Matrix ©);
-
- Matrix(const float *matrix);
-
- /** Returns identity matrix */
- static Matrix identity();
-
-//! Attributes:
-public:
- float matrix[16];
-
- //: Operator that returns the matrix cell at the given index.
- float &operator[](int i) { return matrix[i]; }
-
- //: Operator that returns the matrix cell at the given index.
- const float &operator[](int i) const { return matrix[i]; }
-
- //: Operator that returns the matrix cell at the given index.
- float &operator[](unsigned int i) { return matrix[i]; }
-
- //: Operator that returns the matrix cell at the given index.
- const float &operator[](unsigned int i) const { return matrix[i]; }
-
- //: Returns the x coordinate for the point (0,0,0) multiplied with this
matrix.
- float get_origin_x() const;
-
- //: Returns the y coordinate for the point (0,0,0) multiplied with this
matrix.
- float get_origin_y() const;
-
- //: Returns the z coordinate for the point (0,0,0) multiplied with this
matrix.
- float get_origin_z() const;
-
-//! Operations:
-public:
- //: Copy assignment operator.
- Matrix &operator =(const Matrix ©);
-
- //: Equality operator.
- bool operator==(const Matrix &other) const;
-
- //: Not-equal operator.
- bool operator!=(const Matrix &other) const;
-
- //: Multiply two matrices.
- Matrix multiply(const Matrix &matrix) const;
-
- //: Multiply the matrix with the given scale/translate/rotate matrix
- Matrix scale(float x, float y, float z);
- Matrix translate(float x, float y, float z);
- Matrix rotate(float angle, float x, float y, float z);
-
-//! Implementation:
-private:
-};
-
-std::ostream& operator<<(std::ostream& s, const Matrix& m);
-
-#endif
-
-/* EOF */
Deleted: trunk/pingus/src/math/quaternion.cpp
===================================================================
--- trunk/pingus/src/math/quaternion.cpp 2008-07-02 23:37:43 UTC (rev
3635)
+++ trunk/pingus/src/math/quaternion.cpp 2008-07-03 00:14:18 UTC (rev
3636)
@@ -1,104 +0,0 @@
-
-// Windstille - A Jump'n Shoot Game
-// Copyright (C) 2005 Matthias Braun <address@hidden>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-#include <config.h>
-
-#include "quaternion.hpp"
-
-#include <math.h>
-
-float
-Quaternion::magnitude() const
-{
- return sqrt(w*w + x*x + y*y + z*z);
-}
-
-void
-Quaternion::normalize()
-{
- float mag = magnitude();
- w /= mag;
- x /= mag;
- y /= mag;
- z /= mag;
-}
-
-Matrix
-Quaternion::to_matrix() const
-{
- Matrix r;
- r.matrix[0] = 1.0f - 2.0f * (y*y + z*z);
- r.matrix[4] = 2.0f * (x*y - z*w);
- r.matrix[8] = 2.0f * (x*z + y*w);
- r.matrix[12] = 0.0f;
-
- r.matrix[1] = 2.0f * (x*y + z*w);
- r.matrix[5] = 1.0f - 2.0f * (x*x + z*z);
- r.matrix[9] = 2.0f * (y*z - x*w);
- r.matrix[13] = 0.0f;
-
- r.matrix[2] = 2.0f * (x*z - y*w);
- r.matrix[6] = 2.0f * (y*z + x*w);
- r.matrix[10] = 1.0f - 2.0f * (x*x + y*y);
- r.matrix[14] = 0.0f;
-
- r.matrix[3] = 0.0f;
- r.matrix[7] = 0.0f;
- r.matrix[11] = 0.0f;
- r.matrix[15] = 1.0f;
-
- return r;
-}
-
-static float clamp(float val, float min, float max)
-{
- if(val < min)
- val = min;
- else if(val > max)
- val = max;
-
- return val;
-}
-
-Quaternion
-Quaternion::slerp(const Quaternion& o, float t) const
-{
- /** Matze: I don't understand this code :-/ It's from
- *
http://number-none.com/product/Understanding%20Slerp,%20Then%20Not%20Using%20It/
- * Though the article recommends not to use slerp I see no code for the other
- * methods so I'll use slerp anyway
- */
- float dot = dot_product(o);
-
- const float DOT_THRESHOLD = 0.995f;
- if(dot > DOT_THRESHOLD) {
- // quaternions are too close, lineary interpolate them
- Quaternion result = *this + (o - *this)*t;
- result.normalize();
- return result;
- }
-
- dot = clamp(dot, -1 ,1); // robustness
- float theta_O = acos(dot);
- float theta = theta_O * t;
-
- Quaternion v2 = o - (*this * dot);
- v2.normalize();
-
- return (*this * cos(theta)) + (v2 * sin(theta));
-}
-
-/* EOF */
Deleted: trunk/pingus/src/math/quaternion.hpp
===================================================================
--- trunk/pingus/src/math/quaternion.hpp 2008-07-02 23:37:43 UTC (rev
3635)
+++ trunk/pingus/src/math/quaternion.hpp 2008-07-03 00:14:18 UTC (rev
3636)
@@ -1,88 +0,0 @@
-
-// Windstille - A Jump'n Shoot Game
-// Copyright (C) 2005 Matthias Braun <address@hidden>
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with this program. If not, see <http://www.gnu.org/licenses/>.
-
-#ifndef __QUATERNION_HPP__
-#define __QUATERNION_HPP__
-
-#include "matrix.hpp"
-
-class Quaternion
-{
-public:
- float w;
- float x;
- float y;
- float z;
-
- Quaternion()
- : w(0), x(0), y(0), z(0)
- {}
-
- Quaternion(float w, float x, float y, float z)
- : w(w), x(x), y(y), z(z)
- {}
-
- float magnitude() const;
- void normalize();
-
- const Quaternion& operator*= (const Quaternion& o)
- {
- *this = *this * o;
- return *this;
- }
-
- Quaternion operator* (const Quaternion& o) const
- {
- return Quaternion(
- w*o.w - x*o.x - y*o.y - z*o.z,
- w*o.x + x*o.w + y*o.z - z*o.y,
- w*o.y + y*o.w + z*o.x - x*o.z,
- w*o.z + z*o.w + x*o.y - y*o.x);
- }
-
- Quaternion operator- (const Quaternion& o) const
- {
- return Quaternion(w-o.w, x-o.x, y-o.y, z-o.z);
- }
-
- Quaternion operator+ (const Quaternion& o) const
- {
- return Quaternion(w+o.w, x+o.x, y+o.y, z+o.z);
- }
-
- Quaternion operator* (float s) const
- {
- return Quaternion(w*s, x*s, y*s, z*s);
- }
-
- float dot_product(const Quaternion& o) const
- {
- return x*o.x + y*o.y + z*o.z + w*o.w;
- }
-
- Matrix to_matrix() const;
- /**
- * spherical linear interpolation
- * Returns this quaternion rotation added with t* the way from this
quaternion
- * to the o quaternion (so t should be between 0 and 1 usually)
- */
- Quaternion slerp(const Quaternion& o, float t) const;
-};
-
-#endif
-
-/* EOF */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Pingus-CVS] r3636 - trunk/pingus/src/math,
grumbel at BerliOS <=