-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3D_Model.cs
More file actions
138 lines (109 loc) · 4.3 KB
/
Copy path3D_Model.cs
File metadata and controls
138 lines (109 loc) · 4.3 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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;
using System.IO;
using System.Drawing;
namespace _08_Step
{
class _3D_Model
{
public ArrayList L_3D_Pts = new ArrayList();
public ArrayList L_Edges = new ArrayList();
public float focal = 0.5f;
public Camera cam;
public Color clr = Color.Black;
public void AddPoint(CPoint3D_Node pnn)
{
L_3D_Pts.Add(pnn);
}
public void AddEdge(int i, int j, Color cl)
{
Edge pnn = new Edge(i, j);
pnn.cl = cl;
L_Edges.Add(pnn);
}
public void LoadFromFile(string strF)
{
L_3D_Pts = new ArrayList();
L_Edges = new ArrayList();
StreamReader sr = new StreamReader( strF );
string strLine;
int Flag = 0;
while ( (strLine = sr.ReadLine()) != null)
{
if (strLine[0] == 'L')
{
Flag = 1;
continue;
}
if (Flag == 0)
{
string []ss = strLine.Split(',');
CPoint3D_Node pnn = new CPoint3D_Node(
float.Parse (ss[0].Trim()),
float.Parse(ss[1].Trim()),
float.Parse(ss[2].Trim())
);
L_3D_Pts.Add(pnn);
}
if (Flag == 1)
{
string[] ss = strLine.Split(',');
Edge pnn = new Edge(
int.Parse(ss[0].Trim()),
int.Parse(ss[1].Trim())
);
L_Edges.Add(pnn);
}
}
sr.Close();
}
public void DrawYourSelf(Graphics g)
{
CPoint3D_Node tmp1 ;
CPoint3D_Node tmp2 ;
for (int i = 0; i < L_Edges.Count; i++)
{
Edge ptrv = (Edge)L_Edges[i];
Pen PP = new Pen(ptrv.cl);
tmp1 = new CPoint3D_Node((CPoint3D_Node)L_3D_Pts[ptrv.E0]);
tmp2 = new CPoint3D_Node((CPoint3D_Node)L_3D_Pts[ptrv.E1]);
bool isVisible = cam.TransformToOrigin_And_Rotate_And_Project( tmp1, tmp2);
//PointF e = cam.TransformToOrigin_And_Rotate_And_Project((CPoint3D_Node)L_3D_Pts[ptrv.E1]);
if (isVisible)
g.DrawLine( PP,
tmp1.X ,
tmp1.Y ,
tmp2.X ,
tmp2.Y );
}
//Font FF = new Font("System", 10);
//for (int i = 0; i < L_2D.Count; i++)
//{
// PointF v = (PointF)L_2D[i];
// g.FillEllipse(Brushes.Red,
// XB + v.X - 5,
// YB + v.Y - 5,
// 10, 10);
// g.DrawString("P" + (i), FF, Brushes.Green, XB + v.X, YB + v.Y + 10);
//}
}
public void Rotat_Aroun_Edge(int iEdge)
{
if (iEdge < 0 || iEdge >= L_Edges.Count)
return;
Edge e = (Edge)L_Edges[iEdge];
CPoint3D_Node pointer = (CPoint3D_Node )L_3D_Pts[e.E0];
CPoint3D_Node pointer2 = (CPoint3D_Node)L_3D_Pts[e.E1];
CPoint3D_Node v1 = new CPoint3D_Node(pointer.X,pointer .Y, pointer .Z) ;
CPoint3D_Node v2 = new CPoint3D_Node(pointer2.X, pointer2.Y, pointer2.Z);
Transformation_API.RotateArbitrary(
ref L_3D_Pts,
v1, //(CPoint3D_Node)L_3D_Pts[0],
v2, //(CPoint3D_Node)L_3D_Pts[1],
5);
}
}
}