-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathvecmat.cpp
More file actions
78 lines (66 loc) · 1.41 KB
/
vecmat.cpp
File metadata and controls
78 lines (66 loc) · 1.41 KB
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
#include "vecmat.h"
Vector4::Vector4()
{
data[0]=0.0; data[1]=0.0; data[2]=0.0; data[3]=1.0;
}
void Vector4::Set(double x,double y,double z)
{
data[0]=x; data[1]=y; data[2]=z;
}
double Vector4::GetX()
{
return data[0];
}
double Vector4::GetY()
{
return data[1];
}
double Vector4::GetZ()
{
return data[2];
}
Vector4 Vector4::operator- (const Vector4 &gVector)
{
unsigned int i;
Vector4 Result;
for (i=0;i<4;i++) Result.data[i]=data[i]-gVector.data[i];
return Result;
}
Vector4 operator* (const Vector4 &gVector,double val)
{
unsigned int i;
Vector4 Result;
for (i=0;i<4;i++) Result.data[i]=gVector.data[i]*val;
return Result;
}
Matrix4::Matrix4()
{
data[0][0]=0.0; data[0][1]=0.0; data[0][2]=0.0; data[0][3]=0.0;
data[1][0]=0.0; data[1][1]=0.0; data[1][2]=0.0; data[1][3]=0.0;
data[2][0]=0.0; data[2][1]=0.0; data[2][2]=0.0; data[2][3]=0.0;
data[3][0]=0.0; data[3][1]=0.0; data[3][2]=0.0; data[3][3]=1.0;
}
Matrix4 Matrix4::operator* (const Matrix4 gMatrix)
{
int i,j,k;
Matrix4 tmp;
for (i=0;i<4;i++)
for (j=0;j<4;j++)
{
tmp.data[i][j]=0.0;
for (k=0;k<4;k++)
tmp.data[i][j]=tmp.data[i][j]+(data[i][k]*gMatrix.data[k][j]);
}
return tmp;
}
Vector4 operator* (const Matrix4 gMatrix,const Vector4 gVector)
{
unsigned int i,j;
Vector4 tmp;
for (i=0;i<4;i++)
{
tmp.data[i]=0.0;
for (j=0;j<4;j++) tmp.data[i]=tmp.data[i]+(gMatrix.data[i][j]*gVector.data[j]);
}
return tmp;
}