Archived

This topic is now archived and is closed to further replies.

What's wrong with this code? (Newbie prob)

This topic is 6008 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Well, what's wrong with this code: int DrawGLScene(GLvoid) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glLoadIdentity(); glTranslatef(0.0f,0.0f,-20.0f); if (Up==FALSE) { glTranslatef(0.0f,speed,0.0f); glBegin(GL_TRIANGLE_STRIP); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); speed=speed-sped; sped=sped+0.1f; } else if (Up==TRUE) { glTranslatef(0.0f,-speed,0.0f); glBegin(GL_TRIANGLE_STRIP); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f, 1.0f, 0.0f); glColor3f(0.0f,1.0f,0.0f); glVertex3f( 1.0f,-1.0f, 0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f,-1.0f, 0.0f); glColor3f(1.0f,0.0f,0.0f); glVertex3f(-1.0f, 1.0f, 0.0f); glEnd(); speed=speed+sped; sped=sped-0.1f; } if (sped==0.0f) { sped=0.1f; Up=FALSE; } There is somthing wrong here (or thats what i think): if (sped==1.0f) { sped=0.9f; Up=TRUE; } return TRUE; } Sorry for not having it commented I am trying to make a triangle strip bounce up and down It won't turn when reaching 1.0f Thx Edit: Edited some code and added what is wrong Edited by - Rulzern on July 1, 2001 3:35:40 PM

Share this post


Link to post
Share on other sites
There is somthing wrong here (or thats what i think):

if (sped==1.0f)
{
sped=0.9f;
Up=TRUE;
}
return TRUE;
}

It won''t turn when reaching 1.0f

BTW:
else if (Up==TRUE)
{
glTranslatef(0.0f,speed,0.0f);

is supposed to be

else if (Up==TRUE)
{
glTranslatef(0.0f,-speed,0.0f);

thx

Share this post


Link to post
Share on other sites
One tip for you: when you to use commands like speed=speed-sped or sped=sped+0.1f, turn them to speed-=speed or speed+=5...it''s better!!


Later!!!

Share this post


Link to post
Share on other sites
ARGHHH!
What''s wrong with this code

I think it''s in the change between up and down movement, coz when I run it, the triangle strip sorta "skips" between up and down so that when it goes up it is at the top of the screen and when it goes down it "jumps" to the bottom of the screen



int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-20.0f);
if (Up==FALSE)
{
glTranslatef(0.0f,speed,0.0f);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
speed-=sped;
sped+=0.01f;
}
else if (Up==TRUE)
{
glTranslatef(0.0f,-speed,0.0f);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
speed+=sped;
sped-=0.01f;
}
if (sped<=0.00f)
{
sped=0.01f;
Up=FALSE;
}
if (sped>=0.10f)
{
sped=0.09f;
Up=TRUE;
}
return TRUE;
}


Thx fer yer help

Share this post


Link to post
Share on other sites
Try this, instead

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,speed,-20.0f);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
speed+=sped;
if(speed>0.5) Up=0; // Turn point
if(speed<-0.5) Up=1;
if(Up) sped+=0.01; else sped-=0.01; // Acc.
if(sped>0.1) sped=0.1; // Max speed
if(sped<-0.1) sped=-0.1;
}

Share this post


Link to post
Share on other sites
I figured it out:

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glLoadIdentity();
glTranslatef(0.0f,0.0f,-20.0f);
if (Up==FALSE)
{
glTranslatef(0.0f,-speed,0.0f);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(1.0f,0.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
speed-=sped;
sped+=0.01f;
}
else if (Up==TRUE)
{
glTranslatef(0.0f,-speed,0.0f);
glBegin(GL_TRIANGLE_STRIP);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f, 1.0f, 0.0f);
glVertex3f( 1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f,-1.0f, 0.0f);
glVertex3f(-1.0f, 1.0f, 0.0f);
glEnd();
speed+=sped;
sped-=0.01f;
}
if (sped<=0.00f)
{
sped=0.01f;
Up=FALSE;
}
if (sped>=0.10f)
{
sped=0.09f;
Up=TRUE;
}
return TRUE;
}

Thx guys!!

Sepiroth2: Were u into click b 4?

Share this post


Link to post
Share on other sites