-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVector3f.cpp
executable file
·107 lines (86 loc) · 1.91 KB
/
Vector3f.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "Vector3f.h"
namespace Engine
{
Vector3f::Vector3f()
:
x( 0 ),
y( 0 ),
z( 0 )
{}
Vector3f::Vector3f( float x, float y, float z )
:
x( x ),
y( y ),
z( z )
{}
Vector3f::~Vector3f(){}
std::string Vector3f::toString( )
{
//return "(" + x + " " + y + " " + z + ")";
}
float Vector3f::dot( const Vector3f& otherVec )
{
return x * otherVec.getX() + y * otherVec.getY() + z * otherVec.getZ();
}
Vector3f Vector3f::cross( const Vector3f& otherVec )
{
float f0 = y * otherVec.getZ( ) - z * otherVec.getY( );
float f1 = z * otherVec.getX( ) - x * otherVec.getZ( );
float f2 = x * otherVec.getY( ) - y * otherVec.getX( );
return Vector3f( f0, f1, f2 );
}
float Vector3f::length()
{
return (float)sqrt( dot( *this ) );
}
void Vector3f::normalize()
{
float len = length();
if( len != 0 )
{
x /= len;
y /= len;
z /= len;
}
}
void Vector3f::setX( float x )
{
this->x = x;
}
void Vector3f::setY( float y )
{
this->y = y;
}
void Vector3f::setZ( float z )
{
this->z = z;
}
float Vector3f::getX() const
{
return this->x;
}
float Vector3f::getY() const
{
return this->y;
}
float Vector3f::getZ() const
{
return this->z;
}
Vector3f Vector3f::operator+( const Vector3f& otherVec )
{
return Vector3f( x + otherVec.getX(), y + otherVec.getY(), z + otherVec.getZ() );
}
Vector3f Vector3f::operator-( const Vector3f& otherVec )
{
return Vector3f( x - otherVec.getX(), y - otherVec.getY(), z - otherVec.getZ() );
}
Vector3f Vector3f::operator*( float factor )
{
}
Vector3f Vector3f::operator/( float denominator ){}
Vector3f& Vector3f::operator+=( const Vector3f& otherVec ){}
Vector3f& Vector3f::operator-=( const Vector3f& otherVec ){}
Vector3f& Vector3f::operator*=( float factor ){}
Vector3f& Vector3f::operator/=( float denominator ){}
}