Thread: creepy car thing.........

  1. #1
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905

    creepy car thing.........

    Code:
    	float width=50;
    	float height=60;
    	float length=3000;
    	float termvel=100;
    
    	main.Texture2D(true);
    	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    
    	if(main.keys['1'])
    		main.Mode(GL_FRONT,GL_FILL);
    
    	if(main.keys['2'])
    		main.Mode(GL_FRONT,GL_LINE);
    
    	if(main.keys['3'])
    		main.Mode(GL_FRONT,GL_POINT);
    
    	glLoadIdentity();
    	Camera();
    
    	if(up)
    		hover+=0.01f;
    	else
    		hover-=0.01f;
    
    	if(hover>1)
    		up=false;
    	if(hover<-1)
    		up=true;
    
    	glTranslatef(xpos,25.0f+hover,zpos);
    
    	glRotatef(180,0.0f,1.0f,0.0f);
    
    	if(main.keys[VK_LEFT])
    	{
    		crot=-20.0f;
    		xvel-=0.03f;
    	}
    	else if(main.keys[VK_RIGHT])
    	{
    		crot=20.0f;
    		xvel+=0.03f;
    	}
    	else
    	{
    		crot=0.0f;
    		if(xvel<0.02f && xvel>-0.02f)
    			xvel=0.0f;
    	}
    	if(main.keys[VK_UP])
    	{
    		speed+=0.02f;
    		cxrot=-10.0f;
    	}
    	else if(main.keys[VK_DOWN])
    	{
    		speed-=0.02f;
    		cxrot=10.0f;
    	}
    	else
    	{
    		cxrot=0.0f;
    		if(speed<0.2f && speed>-0.2f)
    			speed=0.0f;
    	}
    
    	if(crot>rot)
    		rot+=0.5f;
    	if(crot<rot)
    		rot-=0.5f;
    
    	if(cxrot>xrot)
    		xrot+=0.5f;
    	if(cxrot<xrot)
    		xrot-=0.5f;
    
    	if(xvel>3)
    		xvel=3;
    
    	if(xvel<-3)
    		xvel=-3;
    
    	if(speed>termvel)
    		speed=termvel;
    	if(speed<-termvel)
    		speed=-termvel;
    
    	if(speed>0)
    		speed-=0.01f;
    	if(speed<0)
    		speed+=0.01f;
    
    	if(xvel>0)
    		xvel-=0.005f;
    	if(xvel<0)
    		xvel+=0.005f;
    
    	if(xpos>width/2*10-30)
    	{
    		xpos=width/2*10-30;
    		xvel=-xvel/3;
    	}
    
    	if(xpos<-width/2*10+30)
    	{
    		xpos=-width/2*10+30;
    		xvel=-xvel/3;
    	}
    
    	if(main.keys['C'] && !main.lkeys['C'])
    		view++;
    
    	if(view>=NUMCAM)
    		view=0;
    
    	zpos-=speed;
    	xpos+=xvel;
    
    	glRotatef(-xrot,1.0f,0.0f,0.0f);
    	glRotatef(rot,0.0f,0.0f,1.0f);
    
    	ship->draw();
    
    	main.glPrint(0,32,0,"Speed %f",speed);
    
    	glLoadIdentity();
    	Camera();
    
    	glTranslatef(-10*width/2,0.0f,-40.0f);
    
    	glBindTexture(GL_TEXTURE_2D, main.texture[0]);
    
    	float zposf=0.0f;
    
    	for(int b=0;b<length;b++)
    	{
    		zposf-=height;
    
    		if(zposf<zpos+230 && zposf>zpos-3000)
    		{
    			glBegin(GL_QUADS);
    			glTexCoord2d(0,1);glVertex3f(0.0f, 30.0f,height);
    			glTexCoord2d(1,1);glVertex3f(0.0f, 0.0f,height);
    			glTexCoord2d(1,0);glVertex3f(0.0f, 0.0f,0.0f);
    			glTexCoord2d(0,0);glVertex3f(0.0f, 30.0f,0.0f);
    			for(int a=0;a<10;a++)
    			{
    				glTexCoord2d(0,1);glVertex3f(a*width,0.0f,height);
    				glTexCoord2d(1,1);glVertex3f((a+1)*width,0.0f,height);
    				glTexCoord2d(1,0);glVertex3f((a+1)*width,0.0f,0.0f);
    				glTexCoord2d(0,0);glVertex3f(a*width,0.0f,0.0f);
    			}
    			glTexCoord2d(0,1);glVertex3f(10*width, 30.0f,0.0f);
    			glTexCoord2d(1,1);glVertex3f(10*width, 0.0f,0.0f);
    			glTexCoord2d(1,0);glVertex3f(10*width, 0.0f,height);
    			glTexCoord2d(0,0);glVertex3f(10*width, 30.0f,height);
    			glEnd();
    		}
    		glTranslatef(0.0f,0.0f,-height);
    	}
    	main.glPrint(0,16,0,"%f::%f",zposf,zpos);
    	main.UpdateKeys();
    now, I'm pretty sure nobody here's gonna be able to rip that code off, lmao....

    ok, about the main.* stuff, that's for an opengl header file i made that can do a lot of stuff......but anyways

    thing is, this is the code i'm using for my racing game, and well, it looks perfectly fine to me......the problem is, as I'm driving on the course, once i reach about -40000, the track starts dissapearing, and the car starts sinking below it for some odd reason.....

    i know it's not anything in my header file, because all the header file is used for is creating windows, drawing text, etc etc....i think there might be something wrong with just the way that i'm using opengl,,,,,but i have no idea....

    hopin' someone here has had this happen to them before, and they can help (AND NO STUPID POSTS SAYING, "oooh, just look at google, google is the god, we must all follow google, praise google", I'm looking for someone here who actually KNOWS, cuz i've already looked on Google ) You guys are my last resort......

    -edit oh yeah, here's the camera code-
    Code:
    void Camera()
    {
    	switch(view)
    	{
    	case 0:
    		gluLookAt(xpos,60.0f,zpos+200,	//back view raised
    			xpos,25.0f,zpos,
    			0,1,0);
    		break;
    	case 1:
    		gluLookAt(xpos,25.0f+hover,zpos+1,	//cockpit
    			xpos,25.0f+hover+sin(xrot*PI180),zpos,
    			sin(rot*PI180),cos(rot*PI180),0);
    		break;
    	case 2:
    		glTranslatef(-xpos,-35.0f,-zpos-95);	//back view
    		break;
    	case 3:
    		gluLookAt(xpos,60.0f,zpos+400,
    			xpos,25.0f,zpos,
    			0,1,0);
    		break;
    	}
    }
    Last edited by jverkoey; 03-11-2003 at 06:02 PM.

  2. #2
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    hmmmm.... could you post an .exe so we can see your probem?

  3. #3
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    ok, here's a link to the exe:

    http://ivgda.skylockgames.com/downlo...ngoosedemo.zip

    please read the readme, and don't plagiarize!

    -edit-
    make sure that you save the zip, and don't open from current location, it doesn't work when you open it like that
    Last edited by jverkoey; 03-11-2003 at 08:44 PM.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    well, your speed is always positive (obviously) and you have the following statement to change your ships zpos...

    Code:
    zpos-=speed;
    so, after a bit of racing, the following condition becomes false and the track no longer gets rendered.

    Code:
    float zposf=0.0f;
    ....
    zposf-=height;
    
    if(zposf<zpos+230 && zposf>zpos-3000)
    ...
    when zpos reaches -height-230, the condition becomes

    if( -height < -height

    which is false, and since zpos is just getting smaller, the condition will be false from that point forward.


    im not sure why you have that 'if' statement to begin with (im sure you have your reasons) but if you take it out all together, the track should get rendered all the time.

    hope that helps!
    Last edited by Perspective; 03-12-2003 at 08:46 AM.

  5. #5
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    Originally posted by Perspective
    well, your speed is always positive (obviously) and you have the following statement to change your ships zpos...

    Code:
    zpos-=speed;
    so, after a bit of racing, the following condition becomes false and the track no longer gets rendered.

    Code:
    float zposf=0.0f;
    ....
    zposf-=height;
    
    if(zposf<zpos+230 && zposf>zpos-3000)
    ...
    when zpos reaches -height-230, the condition becomes

    if( -height < -height

    which is false, and since zpos is just getting smaller, the condition will be false from that point forward.


    im not sure why you have that 'if' statement to begin with (im sure you have your reasons) but if you take it out all together, the track should get rendered all the time.

    hope that helps!
    ok, the reason why i've got that if statement is so that i can limit the number of stuff to draw...there's no point in drawing EVERYTHING, because it'll get REALLY slow otherwise........

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    >ok, the reason why i've got that if statement is so that i can limit the number of stuff to draw...there's no point in drawing EVERYTHING, because it'll get REALLY slow otherwise........


    yeah, i figured it was part of your clipping. but the statement is false after zpos gets to " -height -230 " that is why the track does not get rendered.

  7. #7
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    did you check out the game? what seems to happen is that it'll........wait, danbjgltjgla;j i made the view distance longer.........well anyways, what I need is someone to test the game out, and just hold the up button for a while, you'll notice the ship gradually sinking in to the ground......i need to know why this is happening.............nevermind the road stopping thing for now

  8. #8
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    I played until about -400k, and never noticed any sinking. The ship did seem to be moving up and down slightly though.
    Last edited by XSquared; 03-12-2003 at 09:49 PM.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

  9. #9
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    hmm......did you try each view? (press C) the ship does move up and down, because it's hovering

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Originally posted by jverkoey
    hmm......did you try each view? (press C) the ship does move up and down, because it's hovering
    i tried all the views and raced untill the track ran out, the ship never sank into the ground =]

  11. #11
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    lmao, realized i uploaded a slower version of the game where the clipping plane is really far, so you don't even notice the sinking.....*sigh*......i'm just gonna try something else, anyways.....

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bill Gates and General Motors
    By xxxrugby in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 03-28-2005, 06:53 PM
  2. OpenGL coordinates
    By Da-Nuka in forum Game Programming
    Replies: 5
    Last Post: 01-10-2005, 11:26 AM
  3. garage simulation
    By rayrayj52 in forum C++ Programming
    Replies: 14
    Last Post: 11-03-2004, 03:49 PM
  4. need ; before using namespace std
    By wwfarch in forum C++ Programming
    Replies: 7
    Last Post: 05-11-2004, 10:42 PM
  5. How do you judge yourself
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 01-14-2003, 07:44 AM