source:
orxonox.OLD/trunk/src/lib/math/vector2D.cc
@
7242
Last change on this file since 7242 was 6615, checked in by bensch, 19 years ago | |
---|---|
File size: 1.4 KB |
Rev | Line | |
---|---|---|
[4578] | 1 | /* |
[2043] | 2 | orxonox - the future of 3D-vertical-scrollers |
3 | ||
4 | Copyright (C) 2004 orx | |
5 | ||
6 | This program is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | ### File Specific: | |
[6615] | 12 | main-programmer: Benjamin Grauer |
13 | co-programmer: Patrick Boenzli : Vector2D::scale() | |
14 | Vector2D::abs() | |
[4578] | 15 | |
[6615] | 16 | Benjamin Grauer: port to Vector2D |
[2043] | 17 | */ |
18 | ||
[3590] | 19 | #define DEBUG_SPECIAL_MODULE DEBUG_MODULE_MATH |
[2043] | 20 | |
[6615] | 21 | #include "vector2D.h" |
[5662] | 22 | #ifdef DEBUG |
[5672] | 23 | #include "debug.h" |
[5662] | 24 | #else |
[5672] | 25 | #include <stdio.h> |
26 | #define PRINT(x) printf | |
[5662] | 27 | #endif |
[2043] | 28 | |
29 | using namespace std; | |
30 | ||
[4477] | 31 | ///////////// |
32 | /* VECTORS */ | |
33 | ///////////// | |
[2043] | 34 | /** |
[4836] | 35 | * returns the this-vector normalized to length 1.0 |
[4966] | 36 | * @todo there is some error in this function, that i could not resolve. it just does not, what it is supposed to do. |
[5420] | 37 | */ |
[6615] | 38 | Vector2D Vector2D::getNormalized() const |
[2551] | 39 | { |
[4966] | 40 | float l = this->len(); |
41 | if(unlikely(l == 1.0 || l == 0.0)) | |
42 | return *this; | |
43 | else | |
44 | return (*this / l); | |
[2551] | 45 | } |
46 | ||
[3449] | 47 | /** |
[6615] | 48 | * Vector2D is looking in the positive direction on all axes after this |
[4477] | 49 | */ |
[6615] | 50 | Vector2D Vector2D::abs() |
[4477] | 51 | { |
[6615] | 52 | Vector2D v(fabs(x), fabs(y)); |
[4477] | 53 | return v; |
54 | } | |
55 | ||
56 | ||
57 | ||
58 | /** | |
[6615] | 59 | * Outputs the values of the Vector2D |
[5420] | 60 | */ |
[6615] | 61 | void Vector2D::debug() const |
[3541] | 62 | { |
[6615] | 63 | PRINT(0)("x: %f; y: %f", x, y); |
[4987] | 64 | PRINT(0)(" lenght: %f", len()); |
[3541] | 65 | PRINT(0)("\n"); |
66 | } |
Note: See TracBrowser
for help on using the repository browser.