2
\$\begingroup\$

I am programming a 3d solar system (simulator). To describe the path of a planet I wanted to add 3D rectangles.. and draw them. But to no surprise it decreased the frame rate extremely. Also it does not look nice: CelestialMechanics

Do You know how to handle this problem? Is there another way to solve this? Didn't found anything on 3D HLSL Circle Plotting.

\$\endgroup\$
1
  • \$\begingroup\$ 1.: Do you need 3d ellipse or rectanges? 2.: There's no such thing as 3d ellipses or 3d rectangles, there are ellipsoids and boxes \$\endgroup\$
    – Bálint
    Commented Jan 29, 2016 at 19:24

2 Answers 2

1
\$\begingroup\$

I got it. I used a strip of lines instead.

  private void CalculateEllipsoid()
    {
        Path = new VertexPositionColor[64];
        List<VertexPositionColor> Vertices = new List<VertexPositionColor>();

        for (double i = 0; i < 2 * Math.PI; i += 0.001(variable))
        {
            var x = (float)(this.CenterX + (this.MajorAxisA * GLOBALSCALE) * (float)(Math.Cos(i)));
            var y = (float)(this.CenterY + (this.MinorAxisB * GLOBALSCALE) * (float)(Math.Sin(i)));
            Vertices.Add(new VertexPositionColor(new Vector3(x, 0, y), Color.DarkGray));
        }

        Vertices.Add(new VertexPositionColor(
            new Vector3((float)(this.CenterX + (this.MajorAxisA * GLOBALSCALE) * 
                (float)(Math.Cos(0))), 0,
                (float)(this.CenterY + (this.MinorAxisB * GLOBALSCALE) * (float)(Math.Sin(0)))), Color.DarkGray));

        Path = Vertices.ToArray();
    }

The method to calculate an ellipse:

    var x = (float)(this.CenterX + (this.MajorAxisA * GLOBALSCALE) * (float)(Math.Cos(i)));
    var y = (float)(this.CenterY + (this.MinorAxisB * GLOBALSCALE) * (float)(Math.Sin(i)));

is from here

https://stackoverflow.com/questions/9155750/rotate-some-elements-in-an-ellipse-path

To draw it

   public void DrawEllipsoid()
    {
        BasicEffect effect = new BasicEffect(Device);
        effect.World = Matrix.CreateTranslation(new Vector3(CelestialBody.GLOBALX, CelestialBody.GLOBALY, CelestialBody.GLOBALZ));
        effect.View = Camera.ViewMatrix;
        effect.Projection = Camera.ProjectionsMatrix;
        effect.LightingEnabled = false;
        effect.TextureEnabled = false;
        effect.VertexColorEnabled = true;
        effect.CurrentTechnique.Passes[0].Apply();
        Device.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.LineStrip, Path, 0, Path.Length - 1);
    }

The result: Result ( =

\$\endgroup\$
0
\$\begingroup\$

An possible approach:

Each planet's orbital ellipse can be drawn using 4 vertices to form a quad. The quad is drawn with a texture on it that is transparent except for the outline of a perfect circle.

The quad is 1 unit by 1 unit. It uses a world matrix that locates it's center on the orbital center and rotates it's orientation so it is coplanar with the orbital plane.

The world matrix is then scaled in length and width (on 2 of it's 3 axes) as necessary to cause the circle to become elliptical (the quad will change from a square to a rectangle and enlarge) and its circle will lay on the same path as the planet.

You can create a new instance of the quad for each planet and the only thing that is different between the various instances of the quad is the world matrix.

\$\endgroup\$
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .