Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I am trying to learn and teach myself openGL and I wanted to draw a figure 8 in a 3D setting but I'm having a problem. Please forgive me, I am very new at this but I'll attempt to explain what I have done so far

I understand that I can use the Lemniscate of Bernoulli to draw a nice figure 8, so I've have adopted that idea into my code. I just want to draw it along the x and z plane. My code looks like this

#define PI 3.1415926535f
#define MAX_STEPS 100.0f
//...
Vector3 PointOnCurve1(Vector3 p1, float t)
{
    Vector3 tempPoint = {0.0f, 0.0f, 0.0f}; 
    float scaler = 2/ (3- cos(2*t));

    varX = scaler * cos(t);
    varZ = scaler * sin(2*t) / 2

    tempPoint.x = varX+p1.x;
    tempPoint.y += p1.y;
    tempPoint.z =varX+p1.z;

    return tempPoint;
}

Vector3 g_Point    = {-4,  0,  0};
glBegin(GL_LINE_STRIP);                              
    for(float t = -PI; t <= PI; t += PI / MAX_STEPS)
    {
        vPoint = PointOnCurve1(g_Point, t);
        glVertex3f(vPoint.x, vPoint.y, vPoint.z);
    }

glEnd();

All I'm getting is one straight green line instead of a figure 8. any ideas? Am I missing something here? I'm basing this equation from this gamedev article

Eight or infinity sign trajectory

share|improve this question
add comment

closed as too localized by Byte56, Trevor Powell, Sean Middleditch, Sam Hocevar, bummzack Mar 11 '13 at 22:40

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

Looks like a simple typo - you are updating tempPoint.z using varX, not varZ, so your coordinates move in unison and the shape collapses to a line. This is a common sort of mistake when writing componentwise math and you should learn to recognize the symptom.

Avoiding this mistake can be helped by using vector operations where possible, like p1 + var where var is a vector instead of varX and varZ.

share|improve this answer
    
What do you think of operator overloading instead? –  fryBender Mar 11 '13 at 3:54
    
@user955880 That's what I meant in the second paragraph. –  Kevin Reid Mar 11 '13 at 5:33
    
Thank you Kevin, that was very informative. –  fryBender Mar 11 '13 at 16:46
add comment

You're viewing the figure 8 from the side, so it just looks like a line. Try building it on the XY plane instead of the XZ plane.

share|improve this answer
    
Actually... It's even dumber than than. I didn't update the z variable accordingly. tempPoint.z =varX+p1.z; Is what I had. –  fryBender Mar 11 '13 at 3:50
    
Hah, nice, just noticed that varX showed up twice. Glad you got it figured out. –  Daniel Rowe Mar 11 '13 at 3:51
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.