-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFourD.CC
124 lines (96 loc) · 2.88 KB
/
FourD.CC
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
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// Greg Kaiser
//
// CS290 with Prof. Francis
// 4D Tetris
//
// FourD.C
// Last modified: April 24, 1996
//
// (C) 1996 Board of Trustees University of Illinois
#include <iostream> // for debugging purposes only
#include "FourD.h"
// Given: Nothing
// Task: Default constructor
// Return: Nothing
FourD::FourD()
{
pt = new float[4];
}
// Given: A new x, y, z, and w coordinate
// Task: Create a point with these coordinates
// Return: Nothing, but the new point has been created
FourD::FourD(float x, float y, float z, float w)
{
pt = new float[4]; pt[VX] = x; pt[VY] = y; pt[VZ] = z; pt[VW] = w;
}
// Given: A pointer to new x, y, z, and w coordinates
// Task: Create a point with these coordinates
// Return: Nothing, but the new point has been created
FourD::FourD(float *newpt)
{
pt = new float[4];
for (int i = 0; i < 4; i++)
pt[i] = newpt[i];
Assert(pt != NULL, "Ran out of memory!!!");
}
// Given: Nothing
// Task: Delete the memory used by this point
// Return: Nothing, but the memory has been freed
FourD::~FourD()
{
delete pt;
}
// for debugging purposes only
void FourD::Output()
{
#ifdef DEBUG_FOURD
cout << "Begin FourD::Output()" << endl;
#endif
for (int i =0; i < 4; i++)
std::cout << pt[i] << " ";
std::cout << std::endl;
#ifdef DEBUG_FOURD
std::cout << "End FourD::Output()" << endl;
#endif
}
// Given: Three axes for projection and a distancing factor
// Task: Plot this point in the given projection using the given factor
// Return: Nothing, but the point has been plotted
void FourD::Plot(int *axis, float *dist)
{
#ifdef DEBUG_FOURD
cout << "Begin FourD::Plot(..., ...)" << endl;
#endif
//float *temp = new float[3];
float temp[3];
for (int i = 0; i < 3; i++)
temp[i] = pt[axis[i]] - .001 * dist[i];
v3f(temp);
//delete temp;
}
// Given: A change for each of the coordinates for this point
// Task: Increment each of the corrdinates by the given increments
// Return: Nothing, but the point has been translated
void FourD::Translate(float xx, float yy, float zz, float ww)
{
pt[VX] += xx; pt[VY] += yy; pt[VZ] += zz; pt[VW] += ww;
}
// Given: A center for rotation, the two axes for the plane of rotation,
// a the sign of the rotation
// Task: Rotate this point around the given center, in the given plane,
// in the given direction
// Return: Nothing, but the point has been rotated
void FourD::Rotate(FourD *center, int dir, int dude, int sign)
{
float temp = pt[dir];
pt[dir] = ((pt[dude] - (*center)[dude]) * (float)(sign)) + (*center)[dir];
pt[dude] = ((temp - (*center)[dir]) * -(float)(sign)) + (*center)[dude];
}
// Given: An integer i
// Task: This is the subscript operator for the FourD point class
// Return: The value of the i coordinate
float& FourD::operator[](int i)
{
Assert(((i < 4) && (i > -1)), "FourD array index out of range");
return pt[i];
}