Small OpenGL based c++ rendering library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

punkt2d.cpp 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /* libsegl - Sebas Extended GL Library
  2. * Collection of Opengl/3D-Math helpers
  3. *
  4. * Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
  5. * http://www.seba-geek.de
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Library General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Library General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Library General Public
  18. * License along with this library; if not, write to the
  19. * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
  20. * Boston, MA 02110-1301, USA.
  21. */
  22. #include "punkt2d.h"
  23. namespace segl {
  24. Punkt2D::Punkt2D() {
  25. x = y = 0.0f;
  26. }
  27. Punkt2D::Punkt2D(float _x, float _y) {
  28. set(_x, _y);
  29. }
  30. void Punkt2D::set(float _x, float _y) {
  31. x = _x;
  32. y = _y;
  33. }
  34. void Punkt2D::print(std::string coordname) {
  35. if(coordname!="")
  36. coordname.append(" ");
  37. std::cout << coordname << "Coord: (" << x << ", " << y << ")" << std::endl;
  38. }
  39. float Punkt2D::abs() {
  40. return sqrt(x*x + y*y);
  41. }
  42. void Punkt2D::normalize() {
  43. float a = abs();
  44. x /= a;
  45. y /= a;
  46. }
  47. Punkt2D Punkt2D::getNormalized() const {
  48. Punkt2D ret(*this);
  49. ret.normalize();
  50. return ret;
  51. }
  52. Punkt2D Punkt2D::operator+(const Punkt2D &b) {
  53. Punkt2D c;
  54. c.x = x + b.x;
  55. c.y = y + b.y;
  56. // c.z = z + b.z;
  57. return c;
  58. }
  59. Punkt2D Punkt2D::operator-(const Punkt2D &b) {
  60. Punkt2D c;
  61. c.x = x - b.x;
  62. c.y = y - b.y;
  63. // c.z = z - b.z;
  64. return c;
  65. }
  66. Punkt2D& Punkt2D::operator+=(const Punkt2D &b) {
  67. x += b.x;
  68. y += b.y;
  69. // z += b.z;
  70. return *this;
  71. }
  72. Punkt2D& Punkt2D::operator-=(const Punkt2D &b) {
  73. x -= b.x;
  74. y -= b.y;
  75. // z -= b.z;
  76. return *this;
  77. }
  78. Punkt2D Punkt2D::operator+(const float &_m) {
  79. return Punkt2D(x+_m, y+_m);
  80. }
  81. Punkt2D Punkt2D::operator-(const float &_m) {
  82. return Punkt2D(x-_m, y-_m);
  83. }
  84. Punkt2D Punkt2D::operator*(const float &_m) {
  85. return Punkt2D(x*_m, y*_m);
  86. }
  87. Punkt2D Punkt2D::operator/(const float &_m) {
  88. return Punkt2D(x/_m, y/_m);
  89. }
  90. Punkt2D& Punkt2D::operator+=(const float &_m) {
  91. x += _m;
  92. y += _m;
  93. // z += _m;
  94. return *this;
  95. }
  96. Punkt2D& Punkt2D::operator-=(const float &_m) {
  97. x -= _m;
  98. y -= _m;
  99. // z -= _m;
  100. return *this;
  101. }
  102. Punkt2D& Punkt2D::operator*=(const float &_m) {
  103. x *= _m;
  104. y *= _m;
  105. // z *= _m;
  106. return *this;
  107. }
  108. Punkt2D& Punkt2D::operator/=(const float &_m) {
  109. x /= _m;
  110. y /= _m;
  111. // z /= _m;
  112. return *this;
  113. }
  114. float Punkt2D::operator*(const Punkt2D& _m) {
  115. return x * _m.x + y * _m.y;
  116. }
  117. Punkt2D Punkt2D::operator-() {
  118. return Punkt2D(-x, -y);
  119. }
  120. bool Punkt2D::operator==(const Punkt2D& b) {
  121. return ( x==b.x && y==b.y);
  122. }
  123. bool Punkt2D::operator!=(const Punkt2D& b) {
  124. return !(*this==b);
  125. }
  126. // Freunde
  127. segl::Punkt2D operator+(const float& _m, const segl::Punkt2D& b) {
  128. return segl::Punkt2D(b.x+_m, b.y+_m);
  129. }
  130. segl::Punkt2D operator-(const float& _m, const segl::Punkt2D& b) {
  131. return segl::Punkt2D(b.x-_m, b.y-_m);
  132. }
  133. segl::Punkt2D operator*(const float& _m, const segl::Punkt2D& b) {
  134. return segl::Punkt2D(b.x*_m, b.y*_m);
  135. }
  136. segl::Punkt2D operator/(const float& _m, const segl::Punkt2D& b) {
  137. return segl::Punkt2D(b.x/_m, b.y/_m);
  138. }
  139. } // namespace segl
  140. void glTexCoord2f(segl::Punkt2D p) {
  141. glTexCoord2f(p.x, p.y);
  142. }
  143. float abs(segl::Punkt2D p) {
  144. return p.abs();
  145. }
  146. // Fixed Headers
  147. void glTexCoordP2D(segl::Punkt2D p) {
  148. glTexCoord2f(p.x, p.y);
  149. }