Here's my latest code incase someone spots a blatant error:
float ecc = sqrt(ec2); float semiminorAxis = elems.SemiMajorAxis*sqrt(1.0f - ec2); Vector2f focusPos = m_focusBody->getPosition(); Vector2f normalized = elems.RelativePosition; normalized.X /= elems.R; normalized.Y /= elems.R; float xs = focusPos.X + normalized.X*elems.SemiMajorAxis*ecc/2; float ys = focusPos.Y + normalized.Y*elems.SemiMajorAxis*ecc/2; glBegin(GL_LINE_LOOP); for(float i = 0.0f; i < 3.141592654f*2.0f; i+= (3.141592654f/40.0f)) { float RX = xs + cos(i)*elems.SemiMajorAxis*normalized.X - sin(i)*semiminorAxis*normalized.Y; float RY = ys + cos(i)*elems.SemiMajorAxis*normalized.Y + sin(i)*semiminorAxis*normalized.X; glVertex2f(RX, RY); } glEnd();
Edit: Okay, after hours of trying and failing I'm going to bed. The only thing I can think of that is wrong with the above code is that my "normalized" vector that I use during the calculation of both the center point of the ellipse and in each vertex point on the ellipse itself represents the angle between the X axis and the position of the satellite. However, I think that this normal should actually describe the angle between the line drawn from one focus to another and the line drawn from one focus to the satellite itself. I'm thinking this is the case because every single site I've looked at describes how to draw an ellipse using the same method I'm using, but always with the ellipse's major axis either aligned with the X or Y axis exactly. I on the other hand am dealing with ellipses that have major axis that are rotated, so I think I have to use the axis itself as the reference point for my normal.
...I have absolutely no idea how to do that. I have the position of one focus of the ellipse (the star) and the absolute distance to the other focus (semi-major axis * eccentricity) but I have absolutely no information on which DIRECTION this distance should be applied in to figure out the orientation of the ellipse!
I believe all of my problems would be solved if I knew how to find the actual rotation of the ellipse from the information I currently have...
[Edited by - ChugginWindex on December 4, 2010 12:06:12 PM]