-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCube.cpp
More file actions
67 lines (58 loc) · 1.88 KB
/
Copy pathCube.cpp
File metadata and controls
67 lines (58 loc) · 1.88 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
#include "StdAfx.h"
#include "Cube.h"
Cube::Cube(void):
FourDimensionalObject(8, 18, 5)
{
float length1 = 100.0f;
float length2 = 100.0f;
float length3 = 100.0f;
float normalY = 1.0f;
mRadius = Vector4f(length1/2, length2/2, 0, length3/2).length();
for (int i = -1; i <= 1; i+=2)
for (int j = -1; j <= 1; j+=2)
for (int k = -1; k <= 1; k+=2)
AddVertex(Vector4f(i * length1/2, j * length2/2, 0, k * length3/2));
AddCube(00, 01, 02, 03, 04, 05, 06, 07,
Vector4f(0.0, 0.0, normalY/std::fabs(normalY), 0.0));
}
Cube::Cube(const Vector4f ¢er,
float length1, float length2, float length3,
float normalY) :
FourDimensionalObject(8, 18, 5),
mCenter(center)
{
assert(normalY != 0);
mRadius = Vector4f(length1/2, length2/2, 0, length3/2).length();
for (int i = -1; i <= 1; i+=2)
for (int j = -1; j <= 1; j+=2)
for (int k = -1; k <= 1; k+=2)
AddVertex(center + Vector4f(i * length1/2, j * length2/2, 0, k * length3/2));
AddCube(00, 01, 02, 03, 04, 05, 06, 07,
Vector4f(0.0, 0.0, normalY/std::fabs(normalY), 0.0));
}
Cube::Cube(const Vector4f &vertex1,
const Vector4f &edge1, const Vector4f &edge2, const Vector4f &edge3,
const Vector4f &normal):
FourDimensionalObject(8, 18, 5)
{
assert(false);
}
Cube::~Cube(void)
{
}
std::auto_ptr<ThreeDimensionalObject> Cube::Slice(const HyperPlane &plane) const
{
if (plane.Distance(mCenter) > mRadius)
return std::auto_ptr<ThreeDimensionalObject>(nullptr);
return FourDimensionalObject::Slice(plane);
}
void Cube::AddCube(size_t v0, size_t v1, size_t v2, size_t v3,
size_t v4, size_t v5, size_t v6, size_t v7,
const Vector4f &normal)
{
AddTetrahedron(v0, v1, v3, v5, normal);
AddTetrahedron(v0, v2, v3, v6, normal);
AddTetrahedron(v0, v4, v5, v6, normal);
AddTetrahedron(v3, v5, v6, v7, normal);
AddTetrahedron(v0, v3, v5, v6, normal);
}