source: NonGTP/FCollada/FMath/FMVector2.h @ 964

Revision 964, 3.5 KB checked in by igarcia, 18 years ago (diff)
Line 
1/*
2        Copyright (C) 2005-2006 Feeling Software Inc.
3        MIT License: http://www.opensource.org/licenses/mit-license.php
4*/
5
6/**
7        @file FMVector2.h
8        The file containing the class and global functions for 2 dimensional
9        vectors.
10*/
11
12#ifndef _FM_VECTOR2_H_
13#define _FM_VECTOR2_H_
14
15/**
16        A 2 dimensional vector.
17        Not used within FCollada.
18       
19        @ingroup FMath
20*/
21class FCOLLADA_EXPORT FMVector2
22{
23public:
24        float u;        /**< The first coordinate. */
25        float v;        /**< The second coordinate. */
26
27public:
28        /**
29         * Creates an empty FMVector2.
30         */
31        #ifndef _DEBUG
32        FMVector2() {}
33        #else
34        FMVector2() { u = 123456789.0f; v = 123456789.0f; }
35        #endif
36
37        /**
38         * Creates the FMVector2 with the coordinates given.
39         *
40         * @param _u The first coordinate.
41         * @param _v The second coordinate.
42         */
43        FMVector2(float _u, float _v) { u = _u; v = _v; }
44
45        /**
46         * Get this FMVector2 as an array of \c floats.
47         *
48         * @return The \c float array.
49         */
50        inline operator float*() { return &u; }
51
52        /**
53         * Adds two FMVector2.
54         *
55         * Adds to this FMVector2's coordinates the individual components of the
56         * given FMVector2 and returns this FMVector2.
57         *
58         * @param a The FMVector2 to add with this one.
59         * @return This FMVector2.
60         */
61        inline FMVector2& operator +=(const FMVector2& a) { u += a.u; v += a.v; return *this; }
62
63        /**
64         * Multiplies this FMVector2 by a scaler.
65         *
66         * Multiplies each of this FMVector2's coordinates with the scaler and
67         * returns this FMVector2.
68         *
69         * @param a The scalar to multiply with.
70         * @return This FMVector2.
71         */
72        inline FMVector2& operator *=(float a) { u *= a; v *= a; return *this; }
73       
74        /**
75         * Assign this FMVector2 to the given float array.
76         *
77         * Assigns each coordinate of this FMVector2 to the elements in the \c
78         * float array. The first element to the first coordinate and the second to
79         * the second. It returns this FMVector2.
80         *
81         * @param f The \c float array to assign with.
82         * @return This FMVector2.
83         */
84        inline FMVector2& operator =(const float* f) { u = *f; v = *(f + 1); return *this; }
85};
86
87/**
88 * Vector addition with two FMVector2.
89 *
90 * @param a The first vector.
91 * @param b The second vector.
92 * @return The FMVector2 representation of the resulting vector.
93 */
94inline FMVector2 operator + (const FMVector2& a, const FMVector2& b) { return FMVector2(a.u + b.u, a.v + b.v); }
95
96/**
97 * Vector subtraction with two FMVector2.
98 *
99 * @param a The first vector.
100 * @param b The second vector.
101 * @return The FMVector2 representation of the resulting vector.
102 */
103inline FMVector2 operator -(const FMVector2& a, const FMVector2& b) { return FMVector2(a.u - b.u, a.v - b.v); }
104
105/**
106 * Dot product of two FMVector2.
107 *
108 * @param a The first vector.
109 * @param b The second vector.
110 * @return The result of the dot product.
111 */
112inline float operator *(const FMVector2& a, const FMVector2& b) { return a.u * b.u + a.v * b.v; }
113
114/**
115 * Scalar multiplication with a FMVector2.
116 *
117 * @param a The vector.
118 * @param b The scalar.
119 * @return The FMVector2 representing the resulting the vector.
120 */
121inline FMVector2 operator *(const FMVector2& a, float b) { return FMVector2(a.u * b, a.v * b); }
122
123/**
124 * Scalar multiplication with a FMVector2.
125 *
126 * @param a The scalar.
127 * @param b The vector.
128 * @return The FMVector2 representing the resulting the vector.
129 */
130inline FMVector2 operator *(float a, const FMVector2& b) { return FMVector2(a * b.u, a * b.v); }
131
132#endif // _FM_VECTOR2_H_
Note: See TracBrowser for help on using the repository browser.