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
|
private void Render()
{
// Colorie Fond Ecran
GL.ClearColor(new Color4((byte)64, (byte)64, (byte)64, (byte)255));
GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit);
// Caméra
float demiAngleOuverture = 40.0f * ((float)(Math.PI / 180.0));
float ratioLargeurSurHauteur = (float)((float)glControl1.Width / (float)glControl1.Height);
float distanceFront = 0.1f;
float distanceBack = 10000.0f;
GL.MatrixMode(MatrixMode.Projection);
GL.LoadIdentity();
OpenTK.Matrix4 perspective = OpenTK.Matrix4.CreatePerspectiveFieldOfView(demiAngleOuverture, ratioLargeurSurHauteur, distanceFront, distanceBack);
GL.LoadMatrix(ref perspective);
float _alpha = (float)(alpha * (Math.PI / 180));
float _beta = (float)(beta * (Math.PI / 180));
float xO = (float)(rayonSphere * Math.Cos(_beta) * Math.Cos(_alpha));
float yO = (float)(rayonSphere * Math.Cos(_beta) * Math.Sin(_alpha));
float zO = (float)(rayonSphere * Math.Sin(_beta));
float upX = (float)(-Math.Cos(_alpha) * Math.Sin(_beta));
float upY = (float)(-Math.Sin(_alpha) * Math.Sin(_beta));
float upZ = (float)Math.Cos(_beta);
Matrix4 camera = Matrix4.LookAt((float)(xCentre + xO), (float)(yCentre + yO), (float)(zCentre + zO), xCentre, yCentre, zCentre, upX, upY, upZ);
GL.MatrixMode(MatrixMode.Modelview);
GL.LoadMatrix(ref camera);
// Lumière
GL.LoadIdentity();
Lumiere(0,0,-1);
// Modèle
// GL.ShadeModel(ShadingModel.Smooth);
GL.Begin(PrimitiveType.Triangles);
bool sens = false;
for (int y = 0; y < nbPasY - 1; y++)
{
int indexDebut = y * nbPasX;
sens = !sens;
for (int i = indexDebut; i < indexDebut + nbPasX - 1; i++)
{
double nx = 0;
double ny = 0;
double nz = 0;
if (sens)
{
// 1er triangle
Normale(ref nx, ref ny, ref nz, strip[i].X1, strip[i].Y1, strip[i].Z1, strip[i].X0, strip[i].Y0, strip[i].Z0, strip[i + 1].X1, strip[i + 1].Y1, strip[i + 1].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X1, (float)strip[i].Y1, (float)strip[i].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X0, (float)strip[i].Y0, (float)strip[i].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X1, (float)strip[i + 1].Y1, (float)strip[i + 1].Z1);
// 2ème triangle
Normale(ref nx, ref ny, ref nz, strip[i + 1].X0, strip[i + 1].Y0, strip[i + 1].Z0, strip[i + 1].X1, strip[i + 1].Y1, strip[i + 1].Z1, strip[i].X0, strip[i].Y0, strip[i].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X0, (float)strip[i + 1].Y0, (float)strip[i + 1].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X1, (float)strip[i + 1].Y1, (float)strip[i + 1].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X0, (float)strip[i].Y0, (float)strip[i].Z0);
}
else
{
// 1er triangle
Normale(ref nx, ref ny, ref nz, strip[i].X0, strip[i].Y0, strip[i].Z0, strip[i].X1, strip[i].Y1, strip[i].Z1, strip[i + 1].X0, strip[i + 1].Y0, strip[i + 1].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X0, (float)strip[i].Y0, (float)strip[i].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X1, (float)strip[i].Y1, (float)strip[i].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X0, (float)strip[i + 1].Y0, (float)strip[i + 1].Z0);
// 2ème triangle
Normale(ref nx, ref ny, ref nz, strip[i + 1].X1, strip[i + 1].Y1, strip[i + 1].Z1, strip[i + 1].X0, strip[i + 1].Y0, strip[i + 1].Z0, strip[i].X1, strip[i].Y1, strip[i].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X1, (float)strip[i + 1].Y1, (float)strip[i + 1].Z1);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i + 1].X0, (float)strip[i + 1].Y0, (float)strip[i + 1].Z0);
GL.Normal3((float)nx, (float)ny, (float)nz);
GL.Vertex3((float)strip[i].X1, (float)strip[i].Y1, (float)strip[i].Z1);
}
}
}
GL.End();
// Rendu
glControl1.SwapBuffers();
} |
Partager