Click here to Skip to main content
15,895,709 members
Articles / Multimedia / OpenGL

3D Solar System with OpenGL and C#

Rate me:
Please Sign up or sign in to vote.
4.91/5 (55 votes)
17 Apr 2013CPOL6 min read 200.1K   22K   64  
A demo of a solar system programmed in OpenGL and C#
In this article, you will see a simple 3D solar system implementation with OpenGL and C#. In the demo, you will learn how OpenGL rotation works and how to rotate a mesh around an arbitrary axis. You will also make use of the main OpenGL primitives: Point, Line and Triangles.
/* 
 *This code is property of Vasily Tserekh
 *if you like it you can visit my personal dev blog
 *http://vasilydev.blogspot.com
*/

using System;
using System.Collections.Generic;
using System.Text;

namespace SistemaSolar
{
    enum Planets
    { Mercury, Venus, Earth, Mars, Jupiter, Saturn, Neptune, Uranus, Pluton }


    public struct Position
    {
        public float x;
        public float y;
        public float z;

        public Position(int x,int y, int z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }
    }

    public class SolarSystem
    {
        Camara camara = new Camara();
        Star estrella = new Star();
        Sun sol = new Sun();
        List<Planet> planetas = new List<Planet>();
       

        public void CreateScene()
        {
            planetas.Add(new Planet(0.5f, Planets.Mercury, new Position(5, 0, 0), "mercurio.jpg",false));
            planetas.Add(new Planet(0.7f, Planets.Venus, new Position(11, 0, 0), "venus.jpg", false));
            planetas.Add(new Planet(1, Planets.Earth, new Position(15, 0, 0), "tierra.jpg", true));
            planetas.Add(new Planet(1, Planets.Mars, new Position(22, 0, 0), "marte.jpg", false));
            planetas.Add(new Planet(1.5f, Planets.Jupiter, new Position(28, 0, 0), "jupiter.jpg", false));
            planetas.Add(new Planet(1.2f, Planets.Saturn, new Position(35, 0, 0), "saturno.bmp", false));
            planetas.Add(new Planet(1.2f, Planets.Uranus, new Position(41, 0, 0), "urano.jpg", false));
            planetas.Add(new Planet(1.2f, Planets.Neptune, new Position(51, 0, 0), "restantes.jpg", false));
            planetas.Add(new Planet(1.2f, Planets.Pluton, new Position(60, 0, 0), "restantes.jpg", false));
            estrella.CreateStars(500);
            sol.Create();
            foreach (var item in planetas)
            {
                item.Create();  
            }
        }

        public Camara Camara
        {
            get { return camara; }
        }

        public void DrawScene()
        {  
            //dibujar las estrellas
            estrella.Draw();
            sol.Paint();
            foreach (var item in planetas)
            {
                item.Paint(); 
            }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
United States United States
Born on 86, had my first computer at the age of 8, wrote my first code at the age of 15(pascal), began to study software engineering at 2005 and graduated in 2010. I have a dev blog www.vasilydev.blogspot.com. My real passion is 3D game programming and playing guitar. I've programmed stuff in C#, python, Delphi, PHP, C++, JS, QT and others...

Comments and Discussions