source: GTP/trunk/App/Games/Jungle_Rumble/src/Vector.cpp @ 1378

Revision 1378, 3.0 KB checked in by giegl, 18 years ago (diff)

GTPD - Jungle Rumble - integrate into GTP SVN structure

Line 
1#include "dxstdafx.h"
2#include ".\vector.h"
3
4Vector::Vector(void) : D3DXVECTOR4(0, 0, 0, 1)
5{
6}
7
8Vector::Vector(float _x, float _y, float _z) : D3DXVECTOR4(_x, _y, _z, 1)
9{
10}
11
12Vector::Vector(NxVec3 vec) :  D3DXVECTOR4(vec.x, vec.y, vec.z,1)
13{
14}
15
16void Vector::normalize()
17{
18        float thelen = 1/sqrt (x*x + y*y + z*z);
19
20        if (thelen != 0)
21        {
22                x *= thelen;
23                y *= thelen;
24                z *= thelen;
25        }
26}
27
28float Vector::length()
29{
30        return sqrt(x*x + y*y + z*z);
31}
32
33NxVec3 Vector::getNxVector()
34{
35        this->nxVector.x = this->x;
36        this->nxVector.y = this->y;
37        this->nxVector.z = this->z;
38        return this->nxVector;
39}
40
41void Vector::setNxVector(NxVec3 &nxv)
42{
43        //D3DVector aktualisieren
44        this->x = nxv.x;
45        this->y = nxv.y;
46        this->z = nxv.z;
47        this->w = 1;
48}
49
50D3DXVECTOR3 Vector::getD3DXVector3()
51{
52        D3DXVECTOR3 temp(this->x, this->y, this->z);
53        return temp;
54}
55
56NxQuat Vector::getNxQuatRotation()
57{
58        NxQuat q;
59
60        float _x, _y, _z,cr, cp, cy, sr, sp, sy, cpcy, spsy;
61
62        _x = this->x/2;
63        _y = this->y/2;
64        _z = this->z/2;
65
66        cr = cos(_x);
67        cp = cos(_y);
68        cy = cos(_z);
69
70        sr = sin(_x);
71        sp = sin(_y);
72        sy = sin(_z);
73
74        cpcy = cp * cy;
75        spsy = sp * sy;
76       
77        q.setx(sr * cpcy - cr * spsy);
78        q.sety(cr * sp * cy + sr * cp * sy);
79        q.setz(cr * cp * sy - sr * sp * cy);
80        q.setw(cr * cpcy + sr * spsy);
81
82        return q;
83}
84
85Vector Vector::crossProd(Vector &v2)
86{
87        Vector v(y*v2.z-z*v2.y, z*v2.x-x*v2.z, x*v2.y-y*v2.x);
88        return v;
89}
90
91float Vector::dotProd(Vector &v2)  {
92        float ret = x*v2.x + y*v2.y + z*v2.z;
93        return ret;
94}
95
96// assignment operators
97Vector Vector::operator += ( CONST Vector& v)
98{
99        D3DXVECTOR4 tmpv = (D3DXVECTOR4) (*this)+v;
100        Vector retv(tmpv.x, tmpv.y, tmpv.z);
101        return retv;
102}
103
104Vector Vector::operator -= ( CONST Vector& v)
105{
106        D3DXVECTOR4 tmpv = (D3DXVECTOR4) (*this)-v;
107        Vector retv(tmpv.x, tmpv.y, tmpv.z);
108        return retv;
109}
110
111Vector Vector::operator *= ( float a)
112{
113        D3DXVECTOR4 tmpv = (D3DXVECTOR4) (*this)*a;
114        Vector retv(tmpv.x, tmpv.y, tmpv.z);
115        return retv;
116}
117
118Vector Vector::operator /= ( float a)
119{
120        D3DXVECTOR4 tmpv = (D3DXVECTOR4) (*this)/a;
121        Vector retv(tmpv.x, tmpv.y, tmpv.z);
122        return retv;
123}
124
125// binary operators
126Vector Vector::operator + ( CONST Vector& v) const
127{
128        Vector retv(this->x+v.x, this->y+v.y, this->z+v.z);
129        return retv;
130}
131
132Vector Vector::operator - ( CONST Vector& v) const
133{
134        Vector retv(this->x-v.x, this->y-v.y, this->z-v.z);
135        return retv;
136}
137
138Vector Vector::operator * ( float a) const
139{
140        Vector retv(this->x*a, this->y*a, this->z*a);
141        return retv;
142}
143
144Vector Vector::operator / ( float a) const
145{
146        Vector retv(this->x/a, this->y/a, this->z/a);
147        return retv;
148}
149
150void Vector::applyD3DXVector(D3DXVECTOR4 *v) {
151        this->x = v->x;
152        this->y = v->y;
153        this->z = v->z;
154        this->w = v->w;
155}
156
157void Vector::setXYZ(float _x, float _y, float _z)
158{
159        this->x = _x;
160        this->y = _y;
161        this->z = _z;
162        this->w = 1;
163}
164
165void Vector::addXYZ(float _x, float _y, float _z)
166{
167        this->x += _x;
168        this->y += _y;
169        this->z += _z;
170}
Note: See TracBrowser for help on using the repository browser.