2009-01-21 01:00:31 +01:00
|
|
|
/* libsegl - Sebas Extended GL Library
|
|
|
|
* Collection of Opengl/3D-Math helpers
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
|
|
|
|
* http://www.seba-geek.de
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library 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
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
2008-03-08 23:03:26 +01:00
|
|
|
#include "punkt2d.h"
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
namespace segl {
|
|
|
|
|
2008-03-08 23:03:26 +01:00
|
|
|
Punkt2D::Punkt2D() {
|
|
|
|
x = y = 0.0f;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D::Punkt2D(float _x, float _y) {
|
|
|
|
set(_x, _y);
|
|
|
|
}
|
|
|
|
|
|
|
|
void Punkt2D::set(float _x, float _y) {
|
|
|
|
x = _x;
|
|
|
|
y = _y;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Punkt2D::print(std::string coordname) {
|
|
|
|
if(coordname!="")
|
|
|
|
coordname.append(" ");
|
|
|
|
std::cout << coordname << "Coord: (" << x << ", " << y << ")" << std::endl;
|
|
|
|
}
|
|
|
|
|
2008-06-17 02:46:39 +02:00
|
|
|
float Punkt2D::abs() {
|
|
|
|
return sqrt(x*x + y*y);
|
|
|
|
}
|
2008-03-08 23:03:26 +01:00
|
|
|
|
2008-09-19 17:34:01 +02:00
|
|
|
void Punkt2D::normalize() {
|
|
|
|
float a = abs();
|
|
|
|
x /= a;
|
|
|
|
y /= a;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::getNormalized() const {
|
|
|
|
Punkt2D ret(*this);
|
|
|
|
ret.normalize();
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2008-03-08 23:03:26 +01:00
|
|
|
Punkt2D Punkt2D::operator+(const Punkt2D &b) {
|
|
|
|
Punkt2D c;
|
|
|
|
c.x = x + b.x;
|
|
|
|
c.y = y + b.y;
|
|
|
|
// c.z = z + b.z;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator-(const Punkt2D &b) {
|
|
|
|
Punkt2D c;
|
|
|
|
c.x = x - b.x;
|
|
|
|
c.y = y - b.y;
|
|
|
|
// c.z = z - b.z;
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D& Punkt2D::operator+=(const Punkt2D &b) {
|
|
|
|
x += b.x;
|
|
|
|
y += b.y;
|
|
|
|
// z += b.z;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D& Punkt2D::operator-=(const Punkt2D &b) {
|
|
|
|
x -= b.x;
|
|
|
|
y -= b.y;
|
|
|
|
// z -= b.z;
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator+(const float &_m) {
|
|
|
|
return Punkt2D(x+_m, y+_m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator-(const float &_m) {
|
|
|
|
return Punkt2D(x-_m, y-_m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator*(const float &_m) {
|
|
|
|
return Punkt2D(x*_m, y*_m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator/(const float &_m) {
|
|
|
|
return Punkt2D(x/_m, y/_m);
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D& Punkt2D::operator+=(const float &_m) {
|
|
|
|
x += _m;
|
|
|
|
y += _m;
|
|
|
|
// z += _m;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Punkt2D& Punkt2D::operator-=(const float &_m) {
|
|
|
|
x -= _m;
|
|
|
|
y -= _m;
|
|
|
|
// z -= _m;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Punkt2D& Punkt2D::operator*=(const float &_m) {
|
|
|
|
x *= _m;
|
|
|
|
y *= _m;
|
|
|
|
// z *= _m;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
Punkt2D& Punkt2D::operator/=(const float &_m) {
|
|
|
|
x /= _m;
|
|
|
|
y /= _m;
|
|
|
|
// z /= _m;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
float Punkt2D::operator*(const Punkt2D& _m) {
|
|
|
|
return x * _m.x + y * _m.y;
|
|
|
|
}
|
|
|
|
|
|
|
|
Punkt2D Punkt2D::operator-() {
|
|
|
|
return Punkt2D(-x, -y);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Punkt2D::operator==(const Punkt2D& b) {
|
|
|
|
return ( x==b.x && y==b.y);
|
|
|
|
}
|
|
|
|
bool Punkt2D::operator!=(const Punkt2D& b) {
|
|
|
|
return !(*this==b);
|
|
|
|
}
|
2008-08-10 17:14:54 +02:00
|
|
|
|
2008-03-08 23:03:26 +01:00
|
|
|
// Freunde
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
segl::Punkt2D operator+(const float& _m, const segl::Punkt2D& b) {
|
|
|
|
return segl::Punkt2D(b.x+_m, b.y+_m);
|
2008-03-08 23:03:26 +01:00
|
|
|
}
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
segl::Punkt2D operator-(const float& _m, const segl::Punkt2D& b) {
|
|
|
|
return segl::Punkt2D(b.x-_m, b.y-_m);
|
2008-03-08 23:03:26 +01:00
|
|
|
}
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
segl::Punkt2D operator*(const float& _m, const segl::Punkt2D& b) {
|
|
|
|
return segl::Punkt2D(b.x*_m, b.y*_m);
|
2008-03-08 23:03:26 +01:00
|
|
|
}
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
segl::Punkt2D operator/(const float& _m, const segl::Punkt2D& b) {
|
|
|
|
return segl::Punkt2D(b.x/_m, b.y/_m);
|
2008-03-08 23:03:26 +01:00
|
|
|
}
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
} // namespace segl
|
|
|
|
|
|
|
|
void glTexCoord2f(segl::Punkt2D p) {
|
2008-04-11 15:57:56 +02:00
|
|
|
glTexCoord2f(p.x, p.y);
|
|
|
|
}
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
float abs(segl::Punkt2D p) {
|
2008-06-17 02:46:39 +02:00
|
|
|
return p.abs();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Fixed Headers
|
2008-08-10 17:14:54 +02:00
|
|
|
void glTexCoordP2D(segl::Punkt2D p) {
|
2008-06-17 02:46:39 +02:00
|
|
|
glTexCoord2f(p.x, p.y);
|
|
|
|
}
|