using System using System Collections Generic using System ComponentMo

  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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
?using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace _3DGraph
{
public partial class graphForm : Form
{
float pi = 3.1415F;
float s1 = 250.0F/17.5F;
float s2 = 2 * 250 * 750 / 1026;
public graphForm()
{
InitializeComponent();
//directXW.Paint += new PaintEventHandler(directXW_Paint);
directXW.DeviceInit();
}
//DateTime dt = new DateTime();
void directXW_Paint(object sender, PaintEventArgs e)
{
//this.Text = "Rendering time: " + (DateTime.Now - dt).TotalMilliseconds.ToString() + " ms...";
//dt = DateTime.Now;
}
private void btnGo_Click(object sender, EventArgs e)
{
Random rd = new Random(unchecked((int)DateTime.Now.Ticks));
directXW.DrawType = rd.Next(0, 2);
directXW.DeviceInit();
if (!directXW.FreeRotations)
{
btnGo.Text = "Стоп";
directXW.FreeRotations = true;
}
else
{
btnGo.Text = "Старт";
directXW.FreeRotations = false;
}
}
public float sech(float d)
{
return (float)(1.0F / Math.Cosh(d));
}
private void DrawSimple()
{
Graphics g = Graphics.FromHwnd(this.Handle);
for (float t = -pi; t < pi; )
{
float c = 0;
c++;
for (float p = -2.0F * pi; p < 2.0F * pi; )
{
float x1 = (p - (float)Math.Tanh(p));
float y1 = sech(p) * (float)Math.Sin(t);
float z1 = sech(p) * (float)Math.Cos(t);
g.FillEllipse(Brushes.Red, 1026.0F / 2.0F + 17.5F * s1 * 2.0F * x1 / (1.0F + z1 / 4.0F), 750.0F / 2.0F + 0.5F * s2 * (750.0F / 1026.0F) * 2.0F * y1 / (1.0F + z1 / 4.0F), 1, 1);
p = p + pi / 100.0F;
}
t = t + (pi / 100.0F) * 2.0F;
}
for (float t = -pi; t < pi; )
{
float c = 0;
c++;
for (float p = -2.0F * pi; p < 2.0F * pi; )
{
float x = (p - (float)Math.Tanh(p)) / ((float)((int)p ^ 2) - 2 * (float)Math.Tanh(p) + 1);
float y = -sech(p) * (float)Math.Sin(t) / ((float)((int)p ^ 2) - 2 * (float)Math.Tanh(p) + 1);
float z = -sech(p) * (float)Math.Cos(t) / ((float)((int)p ^ 2) - 2 * (float)Math.Tanh(p) + 1);
try
{
g.FillEllipse(Brushes.Blue, 1026.0F / 2.0F + s1 * 2.0F * y / (1.0f + z / 4.0f),
750.0F / 6.0F + s2 * (750.0F / 1026.0F) * 2.0F * x / (1.0F + z / 4.0F), 1, 1);
}
catch
{
}
p = p + pi / 100.0F;
}
t = t + (pi / 200.0F) * 2.0F;
}
}
const int WM_KEYDOWN = 0x100;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if ((msg.Msg == WM_KEYDOWN))
{
switch (keyData)
{
case Keys.Down:
directXW.RotateTo(3);
break;
case Keys.Up:
directXW.RotateTo(2);
break;
case Keys.Left:
directXW.RotateTo(0);
break;
case Keys.Right:
directXW.RotateTo(1);
break;
case Keys.OemMinus:
case Keys.Subtract:
directXW.RotateTo(5);
break;
case Keys.Oemplus:
case Keys.Add:
directXW.RotateTo(4);
break;
}
}
else
{
if (keyData == Keys.LButton)
this.Text = DateTime.Now.ToString();
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override void WndProc(ref Message m)
{
bool mouseDown = m.Msg == 0x201 || m.Msg == 0x203;
base.WndProc(ref m);
}
private void cbCenter_CheckedChanged(object sender, EventArgs e)
{
directXW.UniverseCenter = cbCenter.Checked;
}
}
}